Big update
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
"scripts": {
|
||||
"build-dev": "webpack --mode development && npm postbuild",
|
||||
"build": "webpack --mode production",
|
||||
"postbuild": "rsync -avu --delete dist/ ../kadi_backend/static/game",
|
||||
"postbuild": "rsync -avu --delete dist/ ../backend/static/game",
|
||||
"start": "webpack-dev-server --mode development",
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import {ScoreCellValue} from "./ScoreCell";
|
||||
import ScoreBlock, {createBlockFromDef, BlockState, ScoreBlockJSONRepresentation} from "./ScoreBlock";
|
||||
import {BlockDef, Ruleset, CellFlag} from "../../../shared/rulesets";
|
||||
import { Memento, Originator } from "./Caretaker";
|
||||
import {BlockDef, Ruleset} from "../static/rulesets";
|
||||
import {CellFlag} from "../static/enums";
|
||||
|
||||
export type CellLocation = { blockId: string, cellId: string };
|
||||
|
||||
|
||||
@@ -4,7 +4,8 @@ import ScoreCell, {
|
||||
CellState,
|
||||
ScoreCellJSONRepresentation
|
||||
} from "./ScoreCell";
|
||||
import {CellDef, BlockDef, BonusBlockDef, NoBonusBlockDef, CellFlag } from "../../../shared/rulesets";
|
||||
import {BlockDef, BonusBlockDef, CellDef, NoBonusBlockDef} from "../static/rulesets";
|
||||
import {CellFlag} from "../static/enums";
|
||||
|
||||
export const createBlockFromDef = (blockId: string, blockDef: BlockDef) : ScoreBlock => {
|
||||
if (blockDef.hasBonus) {
|
||||
|
||||
@@ -1,12 +1,5 @@
|
||||
import {
|
||||
BoolCellDef,
|
||||
CellDef,
|
||||
CellFlag,
|
||||
FieldType,
|
||||
MultiplierCellDef,
|
||||
NumberCellDef,
|
||||
SuperkadiCellDef
|
||||
} from "../../../shared/rulesets";
|
||||
import {BoolCellDef, CellDef, FieldType, MultiplierCellDef, NumberCellDef, SuperkadiCellDef} from "../static/rulesets";
|
||||
import {CellFlag} from "../static/enums";
|
||||
|
||||
export const createCellFromDef = (cellId: string, cellDef: CellDef): ScoreCell => {
|
||||
switch (cellDef.fieldType) {
|
||||
@@ -91,9 +84,11 @@ abstract class ScoreCell {
|
||||
restoreFromJSON(jsonRep: ScoreCellJSONRepresentation): void {
|
||||
this.update(jsonRep.value);
|
||||
}
|
||||
|
||||
abstract setRandom(): void;
|
||||
}
|
||||
|
||||
type IterableSequenceValues = boolean | number | CellFlag.strike;
|
||||
type IterableSequenceValues = boolean | number;
|
||||
|
||||
abstract class IterableScoreCell extends ScoreCell {
|
||||
protected iteratedSequence: IterableSequenceValues[];
|
||||
@@ -106,7 +101,10 @@ abstract class IterableScoreCell extends ScoreCell {
|
||||
}
|
||||
|
||||
update(value: ScoreCellValue | CellFlag): void {
|
||||
if (value == CellFlag.strike) {
|
||||
if (value === CellFlag.random) {
|
||||
this.setRandom();
|
||||
}
|
||||
else if (value == CellFlag.strike) {
|
||||
this.strike();
|
||||
}
|
||||
else if (this.struck) {
|
||||
@@ -153,22 +151,31 @@ abstract class IterableScoreCell extends ScoreCell {
|
||||
if (this.isStruck()) {
|
||||
this.unstrike();
|
||||
}
|
||||
if (valueAtIteratorIndex == CellFlag.strike) {
|
||||
this.strike();
|
||||
}
|
||||
else {
|
||||
this.value = valueAtIteratorIndex;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
setRandom(): void {
|
||||
const randomInt = Math.round(Math.random() * (this.iteratedSequence.length)) + 1;
|
||||
if (randomInt >= this.iteratedSequence.length) {
|
||||
this.strike();
|
||||
}
|
||||
else {
|
||||
this.unstrike();
|
||||
this.value = this.iteratedSequence[randomInt];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class NumberScoreCell extends ScoreCell {
|
||||
protected static readonly fieldType = FieldType.number;
|
||||
protected readonly max: number;
|
||||
|
||||
constructor(cellId: string, cellDef: NumberCellDef) {
|
||||
super(cellId, cellDef);
|
||||
this.value = 0;
|
||||
this.max = cellDef.max;
|
||||
}
|
||||
|
||||
getScore(): number {
|
||||
@@ -176,7 +183,13 @@ class NumberScoreCell extends ScoreCell {
|
||||
}
|
||||
|
||||
update(value: ScoreCellValue | CellFlag): void {
|
||||
if (typeof value === "boolean") {
|
||||
throw new Error("Number cells cannot be updated with boolean values!");
|
||||
}
|
||||
switch (value){
|
||||
case CellFlag.random:
|
||||
this.setRandom();
|
||||
break;
|
||||
case CellFlag.strike:
|
||||
this.strike();
|
||||
break;
|
||||
@@ -185,9 +198,26 @@ class NumberScoreCell extends ScoreCell {
|
||||
break;
|
||||
default:
|
||||
this.value = value;
|
||||
if (this.value > this.max) {
|
||||
this.value = this.max;
|
||||
}
|
||||
else if (this.value < 0) {
|
||||
this.value = 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
setRandom(): void {
|
||||
const randomInt = Math.round(Math.random() * (this.max + 10)) + 1;
|
||||
if (randomInt > this.max) {
|
||||
this.strike();
|
||||
}
|
||||
else {
|
||||
this.unstrike();
|
||||
this.value = randomInt;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class BoolScoreCell extends IterableScoreCell {
|
||||
@@ -210,6 +240,17 @@ class BoolScoreCell extends IterableScoreCell {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
setRandom(): void {
|
||||
const randomInt = Math.round(Math.random());
|
||||
if (randomInt > 0) {
|
||||
this.strike();
|
||||
}
|
||||
else {
|
||||
this.unstrike();
|
||||
this.value = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class SuperkadiScoreCell extends IterableScoreCell {
|
||||
|
||||
@@ -16,6 +16,7 @@ interface GameState {
|
||||
settingUp: boolean;
|
||||
loading: boolean;
|
||||
availablePlayers: Player[]
|
||||
debug: boolean;
|
||||
}
|
||||
|
||||
interface GameProps {}
|
||||
@@ -36,6 +37,7 @@ class Game extends React.Component<GameProps, GameState> {
|
||||
settingUp: true,
|
||||
loading: true,
|
||||
availablePlayers: [],
|
||||
debug: Settings.debug,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -47,7 +49,7 @@ class Game extends React.Component<GameProps, GameState> {
|
||||
console.log(this.state.availablePlayers);
|
||||
}
|
||||
|
||||
addNewPlayers(players: Player[]) {
|
||||
addNewPlayers(players: Player[]): void {
|
||||
const availablePlayers: Player[] = this.state.availablePlayers;
|
||||
availablePlayers.push(...players);
|
||||
this.setState({availablePlayers});
|
||||
@@ -81,6 +83,7 @@ class Game extends React.Component<GameProps, GameState> {
|
||||
) :
|
||||
(
|
||||
<KadiBoard
|
||||
debug={this.state.debug}
|
||||
settings={this.state.currentSettings}
|
||||
returnToSetup={this.returnToSetup}
|
||||
/>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import React, {ReactNode} from "react";
|
||||
import KadiCell from "./KadiCell";
|
||||
import {CellScores} from "./KadiBoard";
|
||||
import {FieldType} from "../../../shared/rulesets";
|
||||
import {FieldType} from "../static/rulesets";
|
||||
|
||||
interface KadiBlockBonusRowProps {
|
||||
blockId: string;
|
||||
|
||||
@@ -7,7 +7,7 @@ import KadiBlockTotalRow from "./KadiBlockTotalRow";
|
||||
import KadiBlockSubtotalRow from "./KadiBlockSubtotalRow";
|
||||
import KadiBlockBonusRow from "./KadiBlockBonusRow";
|
||||
import LocaleContext from "../LocaleContext";
|
||||
import {BlockDef, FieldType} from "../../../shared/rulesets";
|
||||
import {BlockDef, FieldType} from "../static/rulesets";
|
||||
|
||||
interface BlockRendererProps {
|
||||
blockId: string;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import React, {ReactNode} from "react";
|
||||
import KadiCell from "./KadiCell";
|
||||
import {CellScores} from "./KadiBoard";
|
||||
import {FieldType} from "../../../shared/rulesets";
|
||||
import {FieldType} from "../static/rulesets";
|
||||
|
||||
interface KadiBlockSubtotalRowProps {
|
||||
blockId: string;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import React, {ReactNode} from "react";
|
||||
import KadiCell from "./KadiCell";
|
||||
import {CellScores} from "./KadiBoard";
|
||||
import {FieldType} from "../../../shared/rulesets";
|
||||
import {FieldType} from "../static/rulesets";
|
||||
|
||||
interface KadiBlockTotalRowProps {
|
||||
blockId: string;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import React, {ReactElement, ReactNode, useContext} from "react";
|
||||
import PlayerScoreCard, {CellLocation, PlayerScoreCardJSONRepresentation} from "../Classes/PlayerScoreCard";
|
||||
import {getGameSchemaById} from "../static/rulesets";
|
||||
import {getGameSchemaById, Ruleset} from "../static/rulesets";
|
||||
import LocaleContext from "../LocaleContext";
|
||||
import {ScoreCellValue} from "../Classes/ScoreCell";
|
||||
import {CaretakerSet} from "../Classes/Caretaker";
|
||||
@@ -14,7 +14,7 @@ import KadiBlockRenderer from "./KadiBlockRenderer";
|
||||
import {KadiCellDisplayValue} from "./KadiCell";
|
||||
import {Player} from "./Game";
|
||||
import {SERVER_BASE_NAME} from "../index";
|
||||
import {CellFlag, Ruleset} from "../../../shared/rulesets";
|
||||
import {CellFlag} from "../static/enums";
|
||||
|
||||
|
||||
export interface CellScores {
|
||||
@@ -37,11 +37,13 @@ export interface CellEventResponse {
|
||||
export interface KadiBoardProps {
|
||||
settings: GameSettings;
|
||||
returnToSetup: () => void;
|
||||
debug: boolean;
|
||||
}
|
||||
|
||||
interface KadiBoardState {
|
||||
scoreSheet: ScoreSheet;
|
||||
players: Player[];
|
||||
debug: boolean;
|
||||
showResults: boolean;
|
||||
savingGame: boolean;
|
||||
locked: boolean;
|
||||
@@ -65,6 +67,7 @@ class KadiBoard extends React.Component<KadiBoardProps, KadiBoardState> {
|
||||
this.state = {
|
||||
scoreSheet: this.generateNewScoreSheet(this.props.settings.players),
|
||||
players: this.props.settings.players,
|
||||
debug: this.props.debug,
|
||||
showResults: true,
|
||||
savingGame: false,
|
||||
locked: false,
|
||||
@@ -147,7 +150,7 @@ class KadiBoard extends React.Component<KadiBoardProps, KadiBoardState> {
|
||||
ruleset: this.gameSchema.id,
|
||||
players: this.state.players,
|
||||
results: JSONScoreCards
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
private canSave(): boolean {
|
||||
@@ -182,6 +185,20 @@ class KadiBoard extends React.Component<KadiBoardProps, KadiBoardState> {
|
||||
console.log("Error saving:", error);
|
||||
};
|
||||
|
||||
private fillOutRandomly(): void {
|
||||
for (const player of this.state.players) {
|
||||
for (const blockId in this.gameSchema.blocks) {
|
||||
for (const cellId in this.gameSchema.blocks[blockId].cells) {
|
||||
this.onCellEdit({
|
||||
value: CellFlag.random,
|
||||
location: {cellId: cellId, blockId: blockId},
|
||||
playerId: player.id
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
render(): ReactNode {
|
||||
const Locale = this.context.strings;
|
||||
const rows: ReactElement[] = [];
|
||||
@@ -290,6 +307,17 @@ class KadiBoard extends React.Component<KadiBoardProps, KadiBoardState> {
|
||||
Locale.buttons.saveGameButton.gameSaved :
|
||||
Locale.buttons.saveGameButton.saveGame}
|
||||
</Button>
|
||||
{this.state.debug && (
|
||||
<Button
|
||||
icon={true}
|
||||
labelPosition={"left"}
|
||||
secondary={true}
|
||||
onClick={() => this.fillOutRandomly()}
|
||||
>
|
||||
<Icon name={"random"}/>
|
||||
Random results
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</Container>
|
||||
</div>
|
||||
|
||||
@@ -3,7 +3,8 @@ import {ScoreCellValue} from "../Classes/ScoreCell";
|
||||
import {CellEventResponse} from "./KadiBoard";
|
||||
import {CellLocation} from "../Classes/PlayerScoreCard";
|
||||
import {useLongPress} from "./useLongPress";
|
||||
import {CellFlag, FieldType} from "../../../shared/rulesets";
|
||||
import {FieldType} from "../static/rulesets";
|
||||
import {CellFlag} from "../static/enums";
|
||||
|
||||
export type KadiCellDisplayValue = ScoreCellValue | CellFlag.strike;
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ import {CellLocation} from "../Classes/PlayerScoreCard";
|
||||
import React, {ReactElement} from "react";
|
||||
import KadiCell from "./KadiCell";
|
||||
import {CellEventResponse, CellScores} from "./KadiBoard";
|
||||
import {FieldType} from "../../../shared/rulesets";
|
||||
import {FieldType} from "../static/rulesets";
|
||||
|
||||
interface KadiEditableRowCellsProps {
|
||||
location: CellLocation;
|
||||
|
||||
@@ -3,7 +3,7 @@ import LocaleContext from "../LocaleContext";
|
||||
import KadiCell from "./KadiCell";
|
||||
import {Icon} from "semantic-ui-react";
|
||||
import {CellScores} from "./KadiBoard";
|
||||
import {FieldType} from "../../../shared/rulesets";
|
||||
import {FieldType} from "../static/rulesets";
|
||||
|
||||
interface KadiGrandTotalRowProps {
|
||||
showResults: boolean;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
export enum CellFlag {
|
||||
strike = "cellFlagStrike",
|
||||
unstrike = "cellFlagUnstrike",
|
||||
random = "random",
|
||||
}
|
||||
|
||||
export enum SupportedLang {
|
||||
|
||||
@@ -67,6 +67,7 @@ export interface SuperkadiCellDef extends DefaultCellDef {
|
||||
|
||||
export interface NumberCellDef extends DefaultCellDef {
|
||||
fieldType: FieldType.number;
|
||||
max: number,
|
||||
}
|
||||
|
||||
interface DefaultCellDef {
|
||||
@@ -139,11 +140,13 @@ const gameSchemas: Ruleset[] = [
|
||||
threeKind: {
|
||||
fieldType: FieldType.number,
|
||||
label: "Three of a Kind",
|
||||
max: defaultDiceCount * 6,
|
||||
},
|
||||
|
||||
fourKind: {
|
||||
fieldType: FieldType.number,
|
||||
label: "Four of a Kind",
|
||||
max: defaultDiceCount * 6,
|
||||
},
|
||||
|
||||
fullHouse: {
|
||||
@@ -174,6 +177,7 @@ const gameSchemas: Ruleset[] = [
|
||||
chance: {
|
||||
fieldType: FieldType.number,
|
||||
label: "Chance",
|
||||
max: defaultDiceCount * 6,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
{
|
||||
"debug": true,
|
||||
"ruleset": "DEFAULT_RULESET",
|
||||
"maxHistoryLength": 256
|
||||
}
|
||||
Reference in New Issue
Block a user