mirror of
https://gitlab.com/Oreolek/cloak-salet.git
synced 2024-06-26 12:00:53 +03:00
124 lines
3.5 KiB
CoffeeScript
124 lines
3.5 KiB
CoffeeScript
salet.game_id = "8b0c371c-57f4-49b3-ae3c-cba07d1a9733"
|
|
salet.game_version = "1.0"
|
|
salet.beforeAction = (roomId, actionId) ->
|
|
verbRe = /verb\_(?:\w+)\_(?:\w+)/
|
|
match = verbRe.exec(actionId)
|
|
if match? and match[1] and match[2]
|
|
verb = match[1]
|
|
unit = match[2]
|
|
salet.view.write(salet.rooms[roomId].units[unit][verb].fcall(salet.rooms[roomId]))
|
|
return true # consume the action
|
|
return false
|
|
|
|
$.holdReady( true )
|
|
$.getJSON('game/translations/'+i18n.lang+'.json', (data) ->
|
|
i18n.push(i18n.lang, data)
|
|
|
|
$.holdReady( false )
|
|
)
|
|
|
|
switchTab = (tabid) ->
|
|
$(".tab").removeClass("active")
|
|
$("#"+tabid).addClass("active")
|
|
|
|
$(document).ready(() ->
|
|
window.addEventListener('popstate', (event) ->
|
|
salet.goBack()
|
|
)
|
|
$("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
|
|
)
|
|
$("body").on("click", "#storytab", (event) ->
|
|
event.preventDefault()
|
|
if not salet.here().canSave
|
|
salet.goBack()
|
|
return false
|
|
)
|
|
$("body").on("click", ".tab", (event) ->
|
|
switchTab(event.target.id)
|
|
return true
|
|
)
|
|
|
|
salet.beginGame()
|
|
)
|
|
|
|
updateverb = (unit, verb) ->
|
|
if unit[verb]? or salet.character.displayAll
|
|
$("##{verb}list").append("<li><a href='./verb_#{verb}_#{unit.name}'>#{unit.display()}</a></li>")
|
|
|
|
###
|
|
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>"
|
|
|
|
sysroom = (name, options) ->
|
|
options.canSave = false
|
|
options.enter = () ->
|
|
$("#inventory").hide()
|
|
options.exit = () ->
|
|
$("#inventory").show()
|
|
options.dsc = () ->
|
|
return @text.fcall()+"\n\n"+"""
|
|
<div class="center"><a href="./exit"><button class="btn btn-lg btn-outline-primary">Go back</button></a></div>
|
|
"""
|
|
options.actions = {
|
|
exit: () ->
|
|
return salet.goBack()
|
|
}
|
|
return room(name, options)
|
|
|
|
croom = (name, spec) ->
|
|
spec.clear ?= true
|
|
spec.optionColor ?= ""
|
|
spec.optionText ?= () ->
|
|
retval = """
|
|
<div class="#{spec.optionColor}">
|
|
<div class="title">#{spec.title.fcall()}</div>
|
|
"""
|
|
if (spec.subtitle?)
|
|
retval += """
|
|
<div class="subtitle">#{spec.subtitle.fcall()}</div>
|
|
"""
|
|
retval += '</div>'
|
|
spec.enter = () ->
|
|
salet.character.update_sidebar()
|
|
if @onEnter?
|
|
@onEnter()
|
|
return room(name, spec)
|
|
|
|
sysroom "inventory",
|
|
text: () ->
|
|
if salet.character.inventory.length == 0
|
|
text = "You are carrying nothing."
|
|
else
|
|
text = "You are carrying:\n\n"
|
|
for thing in salet.character.inventory
|
|
text += "* #{salet.character.listinv(thing.name)}\n"
|
|
|
|
sysroom "settings",
|
|
text: () ->
|
|
nightclass = ""
|
|
if window.night
|
|
nightclass = "active"
|
|
return "credits".l() + """
|
|
<button id="filter" class="btn btn-outline-primary}">#{"showall".l()}</button>
|
|
|
|
<button id="night" class="btn btn-outline-primary #{nightclass}">#{"night".l()}</button>
|
|
|
|
<button onclick="TogetherJS(this); return false;" class="btn btn-outline-primary">#{"multiplayer".l()}</button>
|
|
"""
|