Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overhaul sequence filename definitions #20580

Merged
merged 4 commits into from
Jan 22, 2023

Conversation

pchote
Copy link
Member

@pchote pchote commented Dec 24, 2022

This is the first in a series of PRs aiming to remove technical debt from the sequence code and add features needed to finish and upstream remastered asset support.

All the magic around sprite filenames is removed in favour of explicitly specifying the full sprite name (per tileset if needed). This allows mods that don't follow the existing C&C conventions (e.g. by putting each tilesets assets in its own directory) to use tileset-specific artwork. It also prepares for a future PR that will add new ways of specifying filenames (e.g. FilenamePattern: mytank-{:D4}.png).

The Defaults node was previously combined into each sequence using MiniYaml.Merge at sequence-parsing time. This prevented us from implementing recursive merging at the MiniYaml level (see e.g. this complaint) because the raw sequence yaml may be malformed (e.g. trying to remove keys that don't exist) before the defaults have been copied over. This has been replaced with a much simpler fallback convention: the parser first looks for the requested key in the current sequence, and if not found it will look again in Defaults. Sequences can override (or more correctly, mask) the Defaults value by defining a key with no value.

I suggest reviewing by commit, and reading the commit descriptions for more information.
The yaml changes in the third commit are fully automated, so it shouldn't be necessary to inspect every single line in detail. A small number of manual cleanups are specified in the fourth commit.

Copy link
Member

@PunkPun PunkPun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we are changing everything up we may want a more user friendly exception for missing values. It doesn't mention where something is missing nor what

I deleted the filename field from MiG and got this

Exception of type `System.IO.FileNotFoundException`: File not found: 
   at OpenRA.Mods.Common.Graphics.FileNotFoundSequence.OpenRA.Graphics.ISpriteSequence.get_Tick() in /Users/gustas/Documents/GitHub/OpenRA/OpenRA.Mods.Common/Graphics/DefaultSpriteSequence.cs:line 112
   at OpenRA.Graphics.Animation.PlaySequence(String sequenceName) in /Users/gustas/Documents/GitHub/OpenRA/OpenRA.Game/Graphics/Animation.cs:line 126

Completely unhelpful to modders

OpenRA.Mods.Common/UpdateRules/UpdateUtils.cs Outdated Show resolved Hide resolved
OpenRA.Mods.Common/UpdateRules/UpdateUtils.cs Outdated Show resolved Hide resolved
@PunkPun
Copy link
Member

PunkPun commented Dec 24, 2022

The CheckSequences lint test (or a new one) could also be used to pick up on missing values

@pchote
Copy link
Member Author

pchote commented Dec 24, 2022

Fixed.

@PunkPun
Copy link
Member

PunkPun commented Dec 24, 2022

This is much better 👍. However it would be more ideal if lint test didn't display the tracelogs

@pchote
Copy link
Member Author

pchote commented Dec 24, 2022

The next PR completely overhauls the way that the sprite loading and lint tests work, so can we leave that for now?

@PunkPun
Copy link
Member

PunkPun commented Dec 24, 2022

sure

@PunkPun
Copy link
Member

PunkPun commented Dec 25, 2022

I tried updating Treasure_Hunt.oramap.zip and the update rule crashed

Crashlog
System.Collections.Generic.KeyNotFoundException: The given key 'SNOW' was not present in the dictionary.
        at OpenRA.Mods.Common.UpdateRules.Rules.ExplicitSequenceFilenames.ProcessNode(ModData modData, MiniYamlNode sequenceNode, MiniYamlNode resolvedSequenceNode, String imageName) in /Users/gustas/Documents/GitHub/OpenRA/OpenRA.Mods.Common/UpdateRules/Rules/20221203/ExplicitSequenceFilenames.cs:line 281
        at OpenRA.Mods.Common.UpdateRules.Rules.ExplicitSequenceFilenames.UpdateSequenceNode(ModData modData, MiniYamlNode imageNode)+MoveNext() in /Users/gustas/Documents/GitHub/OpenRA/OpenRA.Mods.Common/UpdateRules/Rules/20221203/ExplicitSequenceFilenames.cs:line 136
        at OpenRA.Mods.Common.UpdateRules.UpdateUtils.ApplyTopLevelTransform(ModData modData, List`1 files, TopLevelNodeTransform transform)+MoveNext() in /Users/gustas/Documents/GitHub/OpenRA/OpenRA.Mods.Common/UpdateRules/UpdateUtils.cs:line 292
        at System.Collections.Generic.List`1.InsertRange(Int32 index, IEnumerable`1 collection)
        at System.Collections.Generic.List`1.AddRange(IEnumerable`1 collection)
        at OpenRA.Mods.Common.UpdateRules.UpdateUtils.UpdateMap(ModData modData, IReadWritePackage mapPackage, UpdateRule rule, List`1& files, HashSet`1 externalFilenames) in /Users/gustas/Documents/GitHub/OpenRA/OpenRA.Mods.Common/UpdateRules/UpdateUtils.cs:line 143
        at OpenRA.Mods.Common.UtilityCommands.UpdateMapCommand.ApplyRules(ModData modData, IReadWritePackage mapPackage, IEnumerable`1 rules) in /Users/gustas/Documents/GitHub/OpenRA/OpenRA.Mods.Common/UtilityCommands/UpdateMapCommand.cs:line 108

@pchote
Copy link
Member Author

pchote commented Dec 26, 2022

The update rule requires the legacy tileset metadata (which is removed in the last commit) to be defined in mod.yaml. The map updates fine if you add that back.

@PunkPun
Copy link
Member

PunkPun commented Dec 26, 2022

Seems less than ideal. Update rules are also meant for maps, I'd even say that they're used for maps more than for mods. We should handle the crashes

@pchote
Copy link
Member Author

pchote commented Dec 26, 2022

I can’t think of an acceptable way to do that - keeping unused junk data in mod.yaml isn’t acceptable, and hardcoding the upgrade rule with data for only the upstream mods isn’t really either.

@abcdefg30
Copy link
Member

The update rule shouldn't crash but write a proper error message - explaining what is written in the comments above: That it needs the definitions in mod.yaml and that those can be removed (again) afterwards.

@pchote
Copy link
Member Author

pchote commented Dec 28, 2022

Updated.

ExplicitSequenceFilenames: Sequence filenames must be specified explicitly.
   Updating map... COMPLETE
   Manual changes are required to complete this update:
    * The ExplicitSequenceFilenames rule requires TilesetExtensions
      to be defined under the SpriteSequenceFormat definition in mod.yaml.
      Add these definitions back and run the update rule again.

Semi-automated update complete.
Please review the messages above for any manual actions that must be applied.

@pchote pchote force-pushed the simplify-tileset-sequences branch 2 times, most recently from 0223a1c to bf3ca1a Compare December 28, 2022 08:14
@PunkPun
Copy link
Member

PunkPun commented Dec 28, 2022

In the future we should make it clearer when update rules fail / require manual changes. Currently that information is fairly hard to find within walls of text.

I did run this rule on some other fairly artwork heavy maps and it seems to function well

PunkPun
PunkPun previously approved these changes Dec 28, 2022
Copy link
Member

@PunkPun PunkPun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@PunkPun
Copy link
Member

PunkPun commented Dec 29, 2022

Could there be anything done to the resource centre update function to account for the missing definitions?

@pchote
Copy link
Member Author

pchote commented Dec 30, 2022

Yes, the definitions can be added back to mod.yaml on the RC engines.

@PunkPun
Copy link
Member

PunkPun commented Jan 11, 2023

Needs a rebase / copyright header update

@pchote
Copy link
Member Author

pchote commented Jan 11, 2023

Rebased.

Copy link
Member

@penev92 penev92 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The naming may or may not just be me, but there is at least one crash to fix.

@PunkPun
Copy link
Member

PunkPun commented Jan 18, 2023

https://github.com/OpenRA/OpenRA/wiki/Sequences
will need to be updated after the merge

@pchote pchote force-pushed the simplify-tileset-sequences branch 2 times, most recently from 4838396 to b2664a0 Compare January 21, 2023 14:42
@pchote
Copy link
Member Author

pchote commented Jan 21, 2023

Updated.

Mailaender
Mailaender previously approved these changes Jan 22, 2023
Copy link
Member

@Mailaender Mailaender left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--check-sprite-sequences clean. No problems in-game.

The previous MiniYaml.Merge implementation interacted
poorly with yaml inheritance, making it complicated
(or impossible) to override certain keys from Defaults.

The new implementation is simpler: If a key is defined
it will be used. If it isn't, the default (if defined)
will be used. Defaults can be masked by making sure
the same key is defined (even with an empty value)
in the sequence.

This also fixes naming within the sequence code to
distinguish between images (a group of sequences),
sequences (defining a specific sprite/animation),
and filenames for a specific sprite/animation.
All magic behaviour for constructing sprite filenames
has been removed in favour of an explicit Filename
(and TilesetFilenames for tileset-specific sequences)
property.
@pchote
Copy link
Member Author

pchote commented Jan 22, 2023

Updated.

Copy link
Member

@penev92 penev92 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@penev92 penev92 merged commit e13a7ae into OpenRA:bleed Jan 22, 2023
@penev92
Copy link
Member

penev92 commented Jan 22, 2023

Changelog

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants