Changing the way Editor references original files

Started by Crimson Wizard, Mon 17/08/2015 09:52:42

Previous topic - Next topic

Crimson Wizard

There was a request made by Calin Leafshade: http://www.adventuregamestudio.co.uk/forums/index.php?issue=520.0
Basically it is about switching from using absolute paths to original sprite/audio files to relative ones.

While it is totally clear that this will benefit users who store original assets relative to the project folder (locally to project folder, or close to it), the question that bothers me is, would not that break a use of shared resources for someone?

Is this a common method for some of the AGS users to have a shared resources folder somewhere on their computer to take sprites/audio files from, regardless of where the game project itself is located?

I came to this question because I personally have a "library" of sprites for creating small test games, and this library is located in some place which is completely irrelevant to location of my AGS projects. Is this uncommon to how people work with AGS?
I am worried that changing to relative paths in all cases could break work for someone.

RickJ

I can see a need for both. Could we not have a "path" setting containing multiple paths, both absolute and relative?   

ChamberOfFear

That's a fairly good idea actually, I was worried there was no win-win situation in this. But if we add a new project specific property that lets the game developers choose if the path should be stored as relative or absolute we would meet the needs of both situations and not break previous projects.

Crimson Wizard

Yes, I totally agree, this will be optimal, if its possible to implement. :)

ChamberOfFear

I'll take that as we're in agreement then :) I'll take a look at it

cat

Would it be possible to detect if the path is a sub-path of the main game folder and in this case keep it relative? In any other case it could be absolute.

ChamberOfFear

Quote from: cat on Mon 17/08/2015 10:59:58
Would it be possible to detect if the path is a sub-path of the main game folder and in this case keep it relative? In any other case it could be absolute.

I believe so yes, to be more specific I imagine the end solution something like this.

If absolute paths is checked:



Files and folders outside the projectAbsolute paths
Files and folders inside the projectRelative paths

If relative paths is checked:



Files and folders outside the projectRelative paths
Files and folders inside the projectRelative paths

Files and folder located on another disk will always return an absolute path.

RickJ

It should be a search list rather than be either or, as shown in the example below.

Code: ags

SpritePath=PATH=C:\Ags\Standard\Sprites;.MyGameSprites;


[edit]
I may have mis-rtead your comments ChamberOfFear.
[/edit]

Crimson Wizard

#8
Quote from: RickJ on Mon 17/08/2015 15:57:56
It should be a search list rather than be either or, as shown in the example below.

Code: ags

SpritePath=PATH=C:\Ags\Standard\Sprites;.MyGameSprites;


Quote from: ChamberOfFear on Mon 17/08/2015 10:48:50
But if we add a new project specific property that lets the game developers choose if the path should be stored as relative or absolute we would meet the needs of both situations and not break previous projects.

Sorry, ChamberOfFear, I seem to misread what you say. I was thinking you are going to do what RickJ suggested in his first post here.

I do not think it will be convenient to use project-specific switch, for two reasons:
1) it may be confusing to set this for every new project.
2) it seems like a valid scenario if the project uses assets from different locations, some of which may be relative and some absolute.


E: erm, or we all are confused? maybe we should restate what we have decided again?

ChamberOfFear

Quote from: Crimson Wizard on Mon 17/08/2015 16:09:34
E: erm, or we all are confused? maybe we should restate what we have decided again?

I think I was the one that got confused. For safe measure, please restate how the implementation should be.

cat

May I make a suggestion?

The user adds a new resource.
Scenario 1: It is stored in a subfolder of the game folder -> it is stored as .\sounds\bang.ogg
Scenario 2: It is stored somewhere else -> it is stored as C:\Users\cat\Pictures\logo.bmp

I wouldn't ask people to mess with define the path type or even define their own path settings.

Crimson Wizard

Quote from: cat on Mon 17/08/2015 16:33:50
May I make a suggestion?

The user adds a new resource.
Scenario 1: It is stored in a subfolder of the game folder -> it is stored as .\sounds\bang.ogg
Scenario 2: It is stored somewhere else -> it is stored as C:\Users\cat\Pictures\logo.bmp

I wouldn't ask people to mess with define the path type or even define their own path settings.

Well, that was initial idea; ChamberOfFear suggested that user may want relative path even if the original files are not inside the project folder: for example if there is a shared resources folder, and several project folders positioned near.

ChamberOfFear

I'm almost certain I'm the one who has been misunderstanding things, probably got a little too overzealous when I realized it was possible to implement a solution that was satisfactory for both trouble scenarios. So let me try this again.

Every asset (sprites, audio and font) has a "SourceFile"-property which stores the file location for the asset in question, currently it stores absolute paths, always. The proposed fix is to store both absolute and relative path in a single string inside the "SourceFile"-property.

Using this we can find an asset by reading the SourceFile-property as follows
Code: pseudo

if relative_path == valid
  use relative path
else if absolute_path == valid
  use absolute path
else
  could not verify path


Building off RickJ's example the format of the string should be as follows
Code: text

SpritePath=PATH=absolute_path;relative_path;
AudioPath=PATH=absolute_path;relative_path;
FontPath=PATH=absolute_path;relative_path;


Example (The referenced file is inside the game project folder):
Code: text
SpritePath=PATH=C:\MyGame\Assets\Sprites\sprite001.png;Assets\Sprites\sprite001.png;


Example (The referenced file is outside the game project folder, but on the same disk):
Code: text
SpritePath=PATH=C:\Assets\Sprites\sprite001.png;..\Assets\Sprites\sprite001.png;


Example (The referenced file is outside the game project folder, and on a different disk):
Code: text
SpritePath=PATH=D:\Assets\Sprites\sprite001.png;D:\Assets\Sprites\sprite001.png;

Crimson Wizard

#13
Quote from: ChamberOfFear on Mon 17/08/2015 18:24:05
Every asset (sprites, audio and font) has a "SourceFile"-property which stores the file location for the asset in question, currently it stores absolute paths, always. The proposed fix is to store both absolute and relative path in a single string inside the "SourceFile"-property.

Oh...
Well, this is where our understanding differs.
What I thought RickJ is proposing is a kind of global PATH setting which directs to folders containing resources, where the sprites should be searched for. His last comment kinda suggests this.
But I would wait for him to clarify this himself.

And I must admit, that your variant is interesting too.


IDK, what we will choose, but I was thinking on how RickJ's solution (in my understanding) could be useful, and I came to following opinion.

What is the difference between absolute paths and relative paths from the end-user perspective?
Absolute paths are good for any occasional file. For example, you desperately needed a sprite, browsed your disk and imported one from some random location. Does relative path has any meaning in such case? I guess no, we need only absolute path.
Relative paths, on other hand, are for organized repository. It is when you know for sure that there is a directory structure that you need for your project(s).

So, what I may suggest, is to have a list of only relative paths (either global, or project-specific). If the file was taken from any of those directories (and their subdirectories), then the relative path is stored. Otherwise - absolute path is stored.
The default value for this PATH setting would be ".\", i.e. "project directory".

ChamberOfFear

Quote from: Crimson Wizard on Mon 17/08/2015 19:36:59
What I thought RickJ is proposing is a kind of global PATH setting which directs to folders containing resources, where the sprites should be searched for. His last comment kinda suggests this.
But I would wait for him to clarify this himself.
In retrospect that makes a lot of sense :P

Quote from: Crimson Wizard on Mon 17/08/2015 19:36:59
So, what I may suggest, is to have a list of only relative paths (either global, or project-specific). If the file was taken from any of those directories (and their subdirectories), then the relative path is stored. Otherwise - absolute path is stored.
The default value for this PATH setting would be ".\", i.e. "project directory".
I think this is the best solution proposed so far however, it's simple and elegant, and has little or zero chance to break previous games. But a couple of details needs to be hammered out.

  • Should the list be global, project-specific or both? To me it makes sense for it to be project-specific.
  • Where in the editor should the list be accessible for the user?

Crimson Wizard

Quote from: ChamberOfFear on Mon 17/08/2015 20:03:24

  • Should the list be global, project-specific or both? To me it makes sense for it to be project-specific.
  • Where in the editor should the list be accessible for the user?
Well, if we relate to existing IDEs, these have a IDE-wide path settings, and project-wide. If it would be possible, we could have a setting in Editor Preferences that would serve default value for new projects; and a setting in project's General Settings. There does not seem to be a suitable group for this now. Maybe create a new one called Source Files, or something like that?

selmiak

I like RickJ's choose your own destinypath system, set it in generalsettings somewhere and use your relative or absolute path for this project and set it different for another project. Everything fine, just define the default setting... (btw, I like relative paths)
I don't understand what ChamberOfFear's suggestion offers besides making it more complicated. I don't quite understand it already so this must be really complicated... :wink:

ChamberOfFear

Quote from: selmiak on Tue 18/08/2015 00:03:10
I like RickJ's choose your own destinypath system, set it in generalsettings somewhere and use your relative or absolute path for this project and set it different for another project. Everything fine, just define the default setting... (btw, I like relative paths)
I don't understand what ChamberOfFear's suggestion offers besides making it more complicated. I don't quite understand it already so this must be really complicated... :wink:

Doesn't matter :P I've already discarded it.

sonneveld

I think anything that stores absolute paths should be in a separate file such that is obvious that it only for that machine/user.  That way you can ensure you don't commit machine/user specific information into your repository.

Crimson Wizard

#19
Quote from: sonneveld on Tue 18/08/2015 03:02:59
I think anything that stores absolute paths should be in a separate file
AGS saves this information forever since it was first created.
Splitting the project file is a rather larger topic... this would require to rewrite serialization mechanism.

SMF spam blocked by CleanTalk