Creating an HTML Based eALSRB

Gordon

Forum Guru
Joined
Apr 6, 2017
Messages
2,488
Reaction score
2,940
Country
llUnited States
I think what he means is that "json" would be a neutral method of encoding the rules such that the could be automagically utilized by different software (browsers, Java apps, etc.) without having to explicitly code the source for each different type of software.
 

Vinnie

See Dummies in the index
Joined
Feb 9, 2005
Messages
17,427
Reaction score
3,365
Location
Aberdeen , Scotland
Country
llUnited Kingdom
I feel exactly the same way, but the problem is that this is copyrighted materiel, and as such, we can't really distribute it, even amongst ourselves. But yes, it drives me nuts as well, the amount of duplicated, wasted effort :-/

FWIW, I converted the Perry Sez Q+A to JSON, so that all the eASLRB'ers could re-use it...
I'd be interested in learning how to do this. One version image already incorporates the q&a but it's a very old style. The new html5 one does not have them added yet as it's beyond my programming capabilities and that of my technical consultant (well she's only 16....)
 

Pacman Ghost

Senior Member
Joined
Feb 25, 2017
Messages
590
Reaction score
298
Location
A maze of twisty little passages, all alike
Country
llAustralia
I'd be interested in learning how to do this.
How to convert the Q+A to JSON, or how to use it?

To create the JSON, I wrote a Python script that extracted the information from the HTML version.

If you want to use it, there are a few options. You can just read from the JSON directly from your HTML eASLRB and dynamically insert the content into your eASLRB, but that would require the use of Javascript. Alternatively, you could write a script that converts the JSON back to HTML, but in a format that is appropriate for your uses, and then just include that in your eASLRB.
 

Vinnie

See Dummies in the index
Joined
Feb 9, 2005
Messages
17,427
Reaction score
3,365
Location
Aberdeen , Scotland
Country
llUnited Kingdom
How to convert the Q+A to JSON, or how to use it?

To create the JSON, I wrote a Python script that extracted the information from the HTML version.

If you want to use it, there are a few options. You can just read from the JSON directly from your HTML eASLRB and dynamically insert the content into your eASLRB, but that would require the use of Javascript. Alternatively, you could write a script that converts the JSON back to HTML, but in a format that is appropriate for your uses, and then just include that in your eASLRB.
Yup, that's where you lose me. I'm pretty sure the JavaScript version is what I wish to do but not certain how to go about it....
 

Pacman Ghost

Senior Member
Joined
Feb 25, 2017
Messages
590
Reaction score
298
Location
A maze of twisty little passages, all alike
Country
llAustralia
The following is a really simple example of parsing the Q+A JSON and inserting it into an HTML page. Bung it in a file and open it in a browser. A real solution would need to be a bit smarter (i.e. dynamically inserting the content into the DOM rather than using document.write(), but it shows roughly how it works).

Code:
<head>
<style>
.caption { font-weight: bold ; background: #eee ; padding: 0.25em ; }
.question { margin-bottom: 0.5em ; }
.answer { font-style: italic ; margin-bottom: 0.5em ;  }
.source { font-size: 80% ; font-style: italic ; color: #666 ; }
</style>
</head>

<script>

perry_sez = 
{

"Chapter A": [

{ "caption": "A.5 & A7.52",
  "ruleids": [ "A.5", "A7.52" ],
  "content": [
    { "question": "What is the total DRM for a two-Location FG: the 1<sup>st</sup> Location contains an 8-1 and a squad and has +2 total Hindrance to the target; the 2nd Location has a CX squad and no Hindrance to the target?",
      "answers": [
        [ "+3.<;t contain an entry for SPAA. Riders are allowed on a SPA. So is a SPAA just one kind of SPA?", "ps" ],
        [ "Riders are allowed. SPAA is a subset of SPA.", "ps" ]
      ]
    }
  ]
},
{ "caption": "A.8",
  "ruleids": [ "A.8" ],
  "content": [
    { "question": "Is a Location ADJACENT to itself? I.e., if a rule permits some activity in an ADJACENT Location, and does not \"specifically exclude\" the unit's current Location from that activity, is the current Location included by default?",
      "answers": [ [ "Yes. Yes.", "ps" ] ]
    }
  ]
},
{ "caption": "A.9, A14.23, & E1.4",
  "ruleids": [ "A.9", "A14.23", "E1.4" ],
  "content": [
    { "question": "Are dummy units in a concealed stack with non-dummies considered Eligible Targets when rolling for RS on a sniper attack?",
      "answers": [ [ "Yes; all the Dummies would be considered one (combined) Eligible Target.", "ps" ] ]
    },
    { "question": "When dealing with hexes that have multiple cloaking counters and a RS is called for (e.g. Detection, Sniper, etc) do you RS between each cloaking counter and then RS from there, or do you simply RS between any/all units inside of the cloaking counters? What if one or more of the counters is a dummy?",
      "answers": [ [ "A.9 and A14.23 will apply normally. Ignore the cloaking counters unless they are empty (in which case they count as their own (dummy) unit [A.9] or as part of all Dummies in that Location [A14.23]).", "ps" ] ]
    }
  ]
},

]

} ;

entries = perry_sez[ "Chapter A" ] ;
for ( var i=0 ; i < entries.length ; ++i ) {
    var entry = entries[ i ] ;
    document.write( "<div class='caption'>", entry.caption, "</div>" ) ;
    for ( var j=0 ; j < entry.content.length ; ++j ) {
        var content = entry.content[ j ] ;
        document.write( "<div class='question'> <b>Q:</b> ", content.question, "</div>" ) ;
        for ( var k=0 ; k < content.answers.length ; ++k )
            document.write( "<div class='answer'> <b>A:</b> ", content.answers[k][0], " <span class='source'>("+content.answers[k][1]+")</span>", "</div>" ) ;
    }
}

</script>
 

Sparafucil3

Forum Guru
Joined
Oct 7, 2004
Messages
11,335
Reaction score
5,071
Location
USA
First name
Jim
Country
llUnited States
The system engineer in me hates that you all are doing it by yourselves, not leveraging each other at all.

WORK TOGETHER.
It's a hard thing to do. At some point, it raises to the level of attention and then who knows where that goes. -- jim
 

dlazov

Elder Member
Joined
Mar 22, 2004
Messages
7,991
Reaction score
1,377
Location
Toledo, Ohio
First name
Don
Country
llUnited States
In my line of work we call it "paired programming" it works quite well once you get used to it.
 

ColinJ

Member
Joined
Dec 19, 2009
Messages
129
Reaction score
107
Location
Calgary
Country
llCanada
I'd be interested in learning how to do this. One version image already incorporates the q&a but it's a very old style. The new html5 one does not have them added yet as it's beyond my programming capabilities and that of my technical consultant (well she's only 16....)
Depending on how deep you wish to go, the name attribute may work. Putting the <p name="blah blah blah"> with show "blah blah blah" when the cursor hovers over the text. Don't know if there is a character limit on it. For shorter bits it may work for you.
I started using this to indicate what the errata was for a specific rules section. After I did a few, I just convert the official errata into a separate html document and just look at it if an issue arose.
 

Vic Provost

Forum Guru
Joined
Sep 18, 2016
Messages
1,455
Reaction score
3,269
Location
Pittsfield, MA USA
First name
Vic
Country
llUnited States
I would die for something like this, would give a WORKs order + a Lifetime subscription to get my hands on one.

Also way past my meager skills.

Well past time for MMP to consider a digital copy... Vic.
 

MatrimSaric

Member
Joined
Sep 7, 2012
Messages
493
Reaction score
159
Location
Leicestershire
Country
llUnited Kingdom
I've started on my project and the base app structure seems to cope well. I still have to add history breadcrumbs (so you can track back over previous entries quickly). As an example here is one of the rules displayed (with the browser shrunk as mine is quite large.

8385
Clicking on the links obviously follows the link but clicking on the image shows a lookup with the image and related text. This is at a larger scale than the default (which will be settable) as so (this has been shrunk by 50% to be uploadable here so is actually double the size of the one above as you can tell from the text.


8386

One question I wanted to ask concerned rules versioning. How does MMP track its rules changes (if they do). I intend to work through the various errata post the version uploaded and would prefer to use MMPs flags to indicate most recent (but if necessary will use my own, probably year, major version, minor version.
 

zgrose

Elder Member
Joined
Jun 13, 2004
Messages
4,235
Reaction score
948
Location
Kingwood, TX
First name
Zoltan
Country
llUnited States
One question I wanted to ask concerned rules versioning. How does MMP track its rules changes (if they do). I intend to work through the various errata post the version uploaded and would prefer to use MMPs flags to indicate most recent (but if necessary will use my own, probably year, major version, minor version.
In the SKs, they highlight the text that has been changed/added from the last version. Not sure if they note removals. IIRC, they just go "one level" back.
 
Top