diff --git a/Gulpfile.coffee b/Gulpfile.coffee index 7cb56e3..ad697cf 100644 --- a/Gulpfile.coffee +++ b/Gulpfile.coffee @@ -46,7 +46,7 @@ html = (target, debug) -> 'node_modules/improv/dist/template.js' ]) .pipe(gulp.dest(target+"/game/improv")) - gulp.src(['/www/games/salet-module/lib/index.min.js']) + gulp.src(['node_modules/salet/lib/index.min.js']) .pipe(rename('salet.min.js')) .pipe(gulp.dest(target+"/game")) diff --git a/README.md b/README.md index ab533a9..5f64bdc 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,8 @@ Работает только в новых браузерах с поддержкой ES6. Если хотите, чтобы работало во всех браузерах, надо компилировать Improv вместе с полифиллом для babel. +Для других игр я пробовал переписывать Improv на CoffeeScript, но хочется всё-таки иметь +возможность обновляться. Сам код игры и Salet такой строгой зависимости не имеет. Код демо собран из обрезков разных игр и черновиков. Есть баги. diff --git a/game/engine.coffee b/game/engine.coffee index db232e2..be74707 100644 --- a/game/engine.coffee +++ b/game/engine.coffee @@ -51,6 +51,7 @@ setup_keys = () -> ) $(document).ready(() -> + $(".tab_wrapper").hide() window.addEventListener('popstate', (event) -> salet.goBack() ) @@ -108,6 +109,12 @@ $(document).ready(() -> salet.beginGame() ) +$(document).on('room_ru_exit', () -> + $(".tab_wrapper").show() +) +$(document).on('room_en_exit', () -> + $(".tab_wrapper").show() +) $(document).on('init', () -> salet.character.improv = new Improv(window.improvdata, { filters: [ diff --git a/game/model.coffee b/game/model.coffee index cf6db17..bc94c01 100644 --- a/game/model.coffee +++ b/game/model.coffee @@ -69,73 +69,6 @@ sysroom "inventory", for thing in salet.character.inventory text += "* #{salet.character.listinv(thing.name)}\n" -sysroom "map", - text: () -> - return "
" - after: () -> - data = { - edges: [] - nodes: [] - } - edges = [] - rooms = [] - globx = 1 - globy = 1 - deltas = [ - # [1, 0], # looks bad on our map - [0, 1], - [-1, 0], - [0, -1], - ] - for name, room of salet.rooms - if room.canSave == false or name == "start" - continue - if rooms.indexOf(name) == -1 - data.nodes.push({ - "id": name - "label": room.title() - "size": 5 - "color": "#000" - "x": globx - "y": globy - }) - rooms.push(name) - if room.ways? and room.ways.length > 0 - delta = 0 - for way in room.ways - id = "edge_"+name+"_"+way - # we don't want to display a two-way link twice - if edges.indexOf("edge_"+way+"_"+name) == -1 - edges.push(id) - data.edges.push({ - "id": id - "source": room.name - "target": way - "size": 1 - "color": "#ccc" - }) - if rooms.indexOf(way) == -1 - data.nodes.push({ - "id": way - "label": salet.rooms[way].title() - "size": 5 - "color": "#000" - "x": globx + deltas[delta][0] - "y": globy + deltas[delta][1] - }) - rooms.push(way) - delta++ - globy = globy - 2 - s = new sigma({ - graph: data, - container: 'map' - }) - s.bind('clickNode', (e) -> - switchTab("storytab") - salet.goTo(e.data.node.id) - ) - return "" - $(document).on("room_language_after_choices", () -> $(".options").addClass("narrowchoice") ) @@ -160,10 +93,6 @@ sysroom "en", i18n.lang = "en" salet.goTo('maze') -sysroom "menu", - dsc: "" - choices: "#menu" - sysroom "settings", tags: ["menu"] title: () -> "settings_title".l() @@ -190,9 +119,21 @@ sysroom "inventory", text += "* #{salet.character.listinv(thing.name)}\n" sysroom "map", - text: () -> """ - Здесь будет карта - """ + text: () -> + out = "" + for y in [0..(salet.character.maze.height-1)] + out += "" + for x in [0..(salet.character.maze.width-1)] + cell = salet.character.maze.at(x,y) + className = cell.getTag("type") + if x == salet.character.x and y == salet.character.y + className += " current" + out += "" + out += "\n" + out += "
" + out += cell.log() + out += "
" + return out Array.prototype.remove = (args...) -> output = [] @@ -309,7 +250,6 @@ tagMismatchFilter = (group, model) -> return null return score - setAdjacent = (model) -> cells = {} cells["north"] = salet.character.maze.getNorth(salet.character.x, salet.character.y) @@ -331,3 +271,9 @@ setAdjacent = (model) -> model["#{type}_direction_adverb"] = "#{direction}_adverb".l() model.tags.push(["adjacent", adjacent]) return model + +class ImprovModel + constructor: () -> + @tags = [] + # склонение существительных в родительный падеж + genitive: (word) -> diff --git a/game/plot.coffee b/game/plot.coffee index c53d1f2..15bec9d 100644 --- a/game/plot.coffee +++ b/game/plot.coffee @@ -16,6 +16,59 @@ plotscene = (title, options) -> return "" return room(title, options) +room "maze", + clear: false + priority: -10 + showTransition: true + before: (from) -> + if @showTransition == false + @showTransition = true + return "" + + salet.character.update_inventory() + currentCell = salet.character.getCell() + if currentCell.hasTag('special') + salet.character.past_x = salet.character.x + salet.character.past_y = salet.character.y + salet.saveGame() + return salet.specials[currentCell.getTag('special')]() + + model = new ImprovModel + if salet.character.past_x? + pastCell = salet.character.getCell(salet.character.past_x, salet.character.past_y) + model.tags.push(['from', pastCell.getTag('type')]) + else + model.tags.push(['from', 'outside']) + model.tags.push(['to', currentCell.getTag('type')]) + # Piwik analytics: terrain type + _paq.push(['setCustomDimension', 1, currentCell.getTag('type')]) + model = setAdjacent(model) + + salet.character.past_x = salet.character.x + salet.character.past_y = salet.character.y + return salet.character.improv.gen('transition', model) + dsc: () -> + update_paths(salet.character) + salet.character.describe() + canExit: (to) -> + model = [] + model["x"] = salet.character.x + model["y"] = salet.character.y + model[to.varname] = model[to.varname] + to.add + + # Определяем, может ли персонаж зайти на клетку. + # Некоторые типы клеток требуют особого навыка. + cell = salet.character.maze.at(model["x"], model["y"]) + if cell.getTag("type") == "lake" + salet.view.append("*#{"lake_inaccessible".l()}*") + @showTransition = false + return false + if cell.getTag("type") == "rock" + salet.view.append("*#{"rock_inaccessible".l()}") + @showTransition = false + return false + return true + ## Встреча 1 plotscene "meet1", enter: () -> diff --git a/package-lock.json b/package-lock.json index 20de3a0..e3e73e7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5661,6 +5661,11 @@ "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==", "dev": true }, + "salet": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/salet/-/salet-2.0.1.tgz", + "integrity": "sha512-Xj4W2+AOB/8LeGo9kmWvT2gXmLeC4GnPy2uhorHF8W/YVPMd+GtZ92MJ3ue2ZfuLAX9EixVtYjBBsU3XKI2t2g==" + }, "sass-graph": { "version": "2.2.4", "resolved": "https://registry.npmjs.org/sass-graph/-/sass-graph-2.2.4.tgz", diff --git a/package.json b/package.json index 0f01c9b..ba26948 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,7 @@ "browserify": "^16.2.2", "cson": "^5.1.0", "improv": "^1.0.0", + "salet": "^2.0.1", "vinyl-source-stream": "^2.0.0", "watchify": "^3.11.0" },