121 lines
3.4 KiB
CoffeeScript
121 lines
3.4 KiB
CoffeeScript
salet.game_id = "being-astrid-is-hard-enough-but-try-living-as-one"
|
|
salet.game_version = "1.0"
|
|
client = deepstream('localhost:6020').login()
|
|
|
|
$.holdReady( true )
|
|
$.getJSON('game/translations/'+i18n.lang+'.json', (data) ->
|
|
i18n.push(i18n.lang, data)
|
|
|
|
$.holdReady( false )
|
|
)
|
|
|
|
$(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()
|
|
)
|
|
|
|
salet.init = () ->
|
|
names = "names".l()
|
|
salet.character.name = names[salet.rnd.randomInt(names.length)]
|
|
salet.character.id = salet.rnd.randn()
|
|
salet.character.color = 0
|
|
button.color = salet.rnd.randomInt(button.colors.length)
|
|
|
|
###
|
|
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>"
|
|
|
|
# The first room of the game.
|
|
# For accessibility reasons the text is provided in HTML, not here.
|
|
room "start",
|
|
dsc: () -> "intro".l()
|
|
choices: "#start"
|
|
|
|
button = unit "button",
|
|
colors: ["red", "blue", "green", "yellow", "orange", "violet"]
|
|
color: 0
|
|
dsc: () -> "<center><b>{{"+("color_"+@colors[@color]).l()+"}}</b></center>"
|
|
act: () ->
|
|
@color = @color + 1
|
|
if @color >= @colors.length
|
|
@color = 0
|
|
salet.character.color = @color
|
|
salet.rooms["entry"].canChoose = true
|
|
salet.view.clearContent()
|
|
salet.here().entering(salet.currentRoom)
|
|
return ""
|
|
|
|
room "instance",
|
|
dsc: () -> "instance".l()
|
|
tags: ["start"]
|
|
choices: "#instance"
|
|
optionText: () -> "begin_game".l()
|
|
exit: () ->
|
|
client.record.listen("presence.#{salet.character.color}.*", (match, isSubscribed, response) =>
|
|
if (isSubscribed)
|
|
response.accept()
|
|
else
|
|
# stop publishing data, client disconnected
|
|
client.record.getRecord(match).discard()
|
|
)
|
|
|
|
salet.rooms["instance"].take(button)
|
|
|
|
croom = (name, options) ->
|
|
options.enter = () ->
|
|
if (salet.interactive)
|
|
color = salet.character.color.toString()
|
|
status = client.record.getRecord('presence.'+color)
|
|
status.set("players."+salet.character.id, salet.character.name)
|
|
players = status.get("players")
|
|
if players.length > 1
|
|
salet.view.write("room_present".l())
|
|
names = []
|
|
for id, name of players
|
|
if name == salet.character.id
|
|
continue
|
|
names.push(name)
|
|
salet.view.write(names.join(', '))
|
|
options.dsc = () ->
|
|
"### #{@title()}\n" + @desc()
|
|
return room(name,options)
|
|
|
|
croom "entry",
|
|
canChoose: false
|
|
tags: ["instance"]
|
|
optionText: () -> "entry_option".l()
|
|
title: () -> "entry_title".l()
|
|
ways: ["corridor"]
|
|
desc: () -> "entry_dsc".l()
|