Commit Graph

256 Commits

Author SHA1 Message Date
Paul Chote
b29b685058 Rename Fluent-related code to be more precise. 2024-10-04 15:11:27 +03:00
Matthias Mailänder
bc3c97398b Add localized message support to warheads. 2024-08-05 12:41:16 +03:00
RoosterDragon
0649f3dc32 RCS0056 - roslynator_max_line_length = 160 2024-07-29 21:56:36 +02:00
RoosterDragon
9d5d2ab493 RCS0056 - roslynator_max_line_length = 180 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
0bfa53b58d Teach CheckTranslationReference about translations in Lua scripts
Using the glory of regex, we can scrape any Lua script files that a map includes and locate calls to the UserInterface.Translate method. We can then treat them in the same way as C# fields marked with a TranslationReferenceAttribute. This allows the lint check to validate the translation invoked in the .lua script has a matching entry in the translation .ftl files, with all the required arguments (if any).

We can also locate any calls to AddPrimaryObjective or AddSecondaryObjective defined by the utils.lua script, which also accept translation keys.

The are a couple of restrictions:
- When linting the map, we don't check for keys in the ftl file that are unused. This is because the linter doesn't load all the keys when checking maps.
- In order to validate translation arguments with the regex, we require the Lua script to pass the table of arguments inline at the callsite. If it does not, we raise a warning so the user can adjust the code.
2024-07-22 17:27:58 +02:00
Matthias Mailänder
5ddc7b1177 Localize the faction dropdown. 2024-07-18 22:10:03 +03:00
Matthias Mailänder
97c61e0068 Extract strings from resource renderer. 2024-04-30 11:27:46 +03:00
RoosterDragon
10d7436cf0 CheckTranslationReference lint pass learns additional checks.
- Test all translation languages, not just English.
- Report any fields marked with TranslationReferenceAttribute that the lint pass lacked the knowledge to check.
- Improve context provided by lint messages.

Restructure code for readability.
2024-04-24 15:28:28 +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
abcdefg30
da507b2eed Add a lint check to ensure no actor names are conflicting with script names
Only scripted maps will have the need to use named actors, so we can
assume that there will be a Lua script used in maps with such actors.
2023-12-15 11:58:42 +02:00
Gustas
b267374d20 It doesn't make sense to put dots after file paths 2023-11-25 16:28:19 +01:00
Gustas
342fc5b0e9 Fix trait linting not providing trait and actor names 2023-11-25 16:28:19 +01:00
RoosterDragon
e6914f707a Introduce FirstOrDefault extensions method for Array.Find and List.Find.
This allows the LINQ spelling to be used, but benefits from the performance improvement of the specific methods for these classes that provide the same result.
2023-11-19 19:28:57 +02:00
RoosterDragon
c8efc5fdd7 Fix CA1854 2023-11-16 09:29:17 +02:00
RoosterDragon
889de5e08a Fix CA1822 2023-11-15 19:13:17 +02:00
RoosterDragon
fbe147ce61 Fix RCS1118 2023-11-10 10:38:41 +02:00
RoosterDragon
4dd787be13 Fix RCS1061 2023-11-10 10:38:41 +02:00
abcdefg30
ed3ca78667 Use TryGetValue instead of ContainsKey followed by indexing 2023-10-30 23:37:52 +02:00
abcdefg30
57cef527ba Use Array.Find and List.Find instead of LINQ's FirstOrDefault 2023-10-30 23:37:52 +02:00
abcdefg30
3f0159cd89 Index at 0 instead of using LINQ's First 2023-10-30 23:37:52 +02:00
Gustas
cbd6b67456 Add automated chrome string extractor. 2023-10-21 19:35:00 +02:00
Gustas
1f0e73906e Fix static linting 2023-10-21 19:35:00 +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
93a97d5d6f Fix CA1851, assume_method_enumerates_parameters = true 2023-08-20 20:41:27 +02:00
RoosterDragon
3275875ae5 Fix CA1851 2023-08-20 20:41:27 +02:00
Matthias Mailänder
94c8339e17 Allow for optional localised text notifications. 2023-08-19 20:46:04 +03:00
RoosterDragon
285443f10f Fix CA1310, CA1311 2023-08-07 21:38:09 +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
f99db8d754 Fix lua sanity check crashing on dedicated servers 2023-08-03 15:34:05 +02:00
Gustas
ed395c8ace Fix linter crashing on null actor array references 2023-07-01 18:29:59 +02:00
RoosterDragon
0958197df2 Fix CA1052 2023-06-20 17:57:40 +02:00
Matthias Mailänder
c31f2abfc9 Add sanity checks to the Lua script trait. 2023-06-11 11:03:38 +03:00
Gustas
06437df9b0 Fix CA1852 2023-06-06 14:13:04 +03:00
RoosterDragon
f4af5c1764 Fix CA1852 2023-06-06 11:51:47 +03:00
RoosterDragon
277699cbd5 Fix CA1822 2023-06-06 11:51:47 +03:00
Matthias Mailänder
5eec9d29cb Add a lint check for invalid integer expression syntax. 2023-06-04 21:29:15 +03:00
Gustas
34bcae9abb Translation keys should not be required 2023-05-19 17:25:03 +02:00
Gustas
8894fdeaf9 Add map translation parse error linting 2023-05-19 17:25:03 +02:00
Gustas
b5ef9c29cf Improve spawnpoint lint 2023-05-19 17:25:03 +02:00
Gustas
f344ccb714 Improve visibility lint 2023-05-19 17:25:03 +02:00
Gustas
9b71317280 Improve lint error wording 2023-05-19 17:25:03 +02:00
Gustas
1ac6912c2a Fix lint error formatting 2023-05-19 17:25:03 +02:00
Gustas
3188532e59 Add punctuation to lint comments 2023-05-19 17:25:03 +02:00
Matthias Mailänder
c5e9567875 Fix a null reference exception upon empty Fluent strings. 2023-05-02 22:25:51 +02:00
Gustas
44f1af7059 Move TileScale to MapGrid 2023-05-02 16:37:30 +03:00
Matthias Mailänder
af6330b1bd Allow localisation of dictionary values. 2023-04-25 21:33:02 +03:00
Gustas
a9a7777293 Report linguini parse errors
Reports duplicate keys
2023-04-22 19:23:41 +02:00
Gustas
bf66068557 Add per map linting 2023-04-22 19:23:41 +02:00
RoosterDragon
07fb5e8027 Fix CA1841 2023-04-17 00:05:12 +02:00