Update 13th March: A Better Way
I have got my dart code running inside the Web Dungeon Grails app and its live. It’s not the most elegant method but it works for now and is kind of simple and dumb and makes me happy.
Dart + Grails
The build folder has the following other nice properties:
So the Dart Editor does a good job of making it easier to integrate the dart into your project. Just copy the build folder anywhere as is and it will run in a browser, or on a web server.
Some Dart Voodoo
One interesting thing I noticed about the generated HTML file was the reference to the dart files are unchanged. But the code runs in normal browsers.
<body> <script type="application/dart" src="game.dart"></script> .... </body>
For reasons unclear to me, the Dart Editor development guys update the DOM on the fly in the dart.js file by replacing the script tag
<script type="application/dart" src="game.dart"></script>
Why couldn’t the ‘pub build’ step in the Dart Editor do this?
Dart in Web Dungeon Code
Anyway, to get my Dart code into my Grails app project, I copied the build directory into the Grails web-app directory. I needed to modify the HTML files in the build directory with the stuff from the app (styles, navigation menus and so on). This is because I had trouble integrating the dart code into the Grails views. Grails, like its spiritual mentor Ruby on Rails, is fantastically productive for building websites if you follow it’s rules. Things can get complicated if you try to get in the way of the preprocessing magic. I am nothing if not persistent though, and I will try and figure out a cleaner way of melding Dart and Grails.
Here is the dart code in my Grails project in Intellij
Web Dungeon – Build 2
I have updated the Web Dungeon Website to build 2. This includes the Dart code in the web app on the demo page, which has a very mediocre sprite moving around the screen. No more crappy videos – this is the real thing!
You might notice that you can use any key to move the sprite around, and not just the arrow keys. This is apparently a limitation in the DOM spec for Key Events. One advantage I guess is that if your arrow keys are broken you can still play!
Create my first slightly-less-crappy sprite. I’m embarrassed by the current one and the kids are underwhelmed too. Less code, more art. Time for the black turtleneck.