-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(webapp): remove namespace and restructure the game logic
- Loading branch information
Showing
20 changed files
with
287 additions
and
249 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
export type BaseCard = { name: string }; | ||
|
||
export type ProjectCard = BaseCard & { | ||
requirements: Record<JobName, number>; | ||
}; | ||
|
||
export type JobCard = BaseCard; | ||
export type JobName = string; | ||
|
||
export type ForceCard = BaseCard; | ||
|
||
export type EventCard = BaseCard; |
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
packages/webapp/src/game/cards.ts → packages/webapp/src/game/cards/cards.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
export interface Deck<T> { | ||
drawPile: T[]; | ||
discardPile: T[]; | ||
} | ||
|
||
export function newCardDeck<T>(drawPile: T[] = [], discardPile: T[] = []): Deck<T> { | ||
return { | ||
drawPile, | ||
discardPile, | ||
}; | ||
} | ||
|
||
export interface IDeck { | ||
ShuffleDrawPile<T>(deck: Deck<T>, shuffler: (pile: T[]) => T[]): void; | ||
ShuffleDiscardPile<T>(deck: Deck<T>, shuffler: (pile: T[]) => T[]): void; | ||
PutDiscardPileToDrawPile<T>(deck: Deck<T>): void; | ||
Draw<T>(deck: Deck<T>, n: number): T[]; | ||
Discard<T>(deck: Deck<T>, ts: T[]): void; | ||
} | ||
|
||
export const Deck: IDeck = { | ||
ShuffleDrawPile<T>(deck: Deck<T>, shuffler: (pile: T[]) => T[]): void { | ||
deck.drawPile = shuffler(deck.drawPile); | ||
}, | ||
ShuffleDiscardPile<T>(deck: Deck<T>, shuffler: (pile: T[]) => T[]): void { | ||
deck.discardPile = shuffler(deck.discardPile); | ||
}, | ||
PutDiscardPileToDrawPile<T>(deck: Deck<T>): void { | ||
deck.drawPile = [...deck.drawPile, ...deck.discardPile]; | ||
deck.discardPile = []; | ||
}, | ||
Draw<T>(deck: Deck<T>, n: number): T[] { | ||
const result = deck.drawPile.slice(0, n); | ||
deck.drawPile = deck.drawPile.slice(n); | ||
return result; | ||
}, | ||
Discard<T>(deck: Deck<T>, ts: T[]) { | ||
deck.discardPile = [...deck.discardPile, ...ts]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { EventCard, ForceCard, JobCard, ProjectCard } from "../cards/card"; | ||
import { Deck, newCardDeck } from "./deck"; | ||
|
||
export type Decks = { | ||
projects: Deck<ProjectCard>; | ||
jobs: Deck<JobCard>; | ||
forces: Deck<ForceCard>; | ||
events: Deck<EventCard>; | ||
}; | ||
|
||
export const setupDecks = (projectCards: ProjectCard[], jobCards: JobCard[], forceCards: ForceCard[], eventCards: EventCard[]): Decks => { | ||
return { | ||
projects: newCardDeck<ProjectCard>(projectCards), | ||
jobs: newCardDeck<JobCard>(jobCards), | ||
forces: newCardDeck<ForceCard>(forceCards), | ||
events: newCardDeck<EventCard>(eventCards), | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.