Metadata Stylesheets

Sick of having to Copy/Paste this over and over again?

    <Route Style="Dashed" Start="0101" End="0202" />
    <Route Style="Dashed" Start="0101" End="0303" />
    <Route Style="Dashed" Start="0101" End="0404" /&gt;

And then you decide that Fu would be better represented with dotted cyan instead, and you need to do a Find/Replace? Oh, the drudgery.

I've added a new metadata element you can use to style a few elements, borders and routes. Here's what you do:

    route.Fu { color: pink; style: dashed; }

    <Route Allegiance="Fu" Start="0101" End="0303" />
    <Route Allegiance="Fu" Start="0101" End="0404" />

Now all of Fu's routes are dashed pink, and more easily changed to dotted cyan.

It's similar to the CSS language used in web pages. The basic structure is a list of rules:

selector, selector, ... { property: value; property: value; ... }

Selectors (the bit up front):
  • type - border or route
  • Optionally followed by a period (.), then allegiance
    • e.g. border.Im
  • Multiple selectors can be listed, separated with commas
    • e.g. border.JuPr, border.JuRu, border.JuHl { color: blue; }
Declarations (the bit in the back):
  • A declaration list occurs in { braces } after the selector list.
  • Each declaration has a property, colon (:), value, semicolon (;)
  • Semicolons are terminators, not separators. You need a trailing semicolon after every declaration. This is different from CSS.
  • color -  HTML color name or six-digit hex color #rrggbb
    • e.g. pink or #FFC0CB
  • width - integer or floating point number
    • e.g. 2 or 1.5 or -123.456e23
  • style
    • solid, dashed or dotted
  • borders have only color
  • routes have color, width, and style
  • routes can use Type instead of Allegiance
    • e.g. route.Trade would select
  • You can use /* comments */ anywhere you can put spaces.
  • Within identifiers, you can use backslash (\) to escape characters like spaces
    • e.g. route.Core\ Route { color: purple; }
  • Explicit values on an element take precedence over a matching stylesheet rule.
Language boffins - here's the grammar:

stylesheet       := WS rule-list WS
rule-list        := rule*
rule             := selector-list '{' WS declaration-list '}' WS
selector-list    := selector WS ( ',' WS selector )* WS
selector         := element ( '.' code )?
element          := IDENT
code             := IDENT
declaration-list := declaration*
declaration      := property WS ':' WS value WS ';' WS
property         := IDENT
value            := IDENT | NUMBER | COLOR
IDENT            := [A-Za-z_]([A-Za-z0-9_] | '\' ANY)* 
NUMBER           := '-'? [0-9]* ('.' [0-9]+) ([eE] [-+]? [0-9]+)?
COLOR            := '#' [0-9A-F]{6}
WS               := ( U+0009 | U+000A | U+000D | U+0020 | '/' '*' ... '*' '/')*

And the source is on GitHub, of course. Also on GitHub you'll find the default stylesheet, which is applied after any values on the elements themselves and any sector-specific stylesheet:

border.Im { color: red; }
route.Im { color: green; }

border.SoCf { color: orange; }
route.SoCf { color: green; }

border.ZhCo { color: blue; }
route.ZhCo { color: lightblue; }

border.As { color: yellow; }
route.As { color: yellow; }

border.Hv { color: purple; }
route.Hv { color: gray; }

border.Kk { color: green; }
route.Kk { color: gray; }

border.JuPr { color: blue; }
route.JuPr { color: lightblue; }

route.Core\ Route { color: purple; style: dashed; }

This will almost certainly expand and be refined over time.



Alex said...

This change seems to have broken the processing of .msec type metadata. Any "border" directive now causes a stack dump.

I e-mailed a bug report yesterday, with more details and a stack dump. Here's the most important bit...

Steps to reproduce:

1. Load http://travellermap.com/poster.html in browser
2. Select any stock sector, to fill in valid sector data.
(E.g. Select "Spinward Marches")
3. Replace Metadata fieldtext with "border 0202 blue".
4. Click "Quick Preview" button.
5. Enjoy stack dump!

The culprit *might* be at Sector.cs:303, where you've replaced the short-circuiting ?: operator with the (probably) not short-circuiting ?? operator.

Keep up the good work!!

Joshua Bell said...

Thanks for the bug report with repro steps!

I think I've fixed it but only had a few minutes to play before heading off to Real Work, so it may be a band-aid and not a comprehensive solution.

Let me know if you see any other problems.

Alex said...

Looks good. Thanks.

Anonymous said...

Is there something broken now with T5 tab delimited poster map uploads? SEC uploads work but not tab delim. I'm even using old tab delim files that used to work. Thanks.

Joshua Bell said...

@Anonymous -

Sorry, I must have deployed a test version to the site. It should be working now. If not, please let me know and email me the .TAB file you're trying with.

Anonymous said...

Seems to be working great again Joshua - thanks!