geordanr/xwing-miniatures-font

Add JSON mapping of ship name to character

Closed this issue · 6 comments

Please add a JSON file that contains a mapping of ship name to icon. It should look something like this:

{
	"aggressor": "i",
	"alphaclassstarwing": "&",
	"arc170": "c",
	"attackshuttle": "g",
        ...
        "ywing": "y",
	"z95headhunter": "z"
}

I maintain the iOS app DialVision which displays a list of ships and their icons. The app dynamically loads xwing-miniatures-ships.ttf from GitHub to ensure that it will display icons for the latest ships without having to redistribute the app every time the font updates but it needs a JSON file that maps the ship name to each character so it knows what character icon to display for each ship. Currently, I have a fork of this repo and have been manually maintaining a JSON file but it would be great if I didn't have to maintain a fork and manually generate the JSON every time there's an update.

Here's a screenshot from my app of the view I'm talking about:
Screenshot

I'd love to help in any way I can, but I'm not sure what the best approach would be. I'm not totally familiar with your build process, but I'm guessing the solution could involve using JSON as the source and generating the *-map.scss files as part of the Grunt task.

I think this is a great idea. Why not make it a seperate repo, though?

I suppose it could be a separate repo, but ideally it would be an automated process so when an icon is added to the font, the JSON is automatically kept in sync. I’m not familiar with any way to setup an automated process to build files in one repo that’s triggered by updates from another repo. But I’d be interested in looking into it if you know of something.

I think this is a good idea to incorporate into this project; that way the HTML (well, Pug template) would also be generated at the same time, and adding new icon names would only require editing one file and regenerating the assets.

I don't have time at the moment to implement this; pull requests welcome. Otherwise I'll see what I can do when I free up.

I was looking through the Gruntfile and it looks like the PUG file is currently manually edited to include all the icons?

I'm thinking that we could instead...

  1. Use JSON as the source for the icon names & symbols.
  2. Create Mustache templates to generate _*-map.scss files from the JSON in the Grunt task.
  3. Either update the PUG file to use JSON to generate index.html or migrate the PUG file to a Mustache template that does the same thing. This way the PUG file won't need to be manually edited every time icons are added.

Since PUG can only be used to generate HTML, I think that Mustache is the best option to generate the _*-map.scss files. The only reason to migrate from PUG to Mustache for the index.html file would be to only support one template format rather than two, but I don't feel strongly either way.

I've used Mustache templates once before with Grunt and can play with it. I'll let you know how it goes.

I got the functionality described above using Handlebars templates, which have some additional functionality over Mustache.

Notes:

  • The _ships-map.scss file now uses escaped characters (e.g. aggressor: "\0069" rather than "aggressor": "i"), which is consistent with the _icons-map.scss file. The ships-map.json file, however, does not use escaped characters which means it should remain easy to manually edit.
  • I changed the JSON format slightly from what was discussed above so each of the *-map.json files has a root object of either "icons" or "ships". This made it easier to reuse the same template to generate the *-map.scss files. They now look like this:
{
    "ships": {
        "aggressor": "i",
        "alphaclassstarwing": "&",
        "arc170": "c",
        ...
    }
}

Open Questions:

  • The JSON files are currently in the src/json/ folder. Is this the best location for that?

Nice thing about using the JSON maps is it now enables the ability to run tests on the font and icon maps. I created a separate PR #45 to do just that.