1
0
Fork 0
Browse Source

Deepstream WIP

master
Alexander Yakovlev 5 years ago
parent
commit
0f452e95a0
  1. 45
      game/begin.coffee
  2. 3
      game/translations/ru.cson
  3. 2
      html/index.html
  4. 6
      package.json
  5. 12
      sass/main.scss
  6. 16
      server.js

45
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)

3
game/translations/ru.cson

@ -4,7 +4,10 @@ intro: """
Астрид спит и видит себя.
Во сне все люди равны, потому что все они — Астрид.
"""
no_local_storage: "Локальное хранилище недоступно."
erase_message: "Это навсегда удалит вашего персонажа и немедленно вернёт вас на старт игры. Вы уверены?"
room_enter: "В комнату входит "
room_present: "В комнате стоят "
entry_option: "Быть Астрид"
entry_title: "Прихожая"
entry_dsc: """

2
html/index.html

@ -58,7 +58,7 @@
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/marked/0.3.5/marked.min.js" crossorigin="anonymous"></script>
<script type="text/javascript" src="https://code.jquery.com/jquery-3.1.1.min.js" crossorigin="anonymous"></script>
<script type="text/javascript" src="game/salet.min.js"></script>
<script src="https://cdn.ably.io/lib/ably.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/deepstream.io-client-js/2.1.1/deepstream.js"></script>
<script type="text/javascript" defer="defer" src="game/main.js"></script>
</body>

6
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"
}
}

12
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;
}
}

16
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()
Loading…
Cancel
Save