Convert javascript-powered web page to standalone application

R

Robin Johnson

Hi,

I've written an engine in Javascript for running text adventure games
on a web page:

http://www.robinjohnson.f9.co.uk/adventure/hamlet.html (That's the
only game I've written with it so far, and a version of the engine
that is slightly less sophisticated than my development copy, which
has cleaner code and a more authentic Infocom-style scrolling display,
but I digress.)

There is essentially only one function each for input (take_command())
and output (say()) so the user-interface code is nice and seperate
from the muscle.

I'd like to be able to produce a download-and-run version of the game
with, crucially, the ability to do some simple file I/O for saving
games (the web version does that with cookies, which work sometimes,
and tend to screw things up if they get too big.) So I know I'll have
to take it outside Javascript, but I'd like to carry on with the code
I've already written.

I did a bit of googling and found Rhino, so I'm guessing I can use
that, and write new user interface and file i/o methods in Java, to
work around the existing code. I'm not very familiar with Java but
maybe this is my chance to learn. (And hopefully there won't be much
complicated stuff to be done anyway; I only want a console-window
app.)

I wondered if anyone here has experience of doing something similar -
basically, of converting a web application to a standalone one - and
might care to shave some advice (or, on the offchance, existing
code...) before I reinvent the wheel.

Thanks
 
R

Robin Johnson

Tony said:
Is there a reason you want to have the user download it, rather than staying
online?

So it can do file I/O, and so the user doesn't have to be online to use
it. (Other than ease of distribution, there's no real advantage to it
being on the web.)

Robin Johnson
 
W

wl

Robin Johnson said:
Hi,

I've written an engine in Javascript for running text adventure games
on a web page:

http://www.robinjohnson.f9.co.uk/adventure/hamlet.html (That's the
only game I've written with it so far, and a version of the engine
that is slightly less sophisticated than my development copy, which
has cleaner code and a more authentic Infocom-style scrolling display,
but I digress.)

There is essentially only one function each for input (take_command())
and output (say()) so the user-interface code is nice and seperate
from the muscle.

I'd like to be able to produce a download-and-run version of the game
with, crucially, the ability to do some simple file I/O for saving
games (the web version does that with cookies, which work sometimes,
and tend to screw things up if they get too big.) So I know I'll have
to take it outside Javascript, but I'd like to carry on with the code
I've already written.

I did a bit of googling and found Rhino, so I'm guessing I can use
that, and write new user interface and file i/o methods in Java, to
work around the existing code. I'm not very familiar with Java but
maybe this is my chance to learn. (And hopefully there won't be much
complicated stuff to be done anyway; I only want a console-window
app.)

I wondered if anyone here has experience of doing something similar -
basically, of converting a web application to a standalone one - and
might care to shave some advice (or, on the offchance, existing
code...) before I reinvent the wheel.

Thanks


Hi Robin,

For compiling javascript into Java classes, so these can be run on any
system having a Java virtual machine, have a look at Mozilla's project
'Rhino' (http://www.mozilla.org/rhino/)

I had some nice good experiences with it in the past.

Wim
 
C

Carl W.

I've written an engine in Javascript for running text adventure games
on a web page:

http://www.robinjohnson.f9.co.uk/adventure/hamlet.html (That's the
only game I've written with it so far, and a version of the engine
that is slightly less sophisticated than my development copy, which
has cleaner code and a more authentic Infocom-style scrolling display,
but I digress.)
[...]
I'd like to be able to produce a download-and-run version of the game
with, crucially, the ability to do some simple file I/O for saving
games (the web version does that with cookies, which work sometimes,
and tend to screw things up if they get too big.) So I know I'll have
to take it outside Javascript, but I'd like to carry on with the code
I've already written.
[...]
I wondered if anyone here has experience of doing something similar -
basically, of converting a web application to a standalone one - and
might care to shave some advice (or, on the offchance, existing
code...) before I reinvent the wheel.

</delurk>
Funny you should mention that. In the last few days I've just
finished translating a simple text adventure game the other way
around - into JavaScript from Perl.

It helped a little that I'm not a total novice in either
language, but I'm no expert either. I was surprised how simple it
all was. You imply that your code is fairly modular, and that
will definitely help. Translating one routine at a time makes the
progress seem much quicker.

Mine looks to be quite a bit simpler (in a not-so-good way) than
yours, mainly because I originally started writing it as a
manifestation of a telephone tech-support joke - The one that
runs like: "Thank you for calling So-and-so & Co. For tech
support you must find the silver key and escape the enchanted
forest. Press 2 for north, 4 for west, 6 for east, 8 for south.
etc.etc."

The Perl version's not anywhere downloadable (perhaps I should do
something about that...), but the JS version is at:
http://www.cyreksoft.yorks.com/raw/textAdv.php

There's contact details on the website for questions and stuff.
(The googlenews@... address falls into a black hole).

Cheers,
Carl - relurking
 
J

J Wynia

Take a look at HTA's (HTML Applications). Only for Windows, but gives
you the IE container without the web browser wrapper. Just rename an
..html file to .hta and double click it to see it in action. I'd
personally wrap it in either a ZIP or a basic installer (NSIS installer
works really well and is free/open source) that adds start menu options,
etc. Otherwise, you'll be dealing with "What do I do with this .hta file?".

I posted this sample in another thread earlier today, but here's a basic
sample, which also shows how to use WScript objects through the WSH
(Windows Scripting Host). The example is running a local application,
but HTA's also allow access to the local filesystem, registry, etc.

------------yourfile.hta---------------
<HTML>
<HEAD>
<TITLE>Your HTA Application</TITLE>
<HTA:APPLICATION ID="yourHTA"
APPLICATIONNAME="Your HTA Application"
BORDER="thin"
CAPTION="yes"
CONTEXTMENU="yes"
ICON=""
INNERBORDER="no"
MAXIMIZEBUTTON="yes"
MINIMIZEBUTTON="yes"
NAVIGABLE="yes"
SCROLL="auto"
SELECTION="yes"
SHOWINTASKBAR="yes"
SINGLEINSTANCE="no"
SYSMENU="no"
VERSION="1.0"
WINDOWSTATE="normal"/>
<script language="javascript">
<!--
function edit_hta(){
$this_hta = yourHTA.commandLine;
$command = "notepad.exe " + $this_hta;
$objShell = new ActiveXObject("WScript.Shell");
$lngReturn = $objShell.Run ($command, 1, true);
}
// -->
</script>
</HEAD>
<BODY>
Your HTA content goes here. Simply <a href="#"
onclick="edit_hta();">open this HTA file</a> in a text editor and go to
town. If you're looking to make this window look much more like a
regular Windows application, I recommend looking at the <a
href="http://webfx.eae.net/docs/environ.html">CSS values that you can
grab from the current Windows theme</a>. By setting your CSS to use
those values instead of things like #CCCCCC, you can make the HTA app
blend in with the current Windows settings.
</BODY>
</HTML>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,262
Messages
2,571,048
Members
48,769
Latest member
Clifft

Latest Threads

Top