Fix #45 - Store state of hugvey and allow to resume from it

This commit is contained in:
Ruben van de Ven 2019-05-11 23:40:52 +02:00
parent 08e3805819
commit cb81c0616e
3 changed files with 32 additions and 19 deletions

View file

@ -577,18 +577,16 @@ class HugveyState(object):
if not self.story:
self.logger.critical("No story to play message in")
else:
#restart first so that story loads the new json
# self.restart()
if self.story is None:
return
self.startMsgId = event['msg_id']
self.logger.debug(f"Restart from {self.startMsgId}")
self.restart()
# Unfortunately setCurrentMessage() doesn't cut it, as the story
# needs to be reloaded, this cannot be done with keeping the state either way
# msg = self.story.get(event['msg_id'])
# await self.story.setCurrentMessage(msg)
if event['reloadStory']:
self.startMsgId = event['msg_id']
self.logger.debug(f"Restart from {self.startMsgId}")
self.restart()
else:
msg = self.story.get(event['msg_id'])
await self.story.setCurrentMessage(msg)
self.eventQueue = None

View file

@ -69,7 +69,7 @@ def getWebSocketHandler(central_command):
elif msg['action'] == 'change_light':
self.msgChangeLightId(msg['hugvey'], int(msg['light_id']))
elif msg['action'] == 'play_msg':
self.msgPlayMsg(msg['hugvey'], msg['msg_id'])
self.msgPlayMsg(msg['hugvey'], msg['msg_id'], msg['reloadStory'])
else:
self.send({'alert': 'Unknown request: {}'.format(message)})
logger.warn('Unknown request: {}'.format(message))
@ -125,8 +125,8 @@ def getWebSocketHandler(central_command):
def msgChangeLightId(self, hv_id, lightId):
central_command.hugveys[hv_id].eventQueue.put_nowait({'event': 'change_light', 'light_id': lightId})
def msgPlayMsg(self, hv_id, msg_id):
central_command.hugveys[hv_id].eventQueue.put_nowait({'event': 'play_msg', 'msg_id': msg_id})
def msgPlayMsg(self, hv_id, msg_id, reloadStory):
central_command.hugveys[hv_id].eventQueue.put_nowait({'event': 'play_msg', 'msg_id': msg_id, 'reloadStory':bool(reloadStory)})
@classmethod
def write_to_clients(wsHandlerClass, msg):

View file

@ -237,11 +237,11 @@ class Panopticon {
this.send( { action: 'change_light', hugvey: hv_id, light_id: light_id } );
}
playFromSelected(msg_id) {
playFromSelected(msg_id, reloadStory) {
if(!this.hugveys.selectedId) {
alert('No hugvey selected');
} else {
this.send({ action: 'play_msg', hugvey: this.hugveys.selectedId, msg_id: msg_id })
this.send({ action: 'play_msg', hugvey: this.hugveys.selectedId, msg_id: msg_id, reloadStory: reloadStory })
}
}
}
@ -1073,7 +1073,7 @@ class Graph {
if(panopticon.hugveys.selectedId) {
let playEl = crel(
msgEl.appendChild(crel(
'div',
{'class': 'play'},
crel(
@ -1084,15 +1084,30 @@ class Graph {
console.log('go save');
panopticon.graph.saveJson(null, null, function(){
console.log('saved, now play');
panopticon.playFromSelected(msg['@id']);
panopticon.playFromSelected(msg['@id'], true);
});
}
}
},
"Save & play on #" + panopticon.hugveys.selectedId
)
);
msgEl.appendChild(playEl);
));
msgEl.appendChild(crel(
'div',
{'class': 'play'},
crel(
'div', {
'class': 'btn btn--play',
'on': {
'click': function (e) {
panopticon.playFromSelected(msg['@id'], false);
}
}
},
"Continue on #" + panopticon.hugveys.selectedId
)
));
}