procgen concatenation

This commit is contained in:
Alexander Yakovlev 2017-11-10 19:18:47 +07:00
parent d3581a6eb4
commit ed75609314
2 changed files with 46 additions and 16 deletions

View File

@ -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}))

View File

@ -1,5 +1,3 @@
ImprovEngine = new Improv
Improv = {}
i18n.push("ru", ru_lang)
i18n.push("en", en_lang)
@ -7,20 +5,16 @@ 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, {
lang = document.getElementsByTagName("html")[0].getAttribute("lang") || "en"
ImprovEngine = new Improv(procgendata[lang], {
rng: () ->
return salet.rnd.randf()
filters: [
ImprovEngine.filters.mismatchFilter()
Improv.filters.mismatchFilter()
]
reincorporate: false
})
$.holdReady( false )
)
$(document).on("init", () ->
salet.character.lastBeat = () ->
return salet.progress.sequence.length - salet.character.beat
@ -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)