Can't quite tell what's changed

This commit is contained in:
Daniel Ledda
2020-05-24 11:46:17 +02:00
parent d99d7cbfec
commit f08105c39f
20 changed files with 144 additions and 137 deletions

View File

@@ -21,7 +21,6 @@ class Game extends React.Component<GameProps, GameState> {
const startupSettings: GameSettings = {
playerIds: Settings.players,
ruleset: Settings.ruleset,
lang: Settings.lang as SupportedLang
};
this.state = {

View File

@@ -1,7 +1,25 @@
import React, {ChangeEvent, FocusEvent, KeyboardEvent, ReactNode} from "react";
import {getSchemaListings, SchemaListing} from "../static/rulesets";
import {LocaleContext, LanguageNames} from "../static/strings";
import {LanguageNames} from "../static/strings";
import LocaleContext from "../LocaleContext";
import {SupportedLang} from "../static/enums";
import {Button} from "semantic-ui-react";
interface GameSetupProps {
onSetupComplete: (settings: GameSettings) => void;
settings: GameSettings;
}
interface GameSetupState {
selectedRuleset: string;
enteredPlayerIds: string[];
editingPlayerName: boolean;
}
export interface GameSettings {
ruleset: string;
playerIds: string[];
}
class GameSetup extends React.Component<GameSetupProps, GameSetupState> {
private readonly availableRulesets: SchemaListing[];
@@ -14,22 +32,12 @@ class GameSetup extends React.Component<GameSetupProps, GameSetupState> {
this.availableRulesets = getSchemaListings();
this.changeLang = () => {};
this.state = {
selectedLang: this.props.settings.lang,
selectedRuleset: this.props.settings.ruleset,
enteredPlayerIds: this.props.settings.playerIds,
editingPlayerName: false,
};
}
componentDidMount(): void {
this.changeLang = this.context.changeLang;
}
onLanguageChange: (lang: SupportedLang) => void = (lang) => {
this.setState({ selectedLang: lang });
this.changeLang(lang);
};
onRulesetChange: (ruleset: string) => void = (ruleset) => {
this.setState({ selectedRuleset: ruleset });
};
@@ -52,31 +60,12 @@ class GameSetup extends React.Component<GameSetupProps, GameSetupState> {
this.props.onSetupComplete({
ruleset: this.state.selectedRuleset,
playerIds: this.state.enteredPlayerIds,
lang: this.state.selectedLang,
});
};
render(): ReactNode {
const Locale = this.context.strings;
const langOptions: ReactNode[] = [];
for (const lang in SupportedLang) {
let className = "option";
if (this.state.selectedLang === lang) {
className += " selected";
}
langOptions.push((
<div
key={lang + "lang_option"}
className={className}
onClick={() => this.onLanguageChange(lang as SupportedLang)}
>
{LanguageNames[lang as SupportedLang]}
<span className={"selectorBox"}/>
</div>
));
}
const rulesetOptions: ReactNode[] = [];
for (const rulesetListing of this.availableRulesets) {
let className = "option";
@@ -143,24 +132,15 @@ class GameSetup extends React.Component<GameSetupProps, GameSetupState> {
{rulesetOptions}
</div>
</div>
<div className={"optionGroup"}>
<div className={"optionGroupTitleContainer"}>
<span className={"optionGroupTitle"}>
{Locale.setupScreen.selectLanguage}
</span>
</div>
<div className={"languageOptions optionList"}>
{langOptions}
</div>
</div>
<div className={"playButtonContainer"}>
<button
className={"playButton"}
<Button
size={"huge"}
color={"blue"}
onClick={this.submitSettings}
disabled={this.state.enteredPlayerIds.length < 1}
>
{Locale.setupScreen.startGame}
</button>
</Button>
</div>
</div>
</div>
@@ -170,24 +150,6 @@ class GameSetup extends React.Component<GameSetupProps, GameSetupState> {
}
GameSetup.contextType = LocaleContext;
interface GameSetupProps {
onSetupComplete: (settings: GameSettings) => void;
settings: GameSettings;
}
interface GameSetupState {
selectedLang: SupportedLang;
selectedRuleset: string;
enteredPlayerIds: string[];
editingPlayerName: boolean;
}
export interface GameSettings {
ruleset: string;
playerIds: string[];
lang: SupportedLang;
}
const AddPlayerField: React.FunctionComponent<AddPlayerFieldProps> = ({playersListEmpty, submitNewPlayer, userEditing}) => {
const Locale = React.useContext(LocaleContext).strings;

View File

@@ -1,7 +1,7 @@
import {BlockDef} from "../static/rulesets";
import {CellLocation} from "../Classes/PlayerScoreCard";
import React, {ReactElement} from "react";
import {formatUnicorn, LocaleContext} from "../static/strings";
import {formatUnicorn} from "../static/strings";
import {FieldType} from "../static/enums";
import {BlockScores, CellEventResponse} from "./KadiBoard";
import GenericKadiRowContainer from "./GenericKadiRowContainer";
@@ -9,6 +9,7 @@ import KadiEditableRowCells from "./KadiEditableRowCells";
import KadiBlockTotalRow from "./KadiBlockTotalRow";
import KadiBlockSubtotalRow from "./KadiBlockSubtotalRow";
import KadiBlockBonusRow from "./KadiBlockBonusRow";
import LocaleContext from "../LocaleContext";
interface BlockRendererProps {
blockSchema: BlockDef;

View File

@@ -1,7 +1,8 @@
import React, {ReactElement, ReactNode, useContext} from "react";
import PlayerScoreCard, {CellLocation, PlayerScoreCardJSONRepresentation} from "../Classes/PlayerScoreCard";
import {BlockDef, GameSchema, getGameSchemaById} from "../static/rulesets";
import {formatUnicorn, LocaleContext} from "../static/strings";
import {formatUnicorn} from "../static/strings";
import LocaleContext from "../LocaleContext";
import {CellFlag} from "../static/enums";
import {ScoreCellValue} from "../Classes/ScoreCell";
import {CaretakerSet} from "../Classes/Caretaker";
@@ -131,11 +132,14 @@ class KadiBoard extends React.Component<KadiBoardProps, KadiBoardState> {
}
private getJSONRepresentationForBoard(): string {
const JSONRepresentation: PlayerScoreCardJSONRepresentation[] = [];
const JSONScoreCards: PlayerScoreCardJSONRepresentation[] = [];
for (const playerId in this.state.scoreSheet) {
JSONRepresentation.push(this.state.scoreSheet[playerId].getJSONRepresentation());
JSONScoreCards.push(this.state.scoreSheet[playerId].getJSONRepresentation());
}
return JSON.stringify(JSONRepresentation);
return JSON.stringify({
gameType: this.gameSchema.id,
results: JSONScoreCards
});
}
private canSave(): boolean {

View File

@@ -1,5 +1,5 @@
import React, {ReactNode} from "react";
import {LocaleContext} from "../static/strings";
import LocaleContext from "../LocaleContext";
import KadiCell from "./KadiCell";
import {FieldType} from "../static/enums";
import {Icon} from "semantic-ui-react";