Permalink
Browse files

mark Herbalist as done, and add an experimental method for compiling …

…on Windows
  • Loading branch information...
1 parent b165faf commit 5215ab74a2d03720b40a81d9e240d2b754e40ad0 @rspeer committed Sep 24, 2011
View
@@ -43,15 +43,24 @@ specified names and play them against each other. For example:
Building the Web app
--------------------
-The Web version of Dominiate is built using CoffeeScript and Less CSS. You'll
-need to follow the instructions above to set up CoffeeScript. You should also
-install Less CSS with `sudo npm-g install less`.
+The Web version of Dominiate is built using CoffeeScript and Less CSS.
+
+**On a reasonable UNIX computer** (including Linux and Mac OS):
+Follow the instructions above to set up CoffeeScript. You should also install
+Less CSS with `sudo npm-g install less`.
Then, type `make` to build the JavaScript and CSS files that will be used
on the Web.
Do not edit the computer-written JavaScript directly! That way lies madness.
+**On Windows**: you can now compile the CoffeeScript files on Windows, using an
+included CoffeeScript compiler, `windows/coffee.exe`. (Being an .exe file
+downloaded from the Internet, you of course run this at your own risk.)
+
+Running `windows/compile.bat` should do the Right Thing, but I haven't tested
+it. See `windows/README` for more information.
+
Roadmap
-------
Short-term planned features include:
View
@@ -1,5 +1,5 @@
-Cards that are done (99)
-========================
+Cards that are done (100)
+=========================
Adventurer
Alchemist
Ambassador
@@ -38,6 +38,7 @@ Goons
Grand Market
Great Hall
Harem
+Herbalist
Hoard
Horn of Plenty
Horse Traders
@@ -100,9 +101,8 @@ Woodcutter
Worker's Village
Workshop
-Cards that still need to be coded (42)
+Cards that still need to be coded (41)
======================================
-Cards marked with ! should be easy to do, given code that already exists.
Easy cards
----------
@@ -113,7 +113,6 @@ Cutpurse
Feast
Fortune Teller
Golem
-Herbalist
Loan
Pearl Diver
Rabble
Submodule gh-pages updated from fffcc3 to c607ae
View
@@ -0,0 +1,32 @@
+This directory contains files that should help you develop Dominiate on
+Windows. Here's the general procedure:
+
+- Edit the *.coffee files however you want (using a good editor such as
+ Notepad++)
+- Run "compile.bat" from this folder, which will compile them into web\playWeb.js
+- Assuming that worked, open web\play.html in Firefox or Chrome and test it
+ out.
+
+I haven't tested this yet. Someone who uses Windows should.
+
+Credits
+-------
+This code uses the CoffeeScript Compiler for Windows by Alexey Lebedev, a
+modified version of Jeremy Ashkenas' original CoffeeScript compiler:
+
+https://github.com/alisey/CoffeeScript-Compiler-for-Windows/
+
+Jeremy Ashkenas' code is freely redistributable under the MIT license. I have
+no idea about the license for Alexey's version, but I'll assume until further
+notice that it's the same.
+
+Warning
+-------
+Strictly speaking, I have no idea what's in the .exe file I'm asking you to
+run. Its source code on GitHub appears reasonable, but I can't guarantee that
+that source actually compiles to that .exe.
+
+In short, if Alexey Lebedev turns out to be evil, you're letting him own your
+computer. I don't think people who make CoffeeScript accessible to more people
+are likely to be evil. But you never know.
+
View
Binary file not shown.
View
@@ -0,0 +1,3 @@
+coffee.exe -c -j ..\web\playWeb.js ..\playWeb.coffee ..\basicAI.coffee ..\cards.coffee ..\gameState.coffee
+coffee.exe -c ..\web\multiLog.coffee
+coffee.exe -c ..\web\scoreTracker.coffee
View
@@ -0,0 +1,10 @@
+How to build:
+
+1. Download JSDB binaries from http://www.jsdb.org/
+ You only need jsdb.exe
+2. Download https://raw.github.com/jashkenas/coffee-script/master/extras/coffee-script.js to this directory.
+3. Zip *.js files from this directory to coffee.zip
+4. Concatenate jsdb.exe and coffee.zip:
+ copy /b jsdb.exe+coffee.zip coffee.exe
+5. The resulting coffee.exe is a standalone CoffeeScript compiler
+6. Optionally, change icon with resource editor (e.g. http://icofx.ro)
View
@@ -0,0 +1,26 @@
+This is a standalone executable allowing you to compile [CoffeeScript](http://coffeescript.org/) files on Windows.
+Download coffee.exe to your Windows directory (or any other directory in your %PATH%)
+
+###Usage
+Same as the original coffee command:
+
+ -c, --compile compile to JavaScript and save as .js files
+ -o, --output [DIR] set the directory for compiled JavaScript
+ -j, --join [FILE] concatenate the scripts before compiling
+ -b, --bare compile without the top-level function wrapper
+ -v, --version display CoffeeScript version
+ -h, --help display a list of available options
+
+If you specify a directory as a source, all .coffee files in that directory will be compiled recursively.
+
+###Updating CoffeeScript
+* Download latest [coffee-script.js](https://raw.github.com/jashkenas/coffee-script/master/extras/coffee-script.js) to the same directory as coffee.exe
+* Check version: coffee --version
+
+###Better solution
+* Download Node.js executable for Windows: http://nodejs.org/#download
+* Download CoffeeScript: http://github.com/jashkenas/coffee-script/tarball/master
+* Create coffee.cmd in your Windows directory:
+
+ @echo off
+ "%PROGRAMFILES%/Node/node.exe" "%PROGRAMFILES%/CoffeeScript/bin/coffee" %*

Large diffs are not rendered by default.

Oops, something went wrong.
View
Binary file not shown.
View
Binary file not shown.
View
@@ -0,0 +1,137 @@
+load('options.js');
+load('coffee-script.js') || load('coffee-script-builtin.js');
+
+var SWITCHES = [
+ ['c', 'compile', '', "compile to JavaScript and save as .js files"],
+ ['o', 'output', ':', "set the directory for compiled JavaScript", "[DIR]"],
+ ['j', 'join', ':', "concatenate the scripts before compiling", "[FILE]"],
+ ['b', 'bare', '', "compile without the top-level function wrapper"],
+ ['v', 'version', '', "display CoffeeScript version"]
+];
+
+try {
+ main();
+} catch(e) {
+ writeln(e);
+}
+
+function main() {
+ var params = parseOptions(SWITCHES, system.arguments);
+ if (!params) return;
+ var options = params.options;
+ var sources = params.arguments;
+
+ if (options.version) {
+ writeln("CoffeeScript version " + CoffeeScript.VERSION);
+ return;
+ }
+
+ if (options.compile && sources) {
+ var files = sources.reduce(function(files, source) {
+ return files.concat(filesFromSource(source));
+ }, []);
+
+ options.join ? compileJoin(files, options)
+ : compileFiles(files, options);
+ }
+}
+
+function normalizePath(path) {
+ return path.replace(/[\\\/]+/g, '/').replace(/\/$/, '');
+}
+
+function fileExists(path) {
+ return !!system.attributes(path);
+}
+
+function fileGetContents(path) {
+ return (new Stream(path, 'rb')).readFile();
+}
+
+function filePutContents(path, contents) {
+ return (new Stream(path, 'wb')).write(contents);
+}
+
+function isDirectory(path) {
+ return /directory/.test(system.attributes(path).attributes);
+}
+
+function joinPath() {
+ return [].filter.call(arguments, function(x) {return x}).join('/');
+}
+
+function pathInfo(path) {
+ var pathParts = path.split('/');
+ var filename = pathParts.pop();
+ var dirname = pathParts.join('/');
+ var filenameParts = filename.split('.');
+ var extname = filenameParts.length > 1 ? filenameParts.pop() : '';
+ var basename = filenameParts.join('.');
+
+ return {
+ dirname: dirname,
+ filename: filename,
+ basename: basename,
+ extname: extname
+ };
+}
+
+function recursiveDirectoryListing (dir, fileMask) {
+ var files = system.files(dir + '/'+ fileMask);
+ var subdirs = system.folders(dir + '/*');
+
+ return subdirs.map(function(subdir) {
+ return recursiveDirectoryListing(dir + '/' + subdir, fileMask)
+ .map(function(file) { return subdir + '/' + file })})
+ .reduce(function(s, i) { return s.concat(i) }, files);
+}
+
+function filesFromSource(source) {
+ source = normalizePath(source);
+
+ if (!fileExists(source)) {
+ throw "File not found: " + source;
+ }
+
+ if (isDirectory(source)) {
+ var root = source;
+ var files = recursiveDirectoryListing(source, '*.coffee');
+ } else {
+ var root = pathInfo(source).dirname;
+ var files = [pathInfo(source).filename];
+ }
+
+ return files.map(function(file) {
+ var path = pathInfo(file);
+ path.root = root;
+ return path;
+ });
+}
+
+function compileFiles(files, options) {
+ files.map(function(f) {
+ var inputFile = joinPath(f.root, f.dirname, f.filename);
+ var coffeeSource = fileGetContents(inputFile);
+ var jsSource = CoffeeScript.compile(coffeeSource, {bare: !!options.bare});
+ var outputDir = joinPath(options.output || f.root, f.dirname);
+ var outputFile = joinPath(outputDir, f.basename + '.js');
+ system.mkdir(outputDir);
+ filePutContents(outputFile, jsSource);
+ });
+}
+
+function compileJoin(files, options) {
+ var coffeeSource = files.reduce(function(all, f) {
+ var srcPath = joinPath(f.root, f.dirname, f.filename);
+ return all + "\n" + fileGetContents(srcPath);
+ }, '');
+ var jsSource = CoffeeScript.compile(coffeeSource, {bare: !!options.bare});
+ system.mkdir(pathInfo(options.join).dirname);
+ filePutContents(options.join, jsSource);
+}
+
+function pp(x) {
+ for (var i in x) {
+ writeln(i + ': ' + x[i]);
+ }
+}
View
@@ -0,0 +1,114 @@
+/** Command-line options parser (http://valeriu.palos.ro/1026/).
+ Copyright 2011 Valeriu Paloş (valeriu@palos.ro). All rights reserved.
+ Released as Public Domain.
+
+ Expects the "schema" array with options definitions and produces the
+ "options" object and the "arguments" array, which will contain all
+ non-option arguments encountered (including the script name and such).
+
+ Syntax:
+ [«short», «long», «attributes», «brief», «callback»]
+
+ Attributes:
+ ! - option is mandatory;
+ : - option expects a parameter;
+ + - option may be specified multiple times (repeatable).
+
+ Notes:
+ - Parser is case-sensitive.
+ - The '-h|--help' option is provided implicitly.
+ - Parsed options are placed as fields in the "options" object.
+ - Non-option arguments are placed in the "arguments" array.
+ - Options and their parameters must be separated by space.
+ - Either one of «short» or «long» must always be provided.
+ - The «callback» function is optional.
+ - Cumulated short options are supported (i.e. '-tv').
+ - If an error occurs, the process is halted and the help is shown.
+ - Repeatable options will be cumulated into arrays.
+ - The parser does *not* test for duplicate option definitions.
+ */
+
+// Sample option definitions.
+
+function parseOptions(schema, argv) {
+ // Parse options.
+ try {
+ if (!argv.length) throw 'help';
+ var tokens = [];
+ var options = {};
+ var arguments = [];
+ for (var i = 0, item = argv[0]; i < argv.length; i++, item = argv[i]) {
+ if (item.charAt(0) == '-') {
+ if (item.charAt(1) == '-') {
+ tokens.push('--', item.slice(2));
+ } else {
+ tokens = tokens.concat(item.split('').join('-').split('').slice(1));
+ }
+ } else {
+ tokens.push(item);
+ }
+ }
+ while (type = tokens.shift()) {
+ if (type == '-' || type == '--') {
+ var name = tokens.shift();
+ if (name == 'help' || name == 'h') {
+ throw 'help';
+ continue;
+ }
+ var option = null;
+ for (var i = 0, item = schema[0]; i < schema.length; i++, item = schema[i]) {
+ if (item[type.length - 1] == name) {
+ option = item;
+ break;
+ }
+ }
+ if (!option) {
+ throw "Unknown option " + type + name + " encountered.";
+ }
+ var value = true;
+ if ((option[2].indexOf(':') != -1) && !(value = tokens.shift())) {
+ throw "Option " + type + name + " expects a parameter.";
+ }
+ var index = option[1] || option[0];
+ if (option[2].indexOf('+') != -1) {
+ options[index] = options[index] instanceof Array ? options[index] : [];
+ options[index].push(value);
+ } else {
+ options[index] = value;
+ }
+ if (typeof(option[4]) == 'function') {
+ option[4](value);
+ }
+ option[2] = option[2].replace('!', '');
+ } else {
+ arguments.push(type);
+ continue;
+ }
+ }
+ for (var i = 0, item = schema[0]; i < schema.length; i++, item = schema[i]) {
+ if (item[2].indexOf('!') != -1) {
+ throw "Option " + (item[1] ? '--' + item[1] : '-' + item[0]) +
+ " is mandatory and was not given.";
+ }
+ }
+ } catch(e) {
+ if (e !== 'help') write("Error: " + e + "\n");
+ write("Usage: coffee [options] path/to/script.coffee");
+ write("\nOptions:");
+ for (var i = 0, item = schema[0]; i < schema.length; i++, item = schema[i]) {
+ var names = (item[0] ? '-' + item[0] + (item[1] ? ', ' : ''): ' ') +
+ (item[1] ? '--' + item[1] : '');
+ var syntax = names + (item[2].indexOf(':') == -1 ? '' : ' ' + item[4]);
+ syntax += syntax.length < 20 ? new Array(20 - syntax.length).join(' ') : '';
+ write("\n " + (item[2].indexOf('!') != -1 ? '*' : ' ')
+ + (item[2].indexOf('+') != -1 ? '+' : ' ')
+ + syntax + "\t" + item[3]);
+ }
+ return false;
+ }
+
+ return {
+ options: options,
+ arguments: arguments
+ };
+}

0 comments on commit 5215ab7

Please sign in to comment.