1
0
Fork 0
mirror of https://github.com/Oreolek/shooter.git synced 2024-04-29 23:49:19 +03:00
shooter/game/begin.coffee

74 lines
2.6 KiB
CoffeeScript
Raw Normal View History

2015-12-08 10:41:05 +02:00
situation = require('raconteur')
undum = require('undum-commonjs')
oneOf = require('raconteur/lib/oneOf.js')
qualities = require('raconteur/lib/qualities.js')
cookie = require('tiny-cookie')
2015-12-08 10:41:05 +02:00
2015-12-14 06:06:48 +02:00
# load the translations
2015-12-08 10:41:05 +02:00
undumloc = require("./translations/ru.coffee").language
undum.language["ru"] = undumloc
undumloc = require("./translations/en.coffee").language
undum.language["en"] = undumloc
2015-12-14 06:06:48 +02:00
# jQuery is used for showing the custom controls when the player clicks on title
2015-12-08 10:41:05 +02:00
$ = require("jquery")
2015-12-14 06:06:48 +02:00
# jQuery UI is for volume slider
2015-12-11 10:37:58 +02:00
require('jquery-ui/slider');
2015-12-08 10:41:05 +02:00
Array.prototype.oneOf = () ->
oneOf.apply(null, this)
2015-12-08 12:55:34 +02:00
md = require('markdown-it')
markdown = new md({
typographer: true,
html: true
})
2015-12-08 10:41:05 +02:00
2015-12-14 06:06:48 +02:00
# unique UUID
2015-12-08 10:41:05 +02:00
undum.game.id = "7a1aba32-f0fd-4e3b-ba5a-59e3fa9e6012"
2015-12-14 06:06:48 +02:00
# You bump the version each time you make a save-breaking bug, i.e. change the game logic.
# Comment and text changes should be fine.
2015-12-25 17:37:01 +02:00
undum.game.version = "3.8"
2015-12-08 10:41:05 +02:00
a = require('raconteur/lib/elements.js').a
2015-12-14 06:06:48 +02:00
# link to a different situation. Styled differently. Not used in this project.
2015-12-08 10:41:05 +02:00
way_to = (content, ref) -> a(content).class('way').ref(ref)
2015-12-14 06:06:48 +02:00
# link to a writer action. Not used in this project.
2015-12-08 10:41:05 +02:00
textlink = (content, ref) -> a(content).once().writer(ref)
textcycle = (content, ref) -> a(content).replacer(ref).class("cycle").id(ref).toString()
# Cycling link. It's implied there can be only one per situation.
# You are welcome to improve this code.
2015-12-13 08:50:43 +02:00
cycle = (obj, character) ->
responses = obj.cycle_gallery()
2015-12-13 08:50:43 +02:00
character.sandbox.cycle_index ?= [] # initialize with empty array
character.sandbox.cycle_index[obj.name] ?= 0 # initialize with 0
response = responses[character.sandbox.cycle_index[obj.name]]
character.sandbox.cycle_index[obj.name]++
if character.sandbox.cycle_index[obj.name] == responses.length
character.sandbox.cycle_index[obj.name] = 0
return textcycle(response, 'cyclewriter')
2015-12-14 06:06:48 +02:00
# usage: writemd( system, "Text to write")
2015-12-08 10:41:05 +02:00
writemd = (system, text) ->
if typeof text is Function
text = text()
system.write(markdown.render(text))
2015-12-14 06:06:48 +02:00
# The first situation. It should be before is_visited because is_visited expects
# the situations array to be already initialized with something.
2015-12-08 10:41:05 +02:00
situation "start",
cycle_gallery: () -> "christine".l()
2015-12-13 08:50:43 +02:00
content: (character) ->
return "start".l()(cycle(this, character))
2015-12-08 10:41:05 +02:00
choices: ["#start"],
writers:
2015-12-13 08:50:43 +02:00
cyclewriter: (character) -> cycle(this, character)
2015-12-08 10:41:05 +02:00
is_visited = (situation) ->
situations = undum.game.situations[situation]
if situations
return Boolean situations.visited
return 0
2015-12-11 10:37:58 +02:00
# Volume from 0 to 1
get_volume = () ->
2015-12-12 16:28:05 +02:00
return ($('#slider').slider('value') - 1) / 100