Posts Tagged ‘css’

I’ve written several times about the development of a client-server Interactive Fiction platform. Parts of this system are called FyreVM, Zifmia, and other parts are just plain old web application development. FyreVM was created years ago and is a very stable implementation of the Glulx virtual machine. Zifmia is a state-machine wrapper that allows FyreVM games to run on a web server with all of the commands coming through AJAX calls and output returned as JSON. I wanted to provide a more detailed view of the new Textfyre system’s construction.

I spent a good portion of my spare time last summer working through the technical issues of a client-server implementation of FyreVM/Glulx. I’d had a very rough prototype, but last summer I sanded down the rough edges and came away with something solid. There were still major issues to resolve, including the design and persistence, but eventually I was able to send commands into the server-side engine and receive story data and display it on a web page. The next step was to turn it all into something “enterprise” ready. Something that initially could handle hundreds of users, but also be able to scale.

The first thing I worked on is making a reasonably clean “library” of JavaScript and jQuery code that was layered and maintainable. I then took all of that code and implemented an ASP.NET MVC 3 website. This allowed me to implement Clean URL’s, but also has a built-in capability for creating RESTful web services. It also allows me to continue using C#, since that’s how FyreVM and Zifmia were coded.

An additional benefit to using RESTful web services for all game play is that other types of clients can be developed later (iPad, Android, Windows 8 Metro).

One of the primary differences in this approach is that all of the game data is stored on the Textfyre servers. You might call it Cloud-IF since the player could conceivably play the same game from many computers and devices without any concern for saving, restoring, or managing files. The system stores the results of every turn and provides a user-interface that lets the player “jump” to any historical turn. The user interface even tracks branches, so the player can see where they jumped and where they changes paths.

This is done using Eloquera, an object-oriented database. It allows for very simple storage and retrieval of session data.

Not to stress this too much, but designing a modern user interface for Interactive Fiction is very difficult. Juhana Leinonen set the standard with his Vorple demonstration a year ago at PAX East. Jon Ingold and his partner Joseph Humfrey are doing some amazing things at Inkle Studios (Note: Jon Ingold is the co-designer and writer of Textfyre’s The Shadow in the Cathedral). I’d like Textfyre’s offering to be capable of similar results.

With that in mind, I’ve left all of the styling capability of this system to external resources. I considered adding a bunch of CSS capability to an Inform 7 extension and asking the author to work under those constraints. After a few passes, this was simply tiresome and very much the wrong direction. I designed the IO of FyreVM to be design neutral for a reason. I believe firmly that content should not know about how it is formatted; outside of emphasizing text with boldface, italics, or similar in-line styles. Any placement or styling beyond that should be handled by the content type. Since FyreVM allows the author to channel output to different content types, this is easily handled in the “interpreter”. In this case, the browser is our interpreter. We simply take content types and associate them to browser placement and styling.

The next assumption I made was that whatever template I designed was only going to be the default or standard template. There are a set of guidelines for authors or anyone interest to develop their own template. It may be daunting for an author and certainly a non-programmer to develop a template using HTML5, but it’s certainly not impossible or even improbable. I think the results of Vorple and Inkle Studios is confirmation that the IF world has the talent.

The standard template is very similar to a standard desktop interpreter with a few changes. Images can be identified by the game by filename and embedded in-game play, a map can be identified, and a few other visual elements allow interaction with the game, including displaying the player’s current inventory.

It would not be difficult to modify the standard template to move things around. Swapping in a new CSS file could change the entire design, similar to the way CSS Zen Garden works.

Web Services
I mentioned that game play is implemented using RESTful web services. Each service is called with a Clean URL and returns JSON (JavaScript Object Notation). HEre is a list of all of the possible web service calls (all executed through HttpWebRequest, always from a jQuery command):
Register player – /Register/{username}/{password}/{nickName}/{emailAddress}
Player login – /Login/{username}/{password}
Is Authorized – /IsAuthorized/{authKey}
Validate Player – /ValidatePlayer/{validationId}
Session Start – /SessionStart/{authKey}/{gameKey}
Session Get – /SessionGet/{authKey}/{sessionKey}
Session History – /SessionHistory/{authKey}/{sessionKey}/{branchid}/{turn}
Session Command – /SessionCommand/{authKey}/{sessionKey}/{branchId}/{turn}/{command}
User Session List – /UserSessionList/{authKey}
List all installed games – /Games

Game Data
When the player enters a command, it’s sent to the Session Command web service. This service executes the command and gathers all of the data. This data has always been called “Channels”, but you could also call it labelling. When the author is emitting text in a game, there are different kinds of text. FyreVM automatically determines most of the types and labels them accordingly. So the room title and description get labelled “Main”. The room title also is labelled “Location”, the score is labelled “Score”, time “Time”, turn “Turn”, and so on. The list of standard labels includes:

Prompt This is the text that precedes the prompt. In a standard IF game, this has always been “>”, but in our system, it can be any normal text.
Main This is the main text of the game, which includes any ‘before’ text, the location title and description, any object lists, and ‘after’ text.
Time This is the time of day within the game. It’s not always implemented or used, so the standard template looks at the Settings text to see if it should be displayed or not.
Location This is the location name.
Chapter If a game implements chapter titles, this is that text.
Credits This is the list of credits for the game.
Hints This is the current list of hints for the game. This data has to coordinate with the browser properly, so modifications to the standard template are required.
Score This contains the current score, if one is offered. The Settings text will identify if a score is displayed or not.
Title This is the game title.
Prologue This is the text displayed in the ‘When play begins’ rule of the game.
Turn This is the current turn number.
Tips This is a tip for the player.
Version This is version of the game.
Verb This contains the verb in the last command.
Tutorial This contains tutorial text.
Maps This contains a map image filename or some other text to show a map to the user. The standard template uses images (that change throughout the game).
Dead This is the text emitted when the game has ended.
Settings This text contains information on whether other types of text should be displayed or not.

Authors can dynamically label alternative content, which can in turn be displayed in the browser based on author preferences.

All of this data is returned in JSON and looks like this (this is an excerpt from a running version of Cloak of Darkness):

"Channels": [
{"Name": "PLOG", "Content": "Hurrying through the rain-swept November night, you\u0027re glad to see the bright lights of the Opera House. It\u0027s surprising that there aren\u0027t more people about but, hey, what do you expect in a cheap demo game...?"},
{"Name": "CRED", "Content": "Cloak of Darkness by David Cornelson\nGame Engine (FyreVM) by Jesse McGrew\nZifmia by David Cornelson\nInform 7 Programming by Emily Short and Graham Nelson, with Channel IO updates by David Cornelson.\nSpecial thanks to Graham Nelson and Emily Short for all of their hard work on Inform 7."},
{ "Name": "SCOR", "Content": "0"},
{ "Name": "TUTR", "Content": "You might try going WEST from the Foyer of the Opera House"},
{ "Name": "TIME", "Content": "540"},
{ "Name": "LOCN", "Content": "Foyer of the Opera House"},
{ "Name": "PRPT", "Content": "What do you want to do next?"},
{ "Name": "MAPS", "Content": "cloakmap-dark.png"},
{ "Name": "MAIN", "Content": "You are standing in a spacious hall, splendidly decorated in red and gold, with glittering chandeliers overhead. The entrance from the street is to the north, and there are doorways south and west."},
{ "Name": "TURN", "Content": "1"},
{ "Name": "TITL", "Content": "Cloak of Darkness"}

There’s a framework in place to convert the JSON data into a known JavaScript class, so “PLOG” becomes game.Prologue and “LOCN” becomes game.Location. This can then be displayed by updating the web page through a jQuery command, like this:


The new Textfyre website is nearly completed and in coordination with several eReader publications, is due out soon. It’s taken a long time to work through all of the technical details, but I think the results will be very attractive to Interactive Fiction game players as well as authors, teachers, and educational content providers.

So I have a working version of Zifmia, a client/server implementation of FyreVM. Basically, this is FyreVM with a state management wrapper where state is stored on the server. The wrapper and engine are hosted in a web service. I started developing the client web behavior with very basic html controls and it’s now time to design and create something interesting.

I was wondering if anyone with mad jQuery/CSS/HTML skills might want to help out and that’s not even a request to actually write code. Even ideas on how to translate an IF game onto a web page would be great. For instance, I don’t plan to implement a running scrollable textbox with game transcript text. I want to develop a paging mechanism and use jQuery to make it fluid within the browser, so keystrokes will allow movement to previous turn output and returning to the latest “page”. I’d like to implement a CSS based compass rose that shows available visited exits and possible unvisited exits (I’ve recently implemented a new channel that reports, in XML, what the visted and unvisted exits are).

I’m not much of a designer and defintely not a jQuery/CSS developer. I also have many other tasks on my plate.

The result of any work is open source and will be documented and shared with the IF community.

One of the aspects of FyreVM that always frustrated me was the hard-coded nature of the channel layout. The engine, up until now, had a hard-coded enumeration of named channels. There wasn’t really any reason for this, other than it makes consuming FyreVM easier to understand. This was a feature that was nice to have, but now that I’m working on three different sets of source, it’s becoming a royal pain. I also have a better understanding of ways in which FyreVM will be used and ported and removing the tightly-coupled nature of the channel layout from the engine seems like a natural course to pursue.

The current engine also had an output filtering system for the different types of clients we were developing. I removed this from the engine as well. A separate project will be created to offer basic output filtering mechanisms for Silverlight, WinForms (RichTextEdit controls), and HTML. This is a simple layer that takes the contents of each specified channel and replaces standardized markup or characters with the specified output. For instance, if you were doing HTML, you’d replace double carriage returns with a wrapping <p> tag for paragraph. A single carriage return would get a </br> tag. Character styling, including bold, italics, underline, double-strike, subscript, superscript, and fonts, if supported by your output system, can also be implemented through the filtering layer. If a particular game had a very specialized output, the layout engine may be built into a special client that understands the layout markup. So if the game marked up all nouns, the client may know what to do with these words outside of just marking them up. It’s possible they’re links to other data or links to commands to be returned to the game engine. Maybe the UI shows a tooltip for such marked up nouns. This would be considered a non-standard layout engine.

There are a set of channels required for every game and they include Main, Prompt, Location, Score, Time, and Death. Main has to be the first channel.

The engine will now automatically allocate buckets for channel data. Since it uses a hashtable and text named channels, this leaves room for any number of channels a person might want. It also removes any need for ordering the channels. — updated 2:24pm

I plan to have a standard set of channels for public consumption, but the expectation is that the author or publisher can modify the channel list for their own purposes. My assumption going forward is that each game will have its own list of channels. The standard is really just a jumping off point.

The output filtering will also require a set of standard extensions, which will be titled something like FyreVM for HTML or FyreVM for Silverlight or FyreVM for WinForms RichText. This will offer the author easy ways to markup their output so that the client can filter it appropriately.

The client will require a second class library that takes the channel layout and the filtering rules and returns the channel data in the expected form.

The channel layout and filtering rules will probably be XML as the default standard, but I may decide plain text is easier to read and edit.

The output filtering requires character by character reading/writing because of begin and end tags in many cases.

I know this is meaningless to nearly everyone, but eventually the benefits will become obvious.