-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement Replay view with a side track
Refactor PlayingField into a proper component and move the engine to a view. Adjust to API changes Obtain current git hash for later analysis of replay data ref #33
- Loading branch information
Showing
14 changed files
with
1,070 additions
and
474 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,78 @@ | ||
import { | ||
WIDTH, | ||
type GameState, | ||
type MultiplayerGame, | ||
type TickResult, | ||
GHOST_Y | ||
} from 'pujo-puyo-core' | ||
|
||
export type Chain = { | ||
number: number | ||
age: number | ||
x: number | ||
y: number | ||
} | ||
|
||
const MAX_CHAIN_CARD_AGE = 100 | ||
|
||
export class ChainDeck { | ||
chains: Chain[][] | ||
ignitionCenters: number[][] | ||
|
||
constructor() { | ||
this.chains = [[], []] | ||
this.ignitionCenters = [ | ||
[0, 0], | ||
[0, 0] | ||
] | ||
} | ||
|
||
clone(): ChainDeck { | ||
const result = new ChainDeck() | ||
result.chains = this.chains.map((cs) => cs.map((c) => ({ ...c }))) | ||
result.ignitionCenters = this.ignitionCenters.map((i) => [...i]) | ||
return result | ||
} | ||
|
||
processTick(game: MultiplayerGame, tickResults: TickResult[]) { | ||
for (let i = 0; i < this.chains.length; ++i) { | ||
for (const chain of this.chains[i]) { | ||
chain.age++ | ||
} | ||
while (this.chains[i][0]?.age > MAX_CHAIN_CARD_AGE) { | ||
this.chains[i].shift() | ||
} | ||
} | ||
|
||
let states: GameState[] | undefined | ||
for (let i = 0; i < tickResults.length; ++i) { | ||
if (tickResults[i].didJiggle) { | ||
if (states === undefined) { | ||
states = game.state | ||
} | ||
let numIgnitions = 0 | ||
let x = 0 | ||
let y = 0 | ||
states[i].screen.ignited.slice(WIDTH * (GHOST_Y + 1)).forEach((flag, index) => { | ||
if (flag) { | ||
x += index % WIDTH | ||
y += Math.floor(index / WIDTH) | ||
numIgnitions++ | ||
} | ||
}) | ||
if (numIgnitions) { | ||
this.ignitionCenters[i][0] = x / numIgnitions | ||
this.ignitionCenters[i][1] = y / numIgnitions | ||
} | ||
} | ||
if (tickResults[i].didClear) { | ||
this.chains[i].push({ | ||
number: tickResults[i].chainNumber, | ||
age: 0, | ||
x: this.ignitionCenters[i][0], | ||
y: this.ignitionCenters[i][1] | ||
}) | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.