diff --git a/game/begin.coffee b/game/begin.coffee index 80d02b1..ee82b09 100644 --- a/game/begin.coffee +++ b/game/begin.coffee @@ -1,7 +1,13 @@ salet.game_id = "being-astrid-is-hard-enough-but-try-living-as-one" salet.game_version = "1.0" -ably = new Ably.Realtime('v6yAiA.PKvuDg:iJhwQu-DkAWpDOUB') -channel = ably.channels.get('astrid-'+i18n.lang) +client = deepstream('localhost:6020').login() +client.record.listen('presence.*', (match, isSubscribed, response) => + if (isSubscribed) + response.accept() + else + # stop publishing data, client disconnected + client.record.getRecord(match).discard() +) $.holdReady( true ) $.getJSON('game/translations/'+i18n.lang+'.json', (data) -> @@ -35,14 +41,6 @@ $(document).ready(() -> window.night = true ) - channel.subscribe('enter', (message) -> - if ( - message.data.room == salet.current and - message.data.name != salet.character.name - ) - salet.view.write("room_enter".l()+message.data.name+".") - ) - salet.beginGame() ) @@ -62,18 +60,33 @@ actlink = (content, ref) -> # For accessibility reasons the text is provided in HTML, not here. room "start", enter: () -> - names = "names".l() - salet.character.name = names[salet.rnd.randomInt(names.length)] + if (salet.character.name == undefined) + names = "names".l() + salet.character.name = names[salet.rnd.randomInt(names.length)] + salet.character.id = salet.rnd.randn() dsc: () -> "intro".l() choices: "#start" croom = (name, options) -> options.enter = () -> if (salet.interactive) - channel.publish('enter', { - room: @name, - name: salet.character.name - }) + status = client.record.getRecord('presence.'+@room) + status.set('presence.'+@room+'.'+salet.character.id, salet.character.name) + players = status.get() + if players.length > 1 + salet.view.write("room_present".l()) + names = [] + for player in players + if player == 'presence.'+@room+'.'+salet.character.id + continue + i = client.record.getRecord(player) + names.push(i) + salet.view.write(names.join(', ')) + options.exit = () -> + if (salet.interactive) + status = client.record.getRecord('presence') + status.delete('presence.'+@name+'.'+salet.character.id) + options.dsc = () -> "### #{@title()}\n" + @desc() return room(name,options) diff --git a/game/translations/ru.cson b/game/translations/ru.cson index 464fe4c..db1fbb5 100644 --- a/game/translations/ru.cson +++ b/game/translations/ru.cson @@ -4,7 +4,10 @@ intro: """ Астрид спит и видит себя. Во сне все люди равны, потому что все они — Астрид. """ +no_local_storage: "Локальное хранилище недоступно." +erase_message: "Это навсегда удалит вашего персонажа и немедленно вернёт вас на старт игры. Вы уверены?" room_enter: "В комнату входит " +room_present: "В комнате стоят " entry_option: "Быть Астрид" entry_title: "Прихожая" entry_dsc: """ diff --git a/html/index.html b/html/index.html index 2b4f6dc..6833cf8 100644 --- a/html/index.html +++ b/html/index.html @@ -58,7 +58,7 @@ - + diff --git a/package.json b/package.json index 0db82d1..e6e5535 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "dependencies": { - "gulp-rename": "^1.2.2", - "salet": "^1.6.15" + "deepstream": "0.0.0", + "deepstream.io": "^2.1.2" }, "private": true, "devDependencies": { @@ -17,6 +17,8 @@ "gulp-zip": "^3.0.2", "vinyl-buffer": "^1.0.0", "vinyl-source-stream": "^1.1.0", + "gulp-rename": "^1.2.2", + "salet": "^1.6.15", "cson": "^4.0.0" } } diff --git a/sass/main.scss b/sass/main.scss index cfb0e79..f515202 100644 --- a/sass/main.scss +++ b/sass/main.scss @@ -4,13 +4,13 @@ // The title block .title { margin-top: 3.5em; - @extend .col-xs-12; + @extend .col-12; .label { margin-top: 1.5em; margin-bottom: 1em; @extend .col-md-8; @extend .offset-md-2; - @extend .col-xs-12; + @extend .col-12; text-align: center; } .subtitle { @@ -39,7 +39,7 @@ } } #choices { - @extend .col-xs-12; + @extend .col-12; } .fixed { position: fixed; @@ -70,7 +70,7 @@ .content { @extend .col-md-10; @extend .offset-md-1; - @extend .col-xs-12; + @extend .col-12; padding: 1em; ul { margin: 0; @@ -110,13 +110,13 @@ #footleft { @extend .col-md-5; @extend .offset-md-2; - @extend .col-xs-12; + @extend .col-12; } #footright { text-align: right; @extend .col-md-2; @extend .offset-md-2; - @extend .col-xs-12; + @extend .col-12; } } diff --git a/server.js b/server.js new file mode 100644 index 0000000..910edc1 --- /dev/null +++ b/server.js @@ -0,0 +1,16 @@ +const DeepstreamServer = require('deepstream.io') +const C = DeepstreamServer.constants +/* + * The server can take + * 1) a configuration file path + * 2) null to explicitly use defaults to be overriden by server.set() + * 3) left empty to load the base configuration from the config file located within the conf directory. + * 4) pass some options, missing options will be merged with the base configuration + * */ +const server = new DeepstreamServer({ + host: 'localhost', + port: 6020 +}) + +// start the server +server.start()