Tractor Mod

Tractor Mod

130k Downloads

[Content Patcher] Let game loading/playing stage available to modder

qqkookie opened this issue ยท 5 comments

commented

Regarding this modding help post, I'd like to have some "When" condition token to check for game loading/playing stage status. Please make such loading stage info available to modder , so that modder can apply different patch depending whether game is in initial asset loading stage on title menu or loading saved game stage or in-game playing stage.

I suggest to introduce some explicit condition token that will succeed only in certain stage of game loading / playing like "GameLoadingStage", with possible values like "Lunching", "OnTitle", "CreatingCharacter", "LoadingSave", and "GamePlaying", etc.

commented

I'd rather not have a load stage token, because the stages and how they affect content packs change over time. For example, most tokens become available very early during save loading (even earlier in SMAPI 3.0), so patches can be applied before the game reads the assets. Content packs which check the load stage would need to handle things like that, but in most cases all they really want to know is 'can I use this token yet'.

Instead I could add a new IsReady token:

"When": {
   "IsReady:{{PlayerGender}}": "true"
}
commented

A token can only be used when it's in scope ("ready"), which is separate from whether it has a value. For example, {{DayEvent}} is ready when a save is loaded, but its value is blank if there's no event today.

With that in mind:

  • HasValue:{{DayEvent}} can only be used when the save is loaded, and returns true if there's an event today.
  • IsReady:{{DayEvent}} can be used anytime, and returns true if the DayEvent token is in scope (regardless of whether it's blank).

A HasValue:{{PlayerGender}} condition isn't failed before the save is loaded, it's out of scope; the condition has no logical meaning, since there's no player to have a gender. If you check patch summary, it will show a message saying the {{PlayerGender}} token is unavailable.

commented

Hmmm.. then, what is difference between "HasValue: {{PlayerGender}}" :"true" and suggested "IsReady:{{PlayerGender}}": "true"? How about changing behavior of the "HasValue: " evaluation?

Currently"When:" token considers both "HasValue: {{PlayerGender}}": "true" and "HasValue: {{PlayerGender}}": "false" as failed condition on loading stage. It IS very confusing behavior.
I suggest that "HasValue: {{PlayerGender}}": "false" should be evaluated as success condition on game loading stage when " {{PlayerGender}}" is not ready.

commented

I got that they are different. But in practical sense it will surely confuse modder.
In most case, case when IsReady is success but HasValue is failed case is not useful case for most modding purpose. When mod check the value of {{Playergender}}, it almost always expect that both the value is Ready AND Has Value to decide the condition to apply the patch in question. I can not figure out in which case some patch should be fired when {{PlayerGender}} is Ready but {{PlayerGender}} does not have value.
So in my humble opinion, In practical modding purpose, IsReady is "True" AND HasValue is "True", is not much different from plain HasValue : "True" condition alone. They will yield almost always same condition test result. I doubt that IsReady will be used usefully and frequently like HasValue.

commented

That's fine for {{PlayerGender}} because it always has a value when ready, so they're essentially equivalent. That's not the case for all tokens. For example, you can use HasValue with a mod-provided token to check if the token has a valid empty value; with your change, it would also apply if the token isn't loaded at all, which probably isn't what the author intended.

You could avoid that by giving global tokens an empty value when they're not ready, which would let you use HasValue:{{PlayerGender}} before a save is loaded. Unfortunately that has other unintended effects; e.g. "FromFile": "assets/{{PlayerGender}}.png" would try to load an assets/.png file immediately instead of waiting until the token is ready.

Another issue is that changing the semantics of HasValue would be a significant breaking change for some existing content packs, so the change would need to wait for a possible future Content Patcher 2.0 release.

Introducing a separate IsReady token avoids all those issues, since content packs can use the one that matches what they need. In your case:

// use configured default gender before save is loaded
{
   "Action": "EditImage",
   "Target": "Characters/Farmer/accessories",
   "FromFile": "assets/accessories_{{DefaultGender}}.png",
   "When": {
      "IsReady:{{PlayerGender}}": "false"
   }
},

// use player gender when save is loaded
{
   "Action": "EditImage",
   "Target": "Characters/Farmer/accessories",
   "FromFile": "assets/accessories_{{PlayerGender}}.png"
},