ludumdare37/game/begin.coffee

104 lines
2.7 KiB
CoffeeScript
Raw Normal View History

dialogue = require('../../lib/dialogue.coffee')
phrase = require('../../lib/phrase.coffee')
#oneOf = require('../../lib/oneOf.coffee')
require('salet')
ImprovEngine = require('improv')
Improv = {}
i18n.push("ru", require('../../game/language/ru.coffee'))
i18n.push("en", require('../../game/language/en.coffee'))
salet.game_id = "0ee0825d-0c71-4a08-bfe5-730e575df26d"
salet.game_version = "1.0"
$.getJSON('game/procgen/'+i18n.lang+'.json', (data) ->
Improv = new ImprovEngine(data, {
filters: [
ImprovEngine.filters.mismatchFilter()
]
reincorporate: false
})
$.holdReady( false )
)
salet.init = () ->
salet.character.lastBeat = () ->
return salet.progress.sequence.length - salet.character.beat
2016-12-11 17:12:06 +02:00
salet.character.newBeat = () ->
salet.character.beat = salet.progress.sequence.length
$(document).ready(() ->
window.addEventListener('popstate', (event) ->
salet.goBack()
)
$("#night").on("click", () ->
if (window.night)
styles = {
"-webkit-filter": ""
"filter": ""
"background-color": ""
}
$("body").css(styles)
$("#night").removeClass("active")
window.night = false
else
styles = {
"-webkit-filter": "invert(1)hue-rotate(180deg)"
"filter": "invert(1)hue-rotate(180deg)"
"background-color": "#000"
}
$("body").css(styles)
$("#night").addClass("active")
window.night = true
)
salet.beginGame()
)
###
Element helpers. There is no real need to build monsters like a().id("hello")
because you won't use them as is. It does not make sense in context, the
author has Markdown and all utilities to *forget* about the markup.
###
way_to = (content, ref) ->
return "<a href='#{ref}' class='way'>#{content}</a>"
textlink = (content, ref) ->
return "<a href='./_writer_#{ref}' class='once'>#{content}</a>"
actlink = (content, ref) ->
return "<a href='./#{ref}' class='once'>#{content}</a>"
class ImprovModel
constructor: () ->
@tags = []
getTag: (tagName) ->
for tag in @tags
if tag[0] == tagName
return tag[1]
return undefined
hasTag: (tagName) ->
for tag in @tags
if tag[0] == tagName
return true
return false
setTag: (tagName, value) ->
for tag, index in @tags
if tag[0] == tagName
@tags[index][1] = value
return true
@tags.push([tagName, value])
return true
setTagIfNotPresent: (tagName, value) ->
if @getTag(tagName) == undefined
@tags.push([tagName, value])
2016-12-11 17:12:06 +02:00
cunit = (name, spec) ->
spec.act = () ->
salet.view.clearContent()
salet.here().entering("start")
return '<em>'+@enact.fcall(this)+'</em>'
return unit(name, spec)
state = new ImprovModel
procgen = (tag) ->
return Improv.gen(tag, state)