parent
05c4bae65d
commit
fcf2b8a463
@ -1,5 +1,5 @@ |
|||||||
import { describe, expect, test } from '@jest/globals' |
import { describe, expect, test } from '@jest/globals' |
||||||
import { DieState, isHeldState, isSelectedState, setDeselected, setSelected, toggleSelected } from './gamestate' |
import { DieState, isHeldState, isSelectedState, setDeselected, setSelected, toggleSelected } from './gameData' |
||||||
|
|
||||||
describe('isHeldState', () => { |
describe('isHeldState', () => { |
||||||
test.each<[DieState, boolean]>([ |
test.each<[DieState, boolean]>([ |
@ -0,0 +1,168 @@ |
|||||||
|
import { DieResult, GameData } from './gameData' |
||||||
|
|
||||||
|
export enum IncomingEventType { |
||||||
|
// Chooses the action to be performed for this round but does not lock it in until the player rolls.
|
||||||
|
SelectAction = 'select_action', |
||||||
|
// Dice buttons toggle the selection of that die
|
||||||
|
ToggleSelectDie = 'toggle_select_die', |
||||||
|
// Button 1 is Select All/Deselect All
|
||||||
|
// Select All appears if no dice are selected
|
||||||
|
// Deselect All displays if at least one die is selected
|
||||||
|
SelectAllDice = 'select_all_dice', |
||||||
|
DeselectAllDice = 'deselect_all_dice', |
||||||
|
// Button 2 is Hold/Release selected dice
|
||||||
|
// If only held dice are selected, Release appears
|
||||||
|
// For selections with at least one unheld die, Hold appears
|
||||||
|
HoldSelectedDice = 'hold_selected_dice', |
||||||
|
ReleaseSelectedDice = 'release_selected_dice', |
||||||
|
// Button 3 is End Turn/Score Selected Dice
|
||||||
|
// End Turn appears if at least one Stop die is selected, but is only enabled if sufficient Stop dice are selected
|
||||||
|
// and no non-Stop dice are selected
|
||||||
|
// Score Selected Dice appears otherwise, but is only enabled if at least one scoreable die is selected and no
|
||||||
|
// non-scoreable dice are selected
|
||||||
|
EndTurn = 'end_turn', |
||||||
|
ScoreSelectedDice = 'score_selected_dice', |
||||||
|
// Button 4 is Roll Dice
|
||||||
|
// It's always visible, but is disabled if there are no unheld dice
|
||||||
|
RollDice = 'roll_dice', |
||||||
|
} |
||||||
|
|
||||||
|
export interface IncomingBaseEvent { |
||||||
|
// The type of event to execute.
|
||||||
|
readonly type: IncomingEventType |
||||||
|
} |
||||||
|
|
||||||
|
export interface IncomingIndexedEvent extends IncomingBaseEvent { |
||||||
|
readonly type: IncomingEventType.SelectAction | IncomingEventType.ToggleSelectDie |
||||||
|
readonly index: number |
||||||
|
} |
||||||
|
|
||||||
|
export interface IncomingSimpleEvent extends IncomingBaseEvent { |
||||||
|
readonly type: |
||||||
|
| IncomingEventType.SelectAllDice |
||||||
|
| IncomingEventType.HoldSelectedDice |
||||||
|
| IncomingEventType.ReleaseSelectedDice |
||||||
|
| IncomingEventType.ScoreSelectedDice |
||||||
|
| IncomingEventType.EndTurn |
||||||
|
| IncomingEventType.DeselectAllDice |
||||||
|
| IncomingEventType.RollDice |
||||||
|
} |
||||||
|
|
||||||
|
export type IncomingEvent = IncomingIndexedEvent | IncomingSimpleEvent |
||||||
|
|
||||||
|
export enum ErrorType { |
||||||
|
NotValidRightNow = 'not_valid_right_now', |
||||||
|
InvalidIndex = 'invalid_index', |
||||||
|
InsufficientMatchingDice = 'insufficient_matching_dice', |
||||||
|
DataLoadFailed = 'data_load_failed', |
||||||
|
UnexpectedError = 'unexpected_error', |
||||||
|
} |
||||||
|
|
||||||
|
export interface GameError { |
||||||
|
readonly type: ErrorType |
||||||
|
readonly message: string |
||||||
|
} |
||||||
|
|
||||||
|
export enum OutgoingEventType { |
||||||
|
Dialogue = 'dialogue', |
||||||
|
Description = 'description', |
||||||
|
|
||||||
|
DamageOrRecovery = 'damage', |
||||||
|
ChangeStops = 'change_stops', |
||||||
|
ChangeFails = 'change_fails', |
||||||
|
ChangeDamageBonus = 'change_damage_bonus', |
||||||
|
|
||||||
|
ScoreDice = 'score_dice', |
||||||
|
GainFailures = 'gain_failures', |
||||||
|
|
||||||
|
LoseRound = 'lose_round', |
||||||
|
LoseGame = 'lose_game', |
||||||
|
|
||||||
|
StartRoll = 'new_roll', |
||||||
|
StartTurn = 'new_turn', |
||||||
|
StartRound = 'new_round', |
||||||
|
} |
||||||
|
|
||||||
|
export enum EventTarget { |
||||||
|
Top = 'top', |
||||||
|
Bottom = 'bottom', |
||||||
|
} |
||||||
|
|
||||||
|
export enum TextSender { |
||||||
|
Top = 'top', |
||||||
|
Bottom = 'bottom', |
||||||
|
Narrator = 'narrator', |
||||||
|
} |
||||||
|
|
||||||
|
export interface OutgoingBaseEvent { |
||||||
|
readonly type: OutgoingEventType |
||||||
|
} |
||||||
|
|
||||||
|
export interface OutgoingTextEvent extends OutgoingBaseEvent { |
||||||
|
readonly type: OutgoingEventType.Description | OutgoingEventType.Dialogue |
||||||
|
readonly sender: TextSender |
||||||
|
readonly text: string |
||||||
|
} |
||||||
|
|
||||||
|
export interface OutgoingBaseTargetedEvent extends OutgoingBaseEvent { |
||||||
|
readonly type: |
||||||
|
| OutgoingEventType.DamageOrRecovery |
||||||
|
| OutgoingEventType.ChangeStops |
||||||
|
| OutgoingEventType.ChangeFails |
||||||
|
| OutgoingEventType.ChangeDamageBonus |
||||||
|
| OutgoingEventType.LoseRound |
||||||
|
| OutgoingEventType.LoseGame |
||||||
|
| OutgoingEventType.ScoreDice |
||||||
|
| OutgoingEventType.GainFailures |
||||||
|
| OutgoingEventType.StartRoll |
||||||
|
| OutgoingEventType.StartTurn |
||||||
|
| OutgoingEventType.StartRound |
||||||
|
readonly target: EventTarget |
||||||
|
} |
||||||
|
|
||||||
|
export interface OutgoingSimpleTargetedEvent extends OutgoingBaseTargetedEvent { |
||||||
|
readonly type: OutgoingEventType.LoseGame | OutgoingEventType.StartTurn | OutgoingEventType.StartRound |
||||||
|
} |
||||||
|
|
||||||
|
export interface OutgoingDamageEvent extends OutgoingBaseTargetedEvent { |
||||||
|
readonly type: |
||||||
|
| OutgoingEventType.DamageOrRecovery |
||||||
|
| OutgoingEventType.ChangeStops |
||||||
|
| OutgoingEventType.ChangeFails |
||||||
|
| OutgoingEventType.ChangeDamageBonus |
||||||
|
| OutgoingEventType.LoseRound |
||||||
|
| OutgoingEventType.GainFailures |
||||||
|
readonly delta: number |
||||||
|
} |
||||||
|
|
||||||
|
export interface OutgoingStartRollEvent extends OutgoingBaseTargetedEvent { |
||||||
|
readonly type: OutgoingEventType.StartRoll |
||||||
|
readonly newDice: DieResult[] |
||||||
|
} |
||||||
|
|
||||||
|
export interface OutgoingScoreDiceEvent extends OutgoingBaseTargetedEvent { |
||||||
|
readonly type: OutgoingEventType.ScoreDice |
||||||
|
readonly scoredDice: DieResult[] |
||||||
|
readonly scoreDelta: number |
||||||
|
} |
||||||
|
|
||||||
|
export type OutgoingEvent = |
||||||
|
| OutgoingTextEvent |
||||||
|
| OutgoingSimpleTargetedEvent |
||||||
|
| OutgoingDamageEvent |
||||||
|
| OutgoingStartRollEvent |
||||||
|
| OutgoingScoreDiceEvent |
||||||
|
|
||||||
|
export interface BaseEventResult { |
||||||
|
readonly newState: GameData |
||||||
|
} |
||||||
|
|
||||||
|
export interface SuccessResult extends BaseEventResult { |
||||||
|
readonly events: OutgoingEvent[] |
||||||
|
} |
||||||
|
|
||||||
|
export interface FailedResult extends BaseEventResult { |
||||||
|
readonly error: GameError |
||||||
|
} |
||||||
|
|
||||||
|
export type EventResult = SuccessResult | FailedResult |
Loading…
Reference in new issue