UNPKG

slp-enforcer

Version:

Finds violations of the Melee Controller Ruleset by inspecting SLP files

70 lines (69 loc) 2.55 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const common_1 = require("./common"); class StockComputer { constructor() { this.state = new Map(); this.playerPermutations = new Array(); this.stocks = new Array(); } setup(settings) { // Reset state this.state = new Map(); this.playerPermutations = common_1.getSinglesPlayerPermutationsFromSettings(settings); this.stocks = []; this.playerPermutations.forEach((indices) => { const playerState = { stock: null, }; this.state.set(indices, playerState); }); } processFrame(frame, allFrames) { this.playerPermutations.forEach((indices) => { const state = this.state.get(indices); if (state) { handleStockCompute(allFrames, state, indices, frame, this.stocks); } }); } fetch() { return this.stocks; } } exports.StockComputer = StockComputer; function handleStockCompute(frames, state, indices, frame, stocks) { var _a, _b; const playerFrame = frame.players[indices.playerIndex].post; const currentFrameNumber = playerFrame.frame; const prevFrameNumber = currentFrameNumber - 1; const prevPlayerFrame = frames[prevFrameNumber] ? frames[prevFrameNumber].players[indices.playerIndex].post : null; // If there is currently no active stock, wait until the player is no longer spawning. // Once the player is no longer spawning, start the stock if (!state.stock) { const isPlayerDead = common_1.isDead(playerFrame.actionStateId); if (isPlayerDead) { return; } state.stock = { playerIndex: indices.playerIndex, startFrame: currentFrameNumber, endFrame: null, startPercent: 0, endPercent: null, currentPercent: 0, count: playerFrame.stocksRemaining, deathAnimation: null, }; stocks.push(state.stock); } else if (prevPlayerFrame && common_1.didLoseStock(playerFrame, prevPlayerFrame)) { state.stock.endFrame = playerFrame.frame; state.stock.endPercent = (_a = prevPlayerFrame.percent) !== null && _a !== void 0 ? _a : 0; state.stock.deathAnimation = playerFrame.actionStateId; state.stock = null; } else { state.stock.currentPercent = (_b = playerFrame.percent) !== null && _b !== void 0 ? _b : 0; } }