1
0
Fork 0

Deepstream WIP

This commit is contained in:
Alexander Yakovlev 2017-01-24 12:18:42 +07:00
parent f94cc8d0fe
commit 0f452e95a0
6 changed files with 59 additions and 25 deletions

View file

@ -1,7 +1,13 @@
salet.game_id = "being-astrid-is-hard-enough-but-try-living-as-one" salet.game_id = "being-astrid-is-hard-enough-but-try-living-as-one"
salet.game_version = "1.0" salet.game_version = "1.0"
ably = new Ably.Realtime('v6yAiA.PKvuDg:iJhwQu-DkAWpDOUB') client = deepstream('localhost:6020').login()
channel = ably.channels.get('astrid-'+i18n.lang) client.record.listen('presence.*', (match, isSubscribed, response) =>
if (isSubscribed)
response.accept()
else
# stop publishing data, client disconnected
client.record.getRecord(match).discard()
)
$.holdReady( true ) $.holdReady( true )
$.getJSON('game/translations/'+i18n.lang+'.json', (data) -> $.getJSON('game/translations/'+i18n.lang+'.json', (data) ->
@ -35,14 +41,6 @@ $(document).ready(() ->
window.night = true 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() salet.beginGame()
) )
@ -62,18 +60,33 @@ actlink = (content, ref) ->
# For accessibility reasons the text is provided in HTML, not here. # For accessibility reasons the text is provided in HTML, not here.
room "start", room "start",
enter: () -> enter: () ->
names = "names".l() if (salet.character.name == undefined)
salet.character.name = names[salet.rnd.randomInt(names.length)] names = "names".l()
salet.character.name = names[salet.rnd.randomInt(names.length)]
salet.character.id = salet.rnd.randn()
dsc: () -> "intro".l() dsc: () -> "intro".l()
choices: "#start" choices: "#start"
croom = (name, options) -> croom = (name, options) ->
options.enter = () -> options.enter = () ->
if (salet.interactive) if (salet.interactive)
channel.publish('enter', { status = client.record.getRecord('presence.'+@room)
room: @name, status.set('presence.'+@room+'.'+salet.character.id, salet.character.name)
name: 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 = () -> options.dsc = () ->
"### #{@title()}\n" + @desc() "### #{@title()}\n" + @desc()
return room(name,options) return room(name,options)

View file

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

View file

@ -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://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="https://code.jquery.com/jquery-3.1.1.min.js" crossorigin="anonymous"></script>
<script type="text/javascript" src="game/salet.min.js"></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> <script type="text/javascript" defer="defer" src="game/main.js"></script>
</body> </body>

View file

@ -1,7 +1,7 @@
{ {
"dependencies": { "dependencies": {
"gulp-rename": "^1.2.2", "deepstream": "0.0.0",
"salet": "^1.6.15" "deepstream.io": "^2.1.2"
}, },
"private": true, "private": true,
"devDependencies": { "devDependencies": {
@ -17,6 +17,8 @@
"gulp-zip": "^3.0.2", "gulp-zip": "^3.0.2",
"vinyl-buffer": "^1.0.0", "vinyl-buffer": "^1.0.0",
"vinyl-source-stream": "^1.1.0", "vinyl-source-stream": "^1.1.0",
"gulp-rename": "^1.2.2",
"salet": "^1.6.15",
"cson": "^4.0.0" "cson": "^4.0.0"
} }
} }

View file

@ -4,13 +4,13 @@
// The title block // The title block
.title { .title {
margin-top: 3.5em; margin-top: 3.5em;
@extend .col-xs-12; @extend .col-12;
.label { .label {
margin-top: 1.5em; margin-top: 1.5em;
margin-bottom: 1em; margin-bottom: 1em;
@extend .col-md-8; @extend .col-md-8;
@extend .offset-md-2; @extend .offset-md-2;
@extend .col-xs-12; @extend .col-12;
text-align: center; text-align: center;
} }
.subtitle { .subtitle {
@ -39,7 +39,7 @@
} }
} }
#choices { #choices {
@extend .col-xs-12; @extend .col-12;
} }
.fixed { .fixed {
position: fixed; position: fixed;
@ -70,7 +70,7 @@
.content { .content {
@extend .col-md-10; @extend .col-md-10;
@extend .offset-md-1; @extend .offset-md-1;
@extend .col-xs-12; @extend .col-12;
padding: 1em; padding: 1em;
ul { ul {
margin: 0; margin: 0;
@ -110,13 +110,13 @@
#footleft { #footleft {
@extend .col-md-5; @extend .col-md-5;
@extend .offset-md-2; @extend .offset-md-2;
@extend .col-xs-12; @extend .col-12;
} }
#footright { #footright {
text-align: right; text-align: right;
@extend .col-md-2; @extend .col-md-2;
@extend .offset-md-2; @extend .offset-md-2;
@extend .col-xs-12; @extend .col-12;
} }
} }

16
server.js Normal file
View file

@ -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()