added viewAs method
This commit is contained in:
parent
0bff5554ed
commit
d2f55c7e71
3 changed files with 42 additions and 1 deletions
|
@ -43,7 +43,12 @@
|
|||
</div>
|
||||
<div id="options" style="display: none;" class="box">
|
||||
<h3>Options</h3>
|
||||
<select id="options-skin"></select><br/><br/>
|
||||
<select id="options-skin"></select>
|
||||
<select id="view-as" style="display: none;">
|
||||
<option value="player-a">View as player A</option>
|
||||
<option value="player-b">View as player B</option>
|
||||
</select>
|
||||
<br/><br/>
|
||||
<label id="options-notation" for="options-notation-input">
|
||||
<input id="options-notation-input" type="checkbox"/> Notation<br/>
|
||||
</label>
|
||||
|
|
|
@ -159,6 +159,21 @@ $(document).ready(function () {
|
|||
|
||||
});
|
||||
|
||||
if(config.view.switchable)
|
||||
$("#view-as").show().on("change",()=>{
|
||||
var playerMode = $("#view-as").val();
|
||||
var player;
|
||||
if(playerMode=="player-a")
|
||||
player = Jocly.PLAYER_A;
|
||||
else if(playerMode=="player-b")
|
||||
player = Jocly.PLAYER_B;
|
||||
if(player)
|
||||
match.viewAs(player)
|
||||
.then( () => {
|
||||
RunMatch(match,progressBar);
|
||||
});
|
||||
});
|
||||
|
||||
// configure computer levels
|
||||
["a","b"].forEach( (which) => {
|
||||
$("#level-"+which).hide();
|
||||
|
|
|
@ -883,6 +883,27 @@
|
|||
return ProxiedMethod(this,"getConfig");
|
||||
}
|
||||
|
||||
GameProxy.prototype.viewAs = function(player) {
|
||||
if(jsContext=="node")
|
||||
return Promise.reject(new Error("viewAs(): not supported in node.js"));
|
||||
if(!this.area && !this.iframe)
|
||||
return Promise.reject(new Error("viewAs(): match is not attached to DOM element"));
|
||||
|
||||
if(this.game) {
|
||||
var self = this;
|
||||
|
||||
var promise = new Promise( function(resolve, reject) {
|
||||
self.game.GameDestroyView();
|
||||
self.game.mViewAs = player;
|
||||
self.game.GameInitView();
|
||||
self.game.DisplayBoard();
|
||||
resolve();
|
||||
});
|
||||
return promise;
|
||||
} else
|
||||
return ProxiedMethod(this,"viewAs",arguments);
|
||||
}
|
||||
|
||||
exports.createMatch = CreateMatch;
|
||||
exports._createInternalGame = CreateInternalGame; // do not use this
|
||||
|
||||
|
|
Loading…
Reference in a new issue