:value="v.id"
:selected="newchallenge.vid==v.id"
)
- | {{ v.name }}
+ | {{ v.display }}
fieldset
label(for="cadence") {{ st.tr["Cadence"] }} *
div#predefinedCadences
"st.variants": function() {
// Set potential challenges and games variant names:
this.challenges.concat(this.games).forEach(o => {
- if (!o.vname) o.vname = this.getVname(o.vid);
+ if (!o.vname) this.setVname(o);
});
if (!this.newchallenge.V && this.newchallenge.vid > 0)
this.loadNewchallVariant();
// Automatic challenge sending, for tournaments
this.loadNewchallVariant(
() => {
- this.newchallenge = {
- fen: "",
- vid:
- this.st.variants
- .find(v => v.name == this.$route.query["variant"])
- .id,
- to: this.$route.query["challenge"],
- color: this.$route.query["color"] || '',
- cadence: this.$route.query["cadence"],
- // Tournament: no randomness (TODO: for now at least)
- randomness: 0,
- memorize: false
- };
+ Object.assign(
+ this.newchallenge,
+ {
+ fen: "",
+ vid:
+ this.st.variants
+ .find(v => v.name == this.$route.query["variant"])
+ .id,
+ to: this.$route.query["challenge"],
+ color: this.$route.query["color"] || '',
+ cadence: this.$route.query["cadence"],
+ // Tournament: no randomness (TODO: for now at least)
+ randomness: 0,
+ memorize: false
+ }
+ );
window.doClick("modalNewgame");
//this.issueNewChallenge(); //NOTE: doesn't work yet.
},
const type = this.classifyObject(c);
const vname = this.getVname(c.vid);
return Object.assign(
- {},
{
type: type,
vname: vname,
this.conn.send(JSON.stringify(Object.assign({ code: code }, obj)));
}
},
- getVname: function(vid) {
- const variant = this.st.variants.find(v => v.id == vid);
+ setVname: function(obj) {
+ const variant = this.st.variants.find(v => v.id == obj.vid);
// this.st.variants might be uninitialized (variant == null)
- return variant ? variant.name : "";
+ if (!!variant) {
+ obj.vname = variant.name;
+ obj.vdisp = variant.display;
+ }
+ // NOTE: Next line is used in loadNewchallVariant
+ return (!variant ? "" : variant.name);
},
filterChallenges: function(type) {
return this.challenges.filter(c => c.type == type);
) {
let newGame = game;
newGame.type = this.classifyObject(game);
- newGame.vname = this.getVname(game.vid);
+ this.setVname(game);
if (!game.score)
// New game from Hall
newGame.score = "*";
}
this.cursor = res.games[L - 1].created;
let moreGames = res.games.map(g => {
- const vname = this.getVname(g.vid);
- return Object.assign(
- {},
- g,
- {
- type: "corr",
- vname: vname
- }
- );
+ this.setVname(g);
+ g.type = "corr";
+ return g;
});
this.games = this.games.concat(moreGames);
}
let fromValues = Object.assign({}, this.people[chall.from]);
delete fromValues["pages"]; //irrelevant in this context
newChall.from = Object.assign({ sid: chall.from }, fromValues);
- newChall.vname = this.getVname(newChall.vid);
+ this.setVname(newChall);
this.challenges.push(newChall);
if (
(newChall.type == "live" && this.cdisplay == "corr") ||
}
},
loadNewchallVariant: async function(cb, vname) {
- vname = vname || this.getVname(this.newchallenge.vid);
+ vname = vname || this.setVname(this.newchallenge);
await import("@/variants/" + vname + ".js")
.then((vModule) => {
window.V = vModule[vname + "Rules"];
this.newchallenge.V = window.V;
- this.newchallenge.vname = vname;
if (!!cb) cb();
});
},
this.challenges.splice(challToDelIdx, 1);
}
this.send("newchallenge", {
- data: Object.assign({ from: this.st.user.sid }, chall)
+ data: Object.assign(
+ // Temporarily add sender infos to display challenge on Discord.
+ { from: this.st.user.sid, sender: this.st.user.name }, chall)
});
// Add new challenge:
chall.from = {
// on game just after, the main Hall will be notified.
};
if (c.type == "live") {
+ // TODO: ask my IP + opp IP, to add to game infos? (potential bans)
notifyNewgame();
this.startNewGame(gameInfo);
// Increment game stats counter in DB
},
// NOTE: for live games only (corr games start on the server)
startNewGame: function(gameInfo) {
+ this.setVname(gameInfo);
const game = Object.assign(
{},
gameInfo,
{
// (other) Game infos: constant
fenStart: gameInfo.fen,
- vname: this.getVname(gameInfo.vid),
created: Date.now(),
// Game state (including FEN): will be updated
moves: [],