Commit Graph

47 Commits

Author SHA1 Message Date
RoosterDragon
0649f3dc32 RCS0056 - roslynator_max_line_length = 160 2024-07-29 21:56:36 +02:00
RoosterDragon
bd809e5af7 Prevent community mods from warning on unused translations in the common assets
Currently when linting translations, we check for any unused translation keys. This works fine for the default mods, which own the entire sets of translation files. For community mods, they often import the translation files from the common mod assets, but they may only use some of the translations provided. Currently, they would get warnings about not using translations from the common files they have imported.

Since the community mods don't own those translations, getting warnings about it is annoying. To solve this issue, introduce a AllowUnusedTranslationsInExternalPackages in the mod.yaml which defaults to true. This will prevent reporting of unused translation keys from external assets. Keys that are used for external assets will still be validated, and keys from the mod assets will be both validated and unused keys will be reported.

We default the new flag to true and don't provide an update rule. This means community mods will get the new behaviour. For the default mods, we do want to check the "external" assets, since we control those assets. So the default mods have their mod.yaml updated to disable the flag and retain the existing behaviour of checking everything.
2024-07-28 22:43:14 +03:00
RoosterDragon
b58c1ea5bc Provide names and pools when creating MiniYaml.
- Rename the filename parameter to name and make it mandatory. Review all callers and ensure a useful string is provided as input, to ensure sufficient context is included for logging and debugging. This can be a filename, url, or any arbitrary text so include whatever context seems reasonable.
- When several MiniYamls are created that have similar content, provide a shared string pool. This allows strings that are common between all the yaml to be shared, reducing long term memory usage. We also change the pool from a dictionary to a set. Originally a Dictionary had to be used so we could call TryGetValue to get a reference to the pooled string. Now that more recent versions of dotnet provide a TryGetValue on HashSet, we can use a set directly without the memory wasted by having to store both keys and values in a dictionary.
2024-01-21 12:39:10 +02:00
Gustas
a5e472dfe6 Add a utility command than extracts rule translations 2023-11-25 16:28:19 +01:00
Gustas
6386e96134 Move chrome extraction utility to common and reuse code 2023-11-25 16:28:19 +01:00
RoosterDragon
330ca92045 Fix RCS1077 2023-11-19 19:28:57 +02:00
RoosterDragon
2ea2106eca Fix CA1865 2023-11-16 09:29:17 +02:00
RoosterDragon
b7e0ed9b87 Improve lookups of nodes by key in MiniYaml.
When handling the Nodes collection in MiniYaml, individual nodes are located via one of two methods:

// Lookup a single key with linear search.
var node = yaml.Nodes.FirstOrDefault(n => n.Key == "SomeKey");

// Convert to dictionary, expecting many key lookups.
var dict = nodes.ToDictionary();

// Lookup a single key in the dictionary.
var node = dict["SomeKey"];

To simplify lookup of individual keys via linear search, provide helper methods NodeWithKeyOrDefault and NodeWithKey. These helpers do the equivalent of Single{OrDefault} searches. Whilst this requires checking the whole list, it provides a useful correctness check. Two duplicated keys in TS yaml are fixed as a result. We can also optimize the helpers to not use LINQ, avoiding allocation of the delegate to search for a key.

Adjust existing code to use either lnear searches or dictionary lookups based on whether it will be resolving many keys. Resolving few keys can be done with linear searches to avoid building a dictionary. Resolving many keys should be done with a dictionary to avoid quaradtic runtime from repeated linear searches.
2023-09-23 14:31:04 +02:00
RoosterDragon
949ba589c0 MiniYaml becomes an immutable data structure.
This changeset is motivated by a simple concept - get rid of the MiniYaml.Clone and MiniYamlNode.Clone methods to avoid deep copying yaml trees during merging. MiniYaml becoming immutable allows the merge function to reuse existing yaml trees rather than cloning them, saving on memory and improving merge performance. On initial loading the YAML for all maps is processed, so this provides a small reduction in initial loading time.

The rest of the changeset is dealing with the change in the exposed API surface. Some With* helper methods are introduced to allow creating new YAML from existing YAML. Areas of code that generated small amounts of YAML are able to transition directly to the immutable model without too much ceremony. Some use cases are far less ergonomic even with these helper methods and so a MiniYamlBuilder is introduced to retain mutable creation functionality. This allows those areas to continue to use the old mutable structures. The main users are the update rules and linting capabilities.
2023-08-07 21:57:10 +03:00
Gustas
462a3ef3c0 Make yaml node resolving optional 2023-07-30 20:39:21 +02:00
RoosterDragon
164abfdae1 Fix IDE0083 2023-04-08 16:51:51 +03:00
RoosterDragon
023d80b94d Fix IDE0057 2023-04-08 16:51:51 +03:00
RoosterDragon
bcfa0c9ae9 Review StyleCop rules.
- Enforce SA1604 ElementDocumentationShouldHaveSummary.
- Enforce SA1629 DocumentationTextShouldEndWithAPeriod.
- Turn off some rules covered by IDExxxx rules.
- Remaining rules are treated as part of OpenRA style.
2023-03-18 12:46:10 +02:00
RoosterDragon
63aa34cb35 Fix CS1570 2023-02-24 22:00:25 +02:00
Paul Chote
8be3ac863b Only update changed files when saving maps. 2023-01-27 07:43:25 +01:00
abcdefg30
5bf7fe852c Remove the copyright year numbers 2023-01-11 11:58:54 +02:00
Paul Chote
129db98a2f Add BeforeUpdate* methods for update rules.
These make it possible to write more advanced update
rules that query state across multiple actors, or
based on resolved state.
2023-01-10 18:02:24 +02:00
abcdefg30
6a31b1f9f3 Update the copyright header year 2022-05-28 00:35:10 -05:00
Matthias Mailänder
af3362c62f Use string.Contains(char) instead of string.Contains(string)
with single characters
2022-04-13 20:09:57 +02:00
Andre Mohren
6810469634 Updated copyright years. 2021-06-29 18:33:21 -05:00
teinarss
10676be377 Replace F extension with string interpolation 2021-05-08 22:20:59 +02:00
teinarss
9c4fd0e3d3 Use Null-Propagation Operator 2020-08-19 18:11:07 +01:00
teinarss
27f1a7ab27 Use out var syntax 2020-08-19 18:11:07 +01:00
teinarss
19b02875c7 Use Tuple syntax 2020-08-15 10:37:10 +01:00
Paul Chote
6d6822ca15 Update map inits in RA/TD/D2k. 2020-07-08 20:38:30 +02:00
reaperrr
0df7fa1596 Add sequence update rule support 2020-04-24 18:22:35 +02:00
abcdefg30
23b3c237b7 Update the year numbers in all license headers to 2020 2020-01-05 17:00:34 +00:00
Paul Chote
f3d7bf403e Rework chrome.yaml format and panel rendering. 2019-12-28 19:15:36 +01:00
abcdefg30
cadbd0d9ab Change the year number in all cs headers from 2018 to 2019 2019-01-26 23:15:21 +01:00
reaperrr
305d82f887 Replace WithChargeAnimation with -SpriteBody
PlayFetchIndex on a With*Animation trait conflicts with the animation
concept, as it's bound to conflict with pretty much all 'normal'
animation traits and blocks progress on the animation priority system.

We also already have multiple precedent SpriteBody traits of similar kind,
like WithGateSpriteBody and WithWallSpriteBody.
2018-12-24 21:29:42 +13:00
Paul Chote
ae3bfb73a1 Fix LastChildMatching ignoring the includeRemovals argument. 2018-11-03 15:09:14 +01:00
Andre Mohren
f342ecf18a Added UpdateRule. 2018-09-24 22:43:14 +02:00
reaperrr
f6278a1f41 Add some more useful extensions to UpdateUtils
In many situations, these will save up to 3-4 lines, because quite often this will be enough to avoid curly brackets, "if"s or one-by-on renamings.
2018-06-16 00:00:13 +02:00
reaperrr
3c9891e729 Refactor some update util extensions
Using arguments instead of separate overloads, plus better support for
automatically handling trait/property removals ('-' prefix).
2018-06-16 00:00:13 +02:00
Paul Chote
a9fa9ee741 Fix NRE when updating actors with inline comments. 2018-05-20 19:16:47 +02:00
Paul Chote
82e2595beb Enable comment and whitespace parsing where it is useful. 2018-05-12 16:42:54 +02:00
abcdefg30
9a8e50e82f Add a RemoveNode(MiniYamlNode) method to UpdateUtils 2018-05-05 00:25:29 +02:00
abcdefg30
ae9371f627 Add a ReplaceValue method to UpdateUtils 2018-05-05 00:25:29 +02:00
abcdefg30
399692341d Add a new AddNode(MiniYamlNode) overload to UpdateUtils 2018-05-05 00:25:29 +02:00
Paul Chote
691c432b72 Ignore yaml files imported from other mods. 2018-05-01 00:46:57 +02:00
Paul Chote
f0e190825a Fix map updater breaking unicode characters. 2018-04-30 02:37:53 +02:00
Paul Chote
2400b152ea Process shared map includes as part of the mod rules.
This ensures that they are only updated once instead
of repeating the updates for every map that includes them.
2018-03-30 21:31:15 +02:00
Paul Chote
aa5b9401c3 Add Chrome update plumbing. 2018-03-30 17:35:30 +02:00
abcdefg30
910064dfe5 Fix FormatMessageList appending a new line at the end of the list 2018-03-30 12:57:18 +01:00
abcdefg30
207a355909 Fix map files being labeled as "<no filename available>" 2018-03-30 12:57:18 +01:00
abcdefg30
972255c6a6 Fix line endings in upgrade rules files
- Use unix line endings
- No "\n" at the end of a message
2018-03-30 12:57:18 +01:00
Paul Chote
ea68f1abb9 Implement new mod/map updater framework. 2018-03-23 20:04:52 +01:00