Spherical forums

Sphere Development => Sphere General => Topic started by: Fat Cerberus on January 29, 2017, 10:34:59 am

Title: Cellscript for Sphere 1.x games
Post by: Fat Cerberus on January 29, 2017, 10:34:59 am
Here's a Cellscript that will compile most Sphere 1.x games and allow use of ES6 syntax.  Save the code below as Cellscript.mjs in the root of the game directory and enter cell from the command line.  That's it!

Code: (javascript) [Select]
/**
 *  Cellscript for Sphere v1 Migration
 *  (c) 2017 Fat Cerberus
 *
 *  save this as `Cellscript.mjs` in the root of your Sphere project, and you're
 *  ready to start taking advantage of everything the Sphere v2 toolchain has to
 *  offer!
 *
**/

import { transpile } from 'cell-runtime';

// any metadata defined here is written to game.json and is available to game
// code through `Sphere.Game`.
Object.assign(Sphere.Game,
{
name: "Game Title",
version: 1,  // Sphere v1 compatibility
author: "Some Guy",
summary: "This game probably sucks.",
resolution: '320x240',
main: 'scripts/main.js',
});

// Duktape doesn't support ES2015 syntax yet so we need to transpile if we want
// access to those features.
transpile('@/scripts', files('scripts/*.js', true));

// this should cover everything needed to run the majority of Sphere v1 games.
install('@/animations',   files('animations/*.mng', true));
install('@/fonts',        files('fonts/*.rfn', true));
install('@/images',       files('images/*.bmp', true));
install('@/images',       files('images/*.jpg', true));
install('@/images',       files('images/*.png', true));
install('@/maps',         files('maps/*.rmp', true));
install('@/maps',         files('maps/*.rts', true));
install('@/sounds',       files('sounds/*.wav', true));
install('@/sounds',       files('sounds/*.ogg', true));
install('@/sounds',       files('sounds/*.mp3', true));
install('@/sounds',       files('sounds/*.flac', true));
install('@/sounds',       files('sounds/*.it', true));
install('@/sounds',       files('sounds/*.xm', true));
install('@/sounds',       files('sounds/*.s3m', true));
install('@/spritesets',   files('spritesets/*.rss', true));
install('@/windowstyles', files('windowstyles/*.rws', true));
install('@/',             files('icon.png'));
Title: Re: Cellscript for Sphere 1.x games
Post by: Fat Cerberus on January 29, 2017, 11:51:14 am
Also: cell -p gamepak.spk to make an SPK.
Title: Re: Cellscript for Sphere 1.x games
Post by: Fat Cerberus on February 07, 2017, 03:29:37 am
The above Cellscript even works to compile frigging Kefka's Revenge and the compiled SPK package runs perfectly* afterwards.  Sometimes my level of commitment to backwards compatibility amazes even me.  Yep, just going to stand here and keep being awesome.  8)

* "Perfectly" must be understood to be a relative term in this context, this being Kefka's Revenge and all... :P
Title: Re: Cellscript for Sphere 1.x games
Post by: DaVince on February 08, 2017, 03:33:08 am
Nice stuff! Will you include this with a template project in miniSphere? Seems like a good idea to get people started, even without an editor. :)
Title: Re: Cellscript for Sphere 1.x games
Post by: Fat Cerberus on February 08, 2017, 03:42:24 am
The ideal state I'd like to get to would be where it's possible to develop Sphere games entirely from the command line.  Cell and SSJ get us most of the way there already; using JavaScript to control Cell builds was the best thing I ever did because it allows the compiler to be easily extended to do pretty much anything you want.
Title: Re: Cellscript for Sphere 1.x games
Post by: DaVince on February 08, 2017, 04:54:11 am
I suppose this could also mean conversion of eg. sprite sheets + a JSON file to rts files and the likes, as long as the work is put into that?
That sounds like an excellent way to go forward to me, as one doesn't necessarily have to rely on just one IDE.
Title: Re: Cellscript for Sphere 1.x games
Post by: Fat Cerberus on February 08, 2017, 11:33:26 am

I suppose this could also mean conversion of eg. sprite sheets + a JSON file to rts files and the likes, as long as the work is put into that?
That sounds like an excellent way to go forward to me, as one doesn't necessarily have to rely on just one IDE.


Yep, that was pretty much the exact kind of thing I had in mind when I first came up with the idea of a Sphere compiler.  I felt it was more important for the miniSphere 4.4 release, though, to implement ES6 support so that we can start using classes and stuff as soon as possible, as it makes for much more readable code.  I find it a lot easier to read a properly indented class definition, for example, compared to the typical Class.prototype.method = function() {} shenanigans required pre-ES6.
Title: Re: Cellscript for Sphere 1.x games
Post by: Fat Cerberus on February 09, 2017, 03:59:14 am
Hm, this could actually be a niche for that majin tool that I stopped developing after it got marginalized by the Cell rewrite: Upgrading Sphere v1 games. :) How that would work is you run majin in a directory containing a game.sgm file and it does everything needed to prepare that directory for a Sphere v2 workflow, including generating a Cellscript, etc.