mapgen/game/3_engine.coffee
Alexander Yakovlev 6ac5090d53
All checks were successful
default/mapgen/master This commit looks good
Ночной режим - правки CSS
Чинит #2
2018-10-09 13:55:38 +07:00

217 lines
6.2 KiB
CoffeeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

###
# This is the file with all thing *around* Salet.
###
Improv = require('improv')
improvdata = require('./procgen/ru.json')
salet.game_id = "49bff9ff-77fe-447f-be41-bc7f6fedbd48"
salet.game_version = "1.0"
salet.optionsRoom = "settings"
salet.start = "language"
salet.autosave = true
salet.autoload = true
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,65 #left
$("#west a").click()
when 38,87 #up,W
$("#north a").click()
when 39,68 # right
$("#east a").click()
when 40,83 # down
$("#south a").click()
when 77 #m
$("#map").click()
when 78 #n
$("#story").click()
when 79 #o
$("#settings").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(() ->
$(".tab_wrapper").hide()
setup_keys();
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)
$(event.target).find("a").trigger("click")
return true
)
$("body").on("click", '#night', (event) ->
if (window.night)
$("body").removeClass("night")
$("#night").removeClass("active")
window.night = false
else
$("body").addClass("night")
$("#night").addClass("active")
window.night = true
event.preventDefault()
event.stopPropagation()
)
$("#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("load_game", () ->
$(".tab_wrapper").show()
)
$(document).on('room_language_exit', () ->
$(".questline").html(marked("intro_questline".l({
bathname: salet.character.bathname
})))
)
$(document).on('room_ru_exit', () ->
$(".tab_wrapper").show()
)
$(document).on('room_en_exit', () ->
$(".tab_wrapper").show()
)
$(document).on('init', () ->
# размер поля, 1x1 это один квадратик
width = 4
height = 4
salet.character.improv ?= new Improv(improvdata, {
filters: [
tagMismatchFilter
]
bind: true
reincorporate: true
audit: true
# используем наш ЧСГ, чтобы при загрузке игры мир не перемешивался
rng: (x) ->
return salet.rnd.randf(x)
})
salet.incstat = (statname) ->
if @character.statname < 10
@character.statname++
salet.decstat = (statname) ->
if @character.statname > 1
@character.statname--
salet.specials =
cedar: () ->
return "cedar".l()
salet.character.maze ?= new Maze(width, height, salet.character.improv)
# игра начинается в одной из таверн
for y in [0..height-1]
for x in [0..width-1]
if salet.character.maze.data[x][y].getTag('type') == 'tavern'
# начальная позиция, 0:0 это левый верхний угол
salet.character.x = x
salet.character.y = y
break
salet.character.describe = () ->
return @maze.describe(@x, @y, @improv)
salet.character.getCell = (x = @x, y = @y) ->
return @maze.at(x,y)
salet.character.setCurrentCellTagIfNotPresent = (tagName, value) ->
@maze.data[@x][@y].setTagIfNotPresent(tagName, value)
return
)
direction_room = (name, varname, plus) ->
return croom(name,
# I'm sure it can be optimized but not now
title: () ->
if salet.character.workshopevent and name == "north"
return "endgame".l()
cell = salet.character.maze.getDirection(@name, salet.character.x, salet.character.y)
if cell != false and cell != undefined
return cell.getTitle()
else
return "no_direction".l()
canView: () ->
if salet.character.workshopevent and name == "north"
return true
cell = salet.character.maze.getDirection(name, salet.character.x, salet.character.y)
if cell != false and cell != undefined and cell.loctitle != undefined
return true
else
return false
subtitle: () ->
return "#{name}_direction".l()
varname: varname,
add: plus
tags: ["direction"]
dsc: false
enter: () ->
if salet.character.workshopevent and name == "north"
salet.goTo("end")
return ""
salet.character[@varname] = salet.character[@varname] + @add
salet.goTo("maze")
return ""
)
direction_room("north", "y", -1)
direction_room("west", "x", -1)
direction_room("east", "x", 1)
direction_room("south", "y", 1)