Skip to content

Commit

Permalink
Mapchecker (new-frontiers-14#844)
Browse files Browse the repository at this point in the history
* Create pr-labeler.yml

* Update labeler.yml

* Mapchecker initial version

* Create frontier-mapchecker.yml

* Update whitelists

* Unrestrict allowable stamps and cat ears

* Thanos snap illegal shit

* Update frontier-mapchecker.yml

* Fix aggressive matching

* Add TODO note

* Revert "Thanos snap illegal shit"

This reverts commit 20abe7b.

* Introduce technical debt into whitelist.

* Fix conditional checking semantics.

* Add blanket-whitelisting for maps, these are never checked.

* Actually skip blanket-whitelisted files. Also remove a print I left in on accident.

* Fix bugs I introduced before

* Move blackmarket whitelists to their own conditional matching group, to demonstrate this works mostly

* Add verbosity flag to mapchecker

* Merge upstream/master into origin/master, adjust default paths

* Make encryption keys except for common and traffic tagged with DO NOT MAP

* Technical debt for encryption keys

* Some more blacklists: Radios and the x-01 multiphase

* Resolve future merge conflict with new-frontiers-14#821

* Expand mapchecker to accept group overrides per-shuttle

* Update MapChecker documentation

* Resolve pipeline failures

* De-upset mapchecker
  • Loading branch information
TsjipTsjip authored Jan 8, 2024
1 parent f53ea0e commit 9b37edd
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 2 deletions.
42 changes: 41 additions & 1 deletion .github/mapchecker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,31 @@ directory which are marked as `DO NOT MAP`, `DEBUG`, ... and verifies that map c

## Usage

Glad I do not have to write this myself! Get detailed help information by running: `./mapchecker.py --help`
Glad I do not have to write this myself! Get detailed help information by running:
`python3 .github/mapchecker/mapchecker.py --help`

The following help block is printed:
```
usage: mapchecker.py [-h] [-v] [-p PROTOTYPES_PATH [PROTOTYPES_PATH ...]] [-m MAP_PATH [MAP_PATH ...]] [-w WHITELIST]
Map prototype usage checker for Frontier Station 14.
options:
-h, --help show this help message and exit
-v, --verbose Sets log level to DEBUG if present, spitting out a lot more information. False by default,.
-p PROTOTYPES_PATH [PROTOTYPES_PATH ...], --prototypes_path PROTOTYPES_PATH [PROTOTYPES_PATH ...]
Directory holding entity prototypes. Default: All entity prototypes in the Frontier Station 14 codebase.
-m MAP_PATH [MAP_PATH ...], --map_path MAP_PATH [MAP_PATH ...]
Map PROTOTYPES or directory of map prototypes to check. Can mix and match.Default: All maps in the Frontier Station 14 codebase.
-w WHITELIST, --whitelist WHITELIST
YML file that lists map names and prototypes to allow for them.
```

You should generally not need to configure `-p`, `-m` or `-w`, as they are autofilled with sensible defaults. You can do
this:
- Set `-p` to only check against prototypes in a specific directory.
- Set `-m` to just check a specific map. (Make sure to **point it at the prototype**, not the map file itself!)
- Set `-v` with `-m` set as per above to get detailed information about a possible rejection for just that map.

## Configuration

Expand All @@ -31,3 +54,20 @@ If a map has a prototype and you believe it should be whitelisted, add a key for
gameMap prototype), and add the prototype ID's to its list.

The whitelist the checker uses by default is `.github/mapchecker/whitelist.yml`.

## Shuttle group override

It is possible that a shuttle is set to group `None` because it is only used in custom shipyard listings. In this case,
you can force the MapChecker script to treat it as a different shipyard group by adding the following to the vessel
prototype:

```yml
...
group: None
# Add this line below.
mapchecker_group_override: ShipyardGroupHere
...
```

Note that for now this will cause a warning to be generated, but it will not cause a failure if the shuttle matches the
criteria for the overridden group.
14 changes: 13 additions & 1 deletion .github/mapchecker/mapchecker.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@
# Collect all prototypes and sort into the collectors.
for proto_file in proto_paths:
with open(proto_file, "r") as proto:
logger.debug(f"Reading prototype file '{proto_file}'.")
file_data = yaml.load(proto, Loader=YamlLoaderIgnoringTags)
if file_data is None:
continue
Expand All @@ -146,7 +147,6 @@
for item in conditionally_illegal_prototypes[key]:
logger.debug(f" - {item}")


# ==================================================================================================================
# PHASE 2: Check all maps in map_proto_paths for illegal prototypes.

Expand All @@ -164,6 +164,9 @@
map_name = map_proto # The map name that will be reported over output.
map_file_location = None
shipyard_group = None # Shipyard group of this map, if it's a shuttle.
# Shipyard override of this map, in the case it's a custom shipyard shuttle but needs to be treated as a
# specific group.
shipyard_override = None

for item in file_data:
if item["type"] == "gameMap":
Expand All @@ -174,6 +177,7 @@
if item["type"] == "vessel":
# This yaml entry is a vessel descriptor!
shipyard_group = item["group"] if "group" in item.keys() else None
shipyard_override = item["mapchecker_group_override"] if "mapchecker_group_override" in item.keys() else None

if map_file_location is None:
# Silently skip. If the map doesn't have a mapPath, it won't appear in game anyways.
Expand All @@ -185,6 +189,14 @@
logger.warning(f"Map '{map_name}' (from prototype '{map_proto}') was blanket-whitelisted. Skipping it.")
continue

if shipyard_override is not None:
# Log a warning, indicating the override and the normal group this shuttle belongs to, then set
# shipyard_group to the override.
logger.warning(f"Map '{map_name}' (from prototype '{map_proto}') is using mapchecker_group_override. "
f"This map will be treated as a '{shipyard_override}' shuttle. (Normally: "
f"'{shipyard_group}'))")
shipyard_group = shipyard_override

logger.debug(f"Starting checks for '{map_name}' (Path: '{map_file_location}' | Shipyard: '{shipyard_group}')")

# Now construct a temporary list of all prototype ID's that are illegal for this map based on conditionals.
Expand Down
7 changes: 7 additions & 0 deletions Content.Shared/Shipyard/Prototypes/VesselPrototype.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ public sealed class VesselPrototype : IPrototype
[DataField("group")]
public string Group = string.Empty;

/// Frontier - Add this field for the MapChecker script.
/// <summary>
/// The MapChecker override group for this vessel.
/// </summary>
[DataField("mapchecker_group_override")]
public string MapcheckerGroup = string.Empty;

/// <summary>
/// Relative directory path to the given shuttle, i.e. `/Maps/Shuttles/yourshittle.yml`
/// </summary>
Expand Down
1 change: 1 addition & 0 deletions Resources/Prototypes/_NF/Shipyard/cleric.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
price: 10800 #Appraisal is 10500
category: Small
group: None
mapchecker_group_override: Security # Treat this as a security vessel for mapchecker purposes
shuttlePath: /Maps/Shuttles/cleric.yml

- type: gameMap
Expand Down
1 change: 1 addition & 0 deletions Resources/Prototypes/_NF/Shipyard/fighter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
price: 9000 #not sure how much mark up % to add but the appraisal is 8491$
category: Small
group: None
mapchecker_group_override: Security # Treat this as a security vessel for mapchecker purposes
shuttlePath: /Maps/Shuttles/fighter.yml

- type: gameMap
Expand Down
1 change: 1 addition & 0 deletions Resources/Prototypes/_NF/Shipyard/rogue.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
price: 8200 #the appraisal is 7941$
category: Small
group: None
mapchecker_group_override: Security # Treat this as a security vessel for mapchecker purposes
shuttlePath: /Maps/Shuttles/rogue.yml

- type: gameMap
Expand Down

0 comments on commit 9b37edd

Please sign in to comment.