Restoring a 19-Year-Old Game With TeaVM
IFML is a 19-year old project on SourceForge by Jenny Schmidt. It is both an engine for creating IF (interactive fiction) games and a game built on the engine. IFML was built using Java Applets and LiveConnect, a technology that let applets modify the DOM. Since Google and Mozilla removed applet support from their browsers a few years ago, the game no longer works in its original form. Since TeaVM lets you compile Java code to run in the browser, I decided to port IFML to the modern web. For the impatient, you can play the game here right now.At the Start: Looking for a Java IF Engine
For a long time I had been interested in interactive fiction. Mostly I was a consumer, playing games like Zork and more. I dabbled in homegrown games from time to time. As the years progressed, I heard of various projects to create game engines, but never got serious until recently. I started searching for a Java IF engine, and quickly found IFML.IFML: Well-Documented, Great TeaVM Match
IFML has thorough documentation of its file format, making very clear how to create your own games. It has a rich selection of options for creating scenes, props, characters, and more. It seemed like a good candidate for making IF games. But could it be ported to the modern web?A quick inspection of its source code showed that there were only a few places that might have issues:
- IFMLEngine made use of Applet APIs, which are no longer available.
- IFMLEngine used LiveConnect APIs to update the DOM. TeaVM and Flavour provide easy-to-use alternatives.
- The XML classes included some File IO APIs, which aren't available in the browser.
Removing the Applet API references were straightforward. Initialization moved to the TeaVM Client main() method.
DOM update API calls became Flavour templates with bound values. I translated longer text describing the scenes as paragraphs added via a Flavour std:foreach loop. For props in the player's inventory, I switched to an unordered list in the template, generated via another foreach Flavour loop.
Rather than try to remove the File IO from the included XML library, I decided to switch to using the browser XML APIs already exposed via TeaVM's JSO bindings. Because IFML used an IXMLElement interface consistently when dealing with XML, I only needed to create an alternate implementation of the interface that wrapped the DOM Node, and most of the game code worked as expected.
A Working Game!
With a few other tweaks to the game code and XML files I was able to get the game running in a browser. Until now, the game had been just static text and commands, but suddenly it was playable. For the first time in years, someone could relive the experience of a stranded ethnobotanist.Thanks to Jenny Schmidt who created the IFML Engine and the first game, Biki's Big Adventure, the one you can now play online here. Thanks also to Alexey Andreev and the other contributors to TeaVM and Flavour for enabling Java to grow and thrive on the modern web.