html/core/engine.js in gamefic-sdk-1.3.1 vs html/core/engine.js in gamefic-sdk-1.4.0
- old
+ new
@@ -5,15 +5,15 @@
var responseCallbacks = {};
var lastInput = null;
var lastPrompt = null;
var getResponse = function(withOutput) {
var r = {
- output: (withOutput ? Opal.GameficOpal.$static_player().$state().$output() : null),
- state: Opal.GameficOpal.$static_plot().$scenes().$fetch(Opal.GameficOpal.$static_player().$character().$scene()).$state(),
+ output: (withOutput ? Opal.GameficOpal.$static_user().$flush() : null),
+ state: Opal.GameficOpal.$static_plot().$scenes().$fetch(Opal.GameficOpal.$static_character().$scene()).$type(),
prompt: lastPrompt,
input: lastInput,
- testing: (Opal.GameficOpal.$static_player().$test_queue().$length() > 0)
+ testing: (Opal.GameficOpal.$static_character().$queue().$length() > 0)
}
return r;
}
var doReady = function(response) {
startCallbacks.forEach(function(callback) {
@@ -24,45 +24,48 @@
var handler = responseCallbacks[response.state] || responseCallbacks['Active'];
handler(response);
}
return {
start: function() {
- Opal.GameficOpal.$load_scripts();
- Opal.GameficOpal.$static_plot().$introduce(Opal.GameficOpal.$static_player().$character());
- lastPrompt = Opal.GameficOpal.$static_plot().$scenes().$fetch(Opal.GameficOpal.$static_player().$character().$scene()).$prompt();
+ Opal.GameficOpal.$load_scripts();
+ Opal.GameficOpal.$static_plot().$introduce(Opal.GameficOpal.$static_character());
+ lastPrompt = Opal.GameficOpal.$static_plot().$scenes().$fetch(Opal.GameficOpal.$static_character().$scene()).$prompt_for(Opal.GameficOpal.$static_character());
var response = getResponse(true);
doReady(response);
handle(response);
finishCallbacks.forEach(function(callback) {
callback(response);
});
},
update: function(input) {
if (input != null) {
- Opal.GameficOpal.$static_player().$character().$queue().$push(input);
+ Opal.GameficOpal.$static_character().$queue().$push(input);
}
lastInput = input;
var response = getResponse(false);
inputCallbacks.forEach(function(callback) {
callback(response);
});
Opal.GameficOpal.$static_plot().$update();
Opal.GameficOpal.$static_plot().$ready();
- lastPrompt = Opal.GameficOpal.$static_plot().$scenes().$fetch(Opal.GameficOpal.$static_player().$character().$scene()).$prompt();
+ lastPrompt = Opal.GameficOpal.$static_plot().$scenes().$fetch(Opal.GameficOpal.$static_character().$scene()).$prompt_for(Opal.GameficOpal.$static_character());
response = getResponse(true);
var updateResponse = response;
doReady(response);
- lastPrompt = Opal.GameficOpal.$static_plot().$scenes().$fetch(Opal.GameficOpal.$static_player().$character().$scene()).$prompt();
+ lastPrompt = Opal.GameficOpal.$static_plot().$scenes().$fetch(Opal.GameficOpal.$static_character().$scene()).$prompt_for(Opal.GameficOpal.$static_character());
response = getResponse(true);
response.output = updateResponse.output + response.output;
handle(response);
finishCallbacks.forEach(function(callback) {
callback(response);
});
- var testCommand = Opal.GameficOpal.$static_player().$test_queue().$shift();
+ /*var testCommand = Opal.GameficOpal.$static_character().$queue().$shift();
if (typeof testCommand == 'string') {
setTimeout("Gamefic.update(" + JSON.stringify(testCommand) + ");", 1);
+ }*/
+ if (Opal.GameficOpal.$static_character().$queue().$length() > 0) {
+ setTimeout("Gamefic.update();", 1);
}
},
onStart: function(callback) {
startCallbacks.push(callback);
},
@@ -76,17 +79,17 @@
responseCallbacks[state] = callback;
},
save: function(filename, data) {
var json = Opal.JSON.$generate(data);
localStorage.setItem(filename, json);
- Opal.GameficOpal.$static_player().$character().$tell('Game saved.');
+ Opal.GameficOpal.$static_character().$tell('Game saved.');
},
restore: function(filename) {
var data = Opal.JSON.$parse(localStorage.getItem(filename));
var metadata = data.$fetch('metadata');
// HACK Converting hashes to strings for JavaScript comparison
if (metadata.$to_s() != Opal.GameficOpal.$static_plot().$metadata().$to_s()) {
- Opal.GameficOpal.$static_player().$character().$tell('The saved data is not compatible with this version of the game.');
+ Opal.GameficOpal.$static_character().$tell('The saved data is not compatible with this version of the game.');
return Opal.nil;
} else {
return data;
}
}