Closed ihsoft closed 1 year ago
Thanks, we have discussed this already in the discord but to summaire.
In general I'd want to keep TimberAPI as low maintances as possible with some exceptions I believe are a must (like category button). To make it easier to update with less downtime.
The suggestion you made is not bad, the big problem I see with it is that it will get confusing when to use _TAPI_RESOURCE_
for a resource.
So my guess would go to a specification like AssetSpecification.TimberApi.json
. If I can do it without name AssetSpecification.json
with the following content:
{
"RemovePrefixes": [
"Spires/StatusIcons"
]
}
Any modder can just add a prefix from the game to the list and the bug will be fixed automaticly.
The RemovePrefixes
isn't the best name, suggestions are welcome.
@ihsoft The specification has become: AssetSpecification.json
.
usage:
AssetSpecification.json
in the specification folder (do not add any name like AssetSpecification.ihsoft.json
Sprites/StatusIcons
, these will be removed before splitting it in the correct loading format.json:
{
"IgnoreDirectoryPrefixes": [
"Sprites/StatusIcons"
]
}
The prefix gets removed as specified, i.e. Sprites/StatusIcons
. However, the actual path that is being resolved is Sprites/StatusIcons\sprite_name
. Where \
is Path.PathSeparator
and not just a constant symbol. I'd expect it be /
on linux-like machines. So, as of now the onle way to make it working is defining all the versions with the separators:
{
"IgnoreDirectoryPrefixes": [
"Sprites/StatusIcons/",
"Sprites/StatusIcons\\",
"UI/Cursors/",
"UI/Cursors\\"
]
}
The prefix gets removed as specified, i.e.
Sprites/StatusIcons
. However, the actual path that is being resolved isSprites/StatusIcons\sprite_name
. Where\
isPath.PathSeparator
and not just a constant symbol. I'd expect it be/
on linux-like machines. So, as of now the onle way to make it working is defining all the versions with the separators:{ "IgnoreDirectoryPrefixes": [ "Sprites/StatusIcons/", "Sprites/StatusIcons\\", "UI/Cursors/", "UI/Cursors\\" ] }
The leading slash must be included if they also automaitcly include it in their string. I don't see this as a problem with the feature but good catch.
I don't think linux is required to have the Sprites/StatusIcons\\
since it is not a files based system and is something from unity itself. to be sure you could ask @ginfuyou on discord to test your mod without the back slashes.
Edit: I overread the Path.PathSeparator... try to test it out and I hope it doesn't require it, but I cannot quite fix it either and your fix looks fine to me.
Here is a code snippet for the custom cursors:
private CustomCursor GetCursor(string cursorName)
{
return _resourceAssetLoader.Load<CustomCursor>(Path.Combine(CursorDirectory, cursorName));
}
Yeah that will switch between slashes depending on the OS. Though I find that it sets double backslashes a bit weird. It will be a small inconvenience to add multiple whenever this is used. Whenever I'll make a guide for it I will add it as a warning to keep this in mind whereever Timberborn does this.
Double slashes are only needed due to it's a JSON file. It's escaping of a specail symbol. Once the JSON is read and decoded, there will be just one back-slash. So, it's one symbol in both cases. Either \
or /
.
Ah right 👍, well I hope the feature will come in handy. No more need to wait for me until I would fix it.
Yeah, it's usable as is :) Thanks!
Sometimes the stock game logic uses names of the resources instead of the full path or an instance. Then, it constructs the full path to the resource internally and tries to load it. Obviously, such an approach is not compatible with modding due to the modded resources are located at the different paths. When this happens people either reinvent the wheel by reimplementing the existing code or patch the game code with Harmony.
Some common examples:
StatusSpecification.SpriteName
. Those, who want to use the status system, have to patchStatusSpriteLoader
.CursorService.SetCursor
. Using of custom cursor would require either doing it via Unity or patching a private method.The idea of this feature request is to come up with a solution to handle resource paths at the TAPI level. By either patching the common game classes or by rewriting the path at the lower level in
AssetLoader.Load
. E.g. like in this experimental branch.