-
Notifications
You must be signed in to change notification settings - Fork 0
JSInterfaces
Here's a quick description of some of the common JavaScript interfaces that we use.
This is a helper class that allows the simulation of common formatting techniques at the time - many DOS mags (and even some Windows ones) simply used control characters (such as \xAB
or \xFF
) to signify a color change, or an inline image, or a font change, and so on. However, since we're porting from this very state-based system to a (hopefully) well-formed HTML one, we're going to need some help.
What the State
class does is simply create an interface where control characters can request setting or removing or toggling some states, and the State
class will keep track of these states and turn them into CSS-compatible styles, while attempting to maintain the markup integrity.
Original text:
júliusban \xffCCSce\xffCBRage\xffCCNest\xffCA party
Example parsing code:
if (str[i]=='\xff')
{
switch (str[++i])
{
case "C": // color
{
var color = str[++i];
switch(color)
{
case "A": out += this.state.add("color","#B8B8B8"); break;
case "B": out += this.state.add("color","#D0D040"); break;
case "C": out += this.state.add("color","#00B848"); break;
case "D": out += this.state.add("color","#00B8D0"); break;
case "E": out += this.state.add("color","#CC4040"); break;
}
// todo
}
break;
[...]
Resulting markup (with line breaks for clarity):
júliusban </span>
<span style="color:#00B848;">Sce</span>
<span style="color:#D0D040;">Rage</span>
<span style="color:#00B848;">Nest</span>
<span style="color:#B8B8B8;"> party
Note how when there's a change, the state manager will attempt to close the previous tag. This makes the markup fairly bloated, but it's something we have to live with.
This is the wrapper class each magazine sits in. The functions are documented in the source, so instead here's a set of considerations and recommended workflow:
- First, implement the following "abstract" functions:
getMagDisplayName
,getExtension
,getIssues
,generateHTML
andgetModes
- most of these are fairly self-explanatory, with the exception ofgetIssues
: since this file both serves as data for JavaScript and the actual website, this has to be well-formed JSON! Again, check existing mags for reference - Second, implement
loadMagIssueData
: This function receives an ArrayBuffer with the mag datafile specified in theurl
field of thegetIssues
record, and should return a Promise which it resolves once it's done loading. - Next, implement
loadFileFromArchive
if possible (some mags don't necessarily have a file-based system, so may just have to returnnull
here); again this receives a filename (or index), and should return a Promise that resolves with an ArrayBuffer of the file contents. This will allow helper functions likeloadASCIIStringFromArchive
to sit on top. - Implement
loadMenu
andloadArchive
; the former's first parameter is a boolean that's true when the mag is first loaded - use this to reset the scrolling and stuff. The latter receives an article filename or index as parameter.
Other tips:
- Use
this.issueX
andthis.issueY
andwindow.onresize()
to change the mag resolution if it wasn't 640x480.