diff --git a/Gulpfile.coffee b/Gulpfile.coffee index 6861cae..59519b0 100644 --- a/Gulpfile.coffee +++ b/Gulpfile.coffee @@ -7,7 +7,9 @@ uglify = require('gulp-uglify') zip = require('gulp-zip') concat = require('gulp-concat') rename = require('gulp-rename') +CSON = require 'cson' fs = require 'fs' +glob = require 'glob' reload = browserSync.reload @@ -54,7 +56,10 @@ gulp.task('tests', () -> ) gulp.task('concatCoffee', () -> + cson('./build') gulp.src([ + #procgen + './build/game/procgen.coffee' # language './game/language/ru.coffee' './game/language/en.coffee' @@ -72,6 +77,37 @@ gulp.task('concatCoffee', () -> .pipe(gulp.dest('./build/game')) ) +cson = (target) -> + sourcedir = + "game/procgen/en/": "en" + "game/procgen/ru/": "ru" + outtext = "procgendata = {}\n" + for sdir, lang of sourcedir + files = glob.sync(sdir+'*.cson') + spec = {} + for file in files + data = CSON.parseCSONFile(file) + if not data.groups? + data.groups = [] + if data.phrases? + data.groups.push({ + tags: [], + phrases: data.phrases + }) + data.phrases = null + key = file.substr(0, file.lastIndexOf('.')) || file + key = key.replace(sdir, '') + spec[key] = data + source = CSON.stringify(spec).split("\n") + out = "" + for line in source + out += " "+line+"\n" + source = "procgendata.#{lang} = {\n"+out+"}\n" + outtext += source + fs.writeFileSync(target+'/game/procgen.coffee', outtext) + +gulp.task('html', html('./build', true)) + gulp.task('coffee', ['concatCoffee'], () -> gulp.src('./build/game/main.coffee') .pipe(coffee({bare: true})) diff --git a/game/begin.coffee b/game/begin.coffee index 1b478f2..793ebe6 100644 --- a/game/begin.coffee +++ b/game/begin.coffee @@ -1,5 +1,3 @@ -ImprovEngine = new Improv -Improv = {} i18n.push("ru", ru_lang) i18n.push("en", en_lang) @@ -7,19 +5,15 @@ i18n.push("en", en_lang) salet.game_id = "0ee0825d-0c71-4a08-bfe5-730e575df26d" salet.game_version = "1.0" -$.holdReady( true ) -$.getJSON('game/procgen/'+i18n.lang+'.json', (data) -> - Improv = new ImprovEngine(data, { - rng: () -> - return salet.rnd.randf() - filters: [ - ImprovEngine.filters.mismatchFilter() - ] - reincorporate: false - }) - - $.holdReady( false ) -) +lang = document.getElementsByTagName("html")[0].getAttribute("lang") || "en" +ImprovEngine = new Improv(procgendata[lang], { + rng: () -> + return salet.rnd.randf() + filters: [ + Improv.filters.mismatchFilter() + ] + reincorporate: false +}) $(document).on("init", () -> salet.character.lastBeat = () -> @@ -109,4 +103,4 @@ cunit = (name, spec) -> return unit(name, spec) state = new ImprovModel procgen = (tag) -> - return Improv.gen(tag, state) + return ImprovEngine.gen(tag, state)