UNPKG

sandhill-road

Version:

A narrative-driven startup simulation game where you guide a founder from garage to exit

86 lines 3.42 kB
"use strict"; // Utility functions for handling events and their effects Object.defineProperty(exports, "__esModule", { value: true }); exports.getAvailableChoices = exports.meetsRequirements = exports.applyResult = void 0; const gameState_1 = require("../core/gameState"); /** * Applies a result to the game state * This handles dot notation for nested properties */ const applyResult = (result) => { (0, gameState_1.updateGameState)(state => { // Create a shallow copy of the state - deep cloning not needed for this use case const newState = { ...state, founderStats: { ...state.founderStats }, companyStats: { ...state.companyStats }, stageProgress: { ...state.stageProgress }, companyFlags: { ...state.companyFlags } }; // Apply each result key-value pair for (const [key, value] of Object.entries(result)) { if (key === 'weeksLost' || value === undefined) continue; // Handled separately or skip undefined const path = key.split('.'); if (path.length === 1) { // Direct property on state - we'd need to handle each possible direct property specifically // For the current game state, we don't actually have direct number properties at the root level // This is just here for completeness console.warn(`Direct property updates not supported: ${key}`); } else if (path.length === 2) { // Nested property const [category, prop] = path; const categoryKey = category; const categoryObj = newState[categoryKey]; if (categoryObj && typeof categoryObj === 'object') { // Use type assertion to treat it as a record const objWithProps = categoryObj; if (typeof objWithProps[prop] === 'number') { objWithProps[prop] = Math.max(0, objWithProps[prop] + value); } } } } return newState; }); }; exports.applyResult = applyResult; /** * Checks if player meets requirements for a choice */ const meetsRequirements = (state, requires) => { if (!requires) return true; for (const [key, reqValue] of Object.entries(requires)) { // Skip if the required value is undefined if (reqValue === undefined) continue; const path = key.split('.'); let currentValue = state; for (const prop of path) { if (currentValue && currentValue[prop] !== undefined) { currentValue = currentValue[prop]; } else { return false; // Required stat not found } } // Compare value if (typeof currentValue === 'number') { if (currentValue < reqValue) { return false; } } } return true; }; exports.meetsRequirements = meetsRequirements; /** * Get available choices for an event based on player stats */ const getAvailableChoices = (state, choices) => { return choices.filter(choice => !choice.requires || (0, exports.meetsRequirements)(state, choice.requires)); }; exports.getAvailableChoices = getAvailableChoices; //# sourceMappingURL=eventUtils.js.map