rename internals of round model for readability
This commit is contained in:
parent
85b9c2459c
commit
81bbad1319
@ -36,16 +36,10 @@ export class Round extends EventTarget {
|
|||||||
/** The event triggered when the round is won. */
|
/** The event triggered when the round is won. */
|
||||||
static winEvent= "roundWon";
|
static winEvent= "roundWon";
|
||||||
|
|
||||||
/** The maximum the "we" team may raise to.
|
/** The maximum the "we" team may raise to. */
|
||||||
*
|
#ourLimit = 11;
|
||||||
* @todo rename to ourLimit
|
/** The maximum the "they" team may raise to. */
|
||||||
*/
|
#theirLimit = 11;
|
||||||
#weLimit = 11;
|
|
||||||
/** The maximum the "they" team may raise to.
|
|
||||||
*
|
|
||||||
* @todo rename to theirLimit
|
|
||||||
*/
|
|
||||||
#theyLimit = 11;
|
|
||||||
|
|
||||||
constructor(value, theyLimit) {
|
constructor(value, theyLimit) {
|
||||||
super();
|
super();
|
||||||
@ -53,11 +47,12 @@ export class Round extends EventTarget {
|
|||||||
if (value === undefined && theyLimit === undefined) {
|
if (value === undefined && theyLimit === undefined) {
|
||||||
} else if (typeof value === "number" && typeof theyLimit === "number") {
|
} else if (typeof value === "number" && typeof theyLimit === "number") {
|
||||||
if (value < this.#points)
|
if (value < this.#points)
|
||||||
throw new RangeError("`weLimit` must be larger than default points");
|
throw new RangeError("`ourLimit` must be larger than default points");
|
||||||
if (theyLimit < this.#points)
|
if (theyLimit < this.#points)
|
||||||
throw new RangeError("`theyLimit` must be larger than default points");
|
throw new RangeError(
|
||||||
this.#weLimit = value;
|
"`theirLimit` must be larger than default points");
|
||||||
this.#theyLimit = theyLimit;
|
this.#ourLimit = value;
|
||||||
|
this.#theirLimit = theyLimit;
|
||||||
} else if (typeof value === "object" && theyLimit === undefined) {
|
} else if (typeof value === "object" && theyLimit === undefined) {
|
||||||
this.#fromStruct(value);
|
this.#fromStruct(value);
|
||||||
} else {
|
} else {
|
||||||
@ -138,12 +133,12 @@ export class Round extends EventTarget {
|
|||||||
|
|
||||||
if (!this.canRaise(team)) return;
|
if (!this.canRaise(team)) return;
|
||||||
|
|
||||||
if (team === Team.We && this.points >= this.#weLimit) {
|
if (team === Team.We && this.points >= this.#ourLimit) {
|
||||||
this.winner = Team.They;
|
this.winner = Team.They;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (team === Team.They && this.points >= this.#theyLimit) {
|
if (team === Team.They && this.points >= this.#theirLimit) {
|
||||||
this.winner = Team.We;
|
this.winner = Team.We;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -170,8 +165,8 @@ export class Round extends EventTarget {
|
|||||||
points: this.#points,
|
points: this.#points,
|
||||||
raisedLast: this.#raisedLast,
|
raisedLast: this.#raisedLast,
|
||||||
winner: this.#winner,
|
winner: this.#winner,
|
||||||
ourLimit: this.#weLimit,
|
ourLimit: this.#ourLimit,
|
||||||
theirLimit: this.#theyLimit,
|
theirLimit: this.#theirLimit,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -202,12 +197,12 @@ export class Round extends EventTarget {
|
|||||||
throw new TypeError("struct must contain ourLimit as number");
|
throw new TypeError("struct must contain ourLimit as number");
|
||||||
if (!Number.isInteger(value.ourLimit) || value.ourLimit < 2)
|
if (!Number.isInteger(value.ourLimit) || value.ourLimit < 2)
|
||||||
throw new RangeError("struct must contain ourLimit >= 2 as integer");
|
throw new RangeError("struct must contain ourLimit >= 2 as integer");
|
||||||
this.#weLimit = value.ourLimit;
|
this.#ourLimit = value.ourLimit;
|
||||||
|
|
||||||
if (typeof value.theirLimit !== "number")
|
if (typeof value.theirLimit !== "number")
|
||||||
throw new TypeError("struct must contain theirLimit as number");
|
throw new TypeError("struct must contain theirLimit as number");
|
||||||
if (!Number.isInteger(value.theirLimit) || value.theirLimit < 2)
|
if (!Number.isInteger(value.theirLimit) || value.theirLimit < 2)
|
||||||
throw new RangeError("struct must contain theirLimit >= 2 as integer");
|
throw new RangeError("struct must contain theirLimit >= 2 as integer");
|
||||||
this.#theyLimit = value.theirLimit;
|
this.#theirLimit = value.theirLimit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user