mapgen/game/engine.coffee

127 lines
3.2 KiB
CoffeeScript

###
# This is the file with all thing *around* Salet.
###
salet.game_id = "2868be0e-0011-4d94-87a9-1a80f65ff7f0"
salet.game_version = "1.0"
salet.optionsRoom = "settings"
salet.start = "language"
salet.autosave = false
salet.autoload = false
switchTab = (tabid) ->
$(".tab").removeClass("active")
$("#"+tabid).addClass("active")
if tabid == "story" and not salet.here().canSave
salet.goBack()
setup_keys = () ->
$(document).keydown((e) ->
if window.down != false # никаких западающих клавиш
return false
window.down = true
switch(e.which)
when 37 #left
$("#west a").click()
when 38 #up
$("#north a").click()
when 39 # right
$("#east a").click()
when 40 # down
$("#south a").click()
when 49 # 1
$(".options li:nth-child(1)").click()
when 50
$(".options li:nth-child(2)").click()
when 51
$(".options li:nth-child(3)").click()
when 52
$(".options li:nth-child(4)").click()
when 53
$(".options li:nth-child(5)").click()
when 54
$(".options li:nth-child(6)").click()
else
return
e.preventDefault()
)
$(document).keyup((e) ->
window.down = false
)
$(document).ready(() ->
window.addEventListener('popstate', (event) ->
salet.goBack()
)
$("body").on("click", ".tab", (event) ->
id = $(event.target).attr("id")
if not id?
id = $(event.target).parent().attr("id")
switchTab(id)
return true
)
$("body").on("click", '#night', () ->
if (window.night)
$("body").removeClass("night")
$("#night").removeClass("active")
window.night = false
else
$("body").addClass("night")
$("#night").addClass("active")
window.night = true
)
$("#page").on("click", "a", (event) ->
if (window.hasOwnProperty('TogetherJS') and !window.remote and TogetherJS.running)
options = {
type: "click"
}
link = $(event.target)
if link.attr("id") != undefined
options.id = link.attr("id")
if link.attr("href") != undefined
options.href = link.attr("href")
if options.href == undefined and options.id == undefined
return
TogetherJS.send(options)
)
window.remote = false
if (window.hasOwnProperty('TogetherJS'))
TogetherJS.config("ignoreForms", true)
TogetherJS.config("ignoreMessages", [
"cursor-update"
"keydown"
"scroll-update"
"form-focus"
"cursor-click"
])
TogetherJS.hub.on("click", (msg) ->
if (! msg.sameUrl)
return
window.remote = true
if msg.id != undefined
$("##{msg.id}").trigger("click")
else if msg.href != undefined
$("#page a[href=#{msg.href}]").trigger("click")
window.remote = false
)
salet.beginGame()
)
$(document).on('init', () ->
salet.character.improv = new Improv(window.improvdata, {
filters: [
tagMismatchFilter
]
reincorporate: true
})
salet.incstat = (statname) ->
if @character.statname < 10
@character.statname++
salet.decstat = (statname) ->
if @character.statname > 1
@character.statname--
salet.specials =
cedar: () ->
return "cedar".l()
)