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

Allow ShieldJSON to specify a map of banners on a base shield instead of requiring separate entries #1073

Merged
merged 59 commits into from
Sep 11, 2024

Conversation

ZeLonewolf
Copy link
Member

@ZeLonewolf ZeLonewolf commented May 19, 2024

This PR allows a user to specify bannered routes as a variant of a base route rather than having to specify an entire route definition block for each bannered variant. This reduces the total size of the uncompressed ShieldJSON by 18kb and is one step towards refactoring it to a small enough size to consider checking in the JSON rather than code to generate it.

Currently, bannered routes are defined as distinct top-level entries in the ShieldJSON map, as follows:

[
    "US:US": {
      "spriteBlank": [
        "shield_badge_2",
        "shield_badge_3"
      ],
      "textColor": "black",
      "padding": {
        "left": 3,
        "right": 3,
        "top": 4,
        "bottom": 5
      }
    },
    "US:US:Truck": {
      "banners": [
        "TRK"
      ],
      "spriteBlank": [
        "shield_badge_2",
        "shield_badge_3"
      ],
      "textColor": "black",
      "padding": {
        "left": 3,
        "right": 3,
        "top": 4,
        "bottom": 5
      }
    },
]

This is awfully repetitive - the entire definition is repeated for the special truck route. Instead, this PR proposes that we can define a base type, and then have a list of variant networks that have all the same styles but with one or more banners attached. To do this, we define a new parameter bannerMap which contains a mapping of route network to banner list. These are unpacked at runtime into the original structure above.

The new structure for above would now look as follows:

[
    "US:US": {
      "spriteBlank": [
        "shield_badge_2",
        "shield_badge_3"
      ],
      "textColor": "black",
      "padding": {
        "left": 3,
        "right": 3,
        "top": 4,
        "bottom": 5
      }
      "bannerMap": {
        "US:US:Truck": ["TRK"],
      }
    },
]

The bannerMap can be extended for any arbitrary number of bannered variants.

This PR initially implements the bannerMap feature on the US:US network and its bannered variants as a proof of concept for feedback. If we think this makes sense, remaining work for this implementation is to flesh out the documentation and go through all the route networks that have bannered variants. I anticipate we can get significant size savings in the ShieldJSON by eliminating all the duplication from banners.

image

Beyond US:US, there are 117 uses of the banneredShield function in shield_defs.js:

image

After this PR:
image

@ZeLonewolf ZeLonewolf added the shield-generator Issues specific to the shield library label May 19, 2024
@ZeLonewolf
Copy link
Member Author

Compressed size difference is minimal (after all, we're removing repetition):
image

@ZeLonewolf ZeLonewolf marked this pull request as ready for review June 1, 2024 22:55
src/js/shield_defs.js Outdated Show resolved Hide resolved
src/js/shield_defs.js Outdated Show resolved Hide resolved
Co-authored-by: Clay Smalley <claysmalley@gmail.com>
Copy link
Member

@claysmalley claysmalley left a comment

Choose a reason for hiding this comment

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

Sorry to leave this hanging. Looks good.

@ZeLonewolf ZeLonewolf merged commit 88c72ad into main Sep 11, 2024
6 checks passed
@ZeLonewolf ZeLonewolf deleted the zlw-banner-map branch September 11, 2024 23:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
shield-generator Issues specific to the shield library
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants