@strixit/storyscript 0.0.0-stage → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env +1 -0
- package/CodeSnippets/StoryScriptSnippets.code-snippets +573 -0
- package/LICENSE.txt +21 -0
- package/LiveTemplates/StoryScript.xml +271 -0
- package/README.md +9 -2
- package/baseViteConfig.js +112 -0
- package/clientFiles/currentGameName.js +1 -0
- package/clientFiles/gitignore +12 -0
- package/clientFiles/tsconfig.json +34 -0
- package/clientFiles/vite.config.ts +14 -0
- package/clientFiles/vitest.config.ts +29 -0
- package/dist/src/Engine/Actions/index.d.ts +2 -0
- package/dist/src/Engine/Actions/open.d.ts +6 -0
- package/dist/src/Engine/Actions/openWithKey.d.ts +7 -0
- package/dist/src/Engine/EntityCreatorFunctions.d.ts +18 -0
- package/dist/src/Engine/Interfaces/action.d.ts +37 -0
- package/dist/src/Engine/Interfaces/autoplayStep.d.ts +11 -0
- package/dist/src/Engine/Interfaces/barrier.d.ts +16 -0
- package/dist/src/Engine/Interfaces/barrierAction.d.ts +19 -0
- package/dist/src/Engine/Interfaces/character.d.ts +48 -0
- package/dist/src/Engine/Interfaces/combatSetup.d.ts +9 -0
- package/dist/src/Engine/Interfaces/combatTurn.d.ts +37 -0
- package/dist/src/Engine/Interfaces/combatWinnings.d.ts +6 -0
- package/dist/src/Engine/Interfaces/combinations/activeCombination.d.ts +14 -0
- package/dist/src/Engine/Interfaces/combinations/combinable.d.ts +18 -0
- package/dist/src/Engine/Interfaces/combinations/combinationAction.d.ts +41 -0
- package/dist/src/Engine/Interfaces/combinations/combinationMatchResult.d.ts +14 -0
- package/dist/src/Engine/Interfaces/combinations/combinations.d.ts +17 -0
- package/dist/src/Engine/Interfaces/combinations/combine.d.ts +22 -0
- package/dist/src/Engine/Interfaces/combinations/combineResult.d.ts +18 -0
- package/dist/src/Engine/Interfaces/combinations/gameCombinations.d.ts +40 -0
- package/dist/src/Engine/Interfaces/compiledLocation.d.ts +33 -0
- package/dist/src/Engine/Interfaces/conversations/conversation.d.ts +44 -0
- package/dist/src/Engine/Interfaces/conversations/conversationLogEntry.d.ts +13 -0
- package/dist/src/Engine/Interfaces/conversations/conversationNode.d.ts +22 -0
- package/dist/src/Engine/Interfaces/conversations/conversationReply.d.ts +49 -0
- package/dist/src/Engine/Interfaces/createCharacter/createCharacter.d.ts +20 -0
- package/dist/src/Engine/Interfaces/createCharacter/createCharacterAttribute.d.ts +18 -0
- package/dist/src/Engine/Interfaces/createCharacter/createCharacterAttributeEntry.d.ts +18 -0
- package/dist/src/Engine/Interfaces/createCharacter/createCharacterQuestion.d.ts +18 -0
- package/dist/src/Engine/Interfaces/createCharacter/createCharacterQuestionEntry.d.ts +22 -0
- package/dist/src/Engine/Interfaces/createCharacter/createCharacterStep.d.ts +40 -0
- package/dist/src/Engine/Interfaces/customCursor.d.ts +8 -0
- package/dist/src/Engine/Interfaces/defaultEquipment.d.ts +19 -0
- package/dist/src/Engine/Interfaces/definitions.d.ts +40 -0
- package/dist/src/Engine/Interfaces/destination.d.ts +31 -0
- package/dist/src/Engine/Interfaces/dynamicStyle.d.ts +10 -0
- package/dist/src/Engine/Interfaces/enemy.d.ts +46 -0
- package/dist/src/Engine/Interfaces/enumerations/actionStatus.d.ts +18 -0
- package/dist/src/Engine/Interfaces/enumerations/actionType.d.ts +9 -0
- package/dist/src/Engine/Interfaces/enumerations/equipmentType.d.ts +51 -0
- package/dist/src/Engine/Interfaces/enumerations/gameState.d.ts +11 -0
- package/dist/src/Engine/Interfaces/enumerations/playState.d.ts +10 -0
- package/dist/src/Engine/Interfaces/enumerations/targetType.d.ts +9 -0
- package/dist/src/Engine/Interfaces/equipment.d.ts +43 -0
- package/dist/src/Engine/Interfaces/feature.d.ts +37 -0
- package/dist/src/Engine/Interfaces/featureCollection.d.ts +7 -0
- package/dist/src/Engine/Interfaces/game.d.ts +148 -0
- package/dist/src/Engine/Interfaces/gameEvents.d.ts +7 -0
- package/dist/src/Engine/Interfaces/groupableItem.d.ts +32 -0
- package/dist/src/Engine/Interfaces/helpers.d.ts +50 -0
- package/dist/src/Engine/Interfaces/index.d.ts +78 -0
- package/dist/src/Engine/Interfaces/interfaceTexts.d.ts +140 -0
- package/dist/src/Engine/Interfaces/item.d.ts +96 -0
- package/dist/src/Engine/Interfaces/key.d.ts +16 -0
- package/dist/src/Engine/Interfaces/location.d.ts +78 -0
- package/dist/src/Engine/Interfaces/maps/map.d.ts +45 -0
- package/dist/src/Engine/Interfaces/maps/mapLocation.d.ts +23 -0
- package/dist/src/Engine/Interfaces/party.d.ts +33 -0
- package/dist/src/Engine/Interfaces/person.d.ts +25 -0
- package/dist/src/Engine/Interfaces/quest.d.ts +51 -0
- package/dist/src/Engine/Interfaces/rules/characterRules.d.ts +84 -0
- package/dist/src/Engine/Interfaces/rules/combatRules.d.ts +46 -0
- package/dist/src/Engine/Interfaces/rules/combinationRules.d.ts +15 -0
- package/dist/src/Engine/Interfaces/rules/demoMode.d.ts +15 -0
- package/dist/src/Engine/Interfaces/rules/encounterRules.d.ts +4 -0
- package/dist/src/Engine/Interfaces/rules/explorationRules.d.ts +42 -0
- package/dist/src/Engine/Interfaces/rules/generalRules.d.ts +62 -0
- package/dist/src/Engine/Interfaces/rules/rules.d.ts +31 -0
- package/dist/src/Engine/Interfaces/rules/setupRules.d.ts +56 -0
- package/dist/src/Engine/Interfaces/rules/titleScreen.d.ts +16 -0
- package/dist/src/Engine/Interfaces/saveGame.d.ts +33 -0
- package/dist/src/Engine/Interfaces/scoreEntry.d.ts +13 -0
- package/dist/src/Engine/Interfaces/services/autoplayService.d.ts +19 -0
- package/dist/src/Engine/Interfaces/services/characterService.d.ts +17 -0
- package/dist/src/Engine/Interfaces/services/combatService.d.ts +26 -0
- package/dist/src/Engine/Interfaces/services/combinationService.d.ts +9 -0
- package/dist/src/Engine/Interfaces/services/commandService.d.ts +64 -0
- package/dist/src/Engine/Interfaces/services/conversationService.d.ts +5 -0
- package/dist/src/Engine/Interfaces/services/dataSerializer.d.ts +4 -0
- package/dist/src/Engine/Interfaces/services/dataService.d.ts +33 -0
- package/dist/src/Engine/Interfaces/services/dataSynchronizer.d.ts +3 -0
- package/dist/src/Engine/Interfaces/services/gameService.d.ts +10 -0
- package/dist/src/Engine/Interfaces/services/index.d.ts +16 -0
- package/dist/src/Engine/Interfaces/services/itemService.d.ts +14 -0
- package/dist/src/Engine/Interfaces/services/localStorageService.d.ts +6 -0
- package/dist/src/Engine/Interfaces/services/locationService.d.ts +8 -0
- package/dist/src/Engine/Interfaces/services/soundService.d.ts +5 -0
- package/dist/src/Engine/Interfaces/services/tradeService.d.ts +9 -0
- package/dist/src/Engine/Interfaces/soundPlayer.d.ts +30 -0
- package/dist/src/Engine/Interfaces/sprite.d.ts +23 -0
- package/dist/src/Engine/Interfaces/stateList.d.ts +9 -0
- package/dist/src/Engine/Interfaces/statistics.d.ts +13 -0
- package/dist/src/Engine/Interfaces/stock.d.ts +39 -0
- package/dist/src/Engine/Interfaces/trade.d.ts +62 -0
- package/dist/src/Engine/ServiceFactory.d.ts +52 -0
- package/dist/src/Engine/Services/AutoplayService.d.ts +11 -0
- package/dist/src/Engine/Services/CharacterService.d.ts +21 -0
- package/dist/src/Engine/Services/CombatService.d.ts +16 -0
- package/dist/src/Engine/Services/CombinationService.d.ts +15 -0
- package/dist/src/Engine/Services/CommandService.d.ts +24 -0
- package/dist/src/Engine/Services/ConversationService.d.ts +26 -0
- package/dist/src/Engine/Services/DataSerializer.d.ts +17 -0
- package/dist/src/Engine/Services/DataService.d.ts +16 -0
- package/dist/src/Engine/Services/DataSynchronizer.d.ts +12 -0
- package/dist/src/Engine/Services/GameService.d.ts +28 -0
- package/dist/src/Engine/Services/HelperService.d.ts +18 -0
- package/dist/src/Engine/Services/ItemService.d.ts +21 -0
- package/dist/src/Engine/Services/LocalStorageService.d.ts +7 -0
- package/dist/src/Engine/Services/LocationService.d.ts +25 -0
- package/dist/src/Engine/Services/SoundService.d.ts +13 -0
- package/dist/src/Engine/Services/TradeService.d.ts +17 -0
- package/dist/src/Engine/Services/index.d.ts +17 -0
- package/dist/src/Engine/Services/serializationData.d.ts +8 -0
- package/dist/src/Engine/Services/sharedFunctions.d.ts +21 -0
- package/dist/src/Engine/arrayAndFunctionExtensions.d.ts +3 -0
- package/dist/src/Engine/defaultTexts.d.ts +7 -0
- package/dist/src/Engine/gameEvents.d.ts +10 -0
- package/dist/src/Engine/index.d.ts +8 -0
- package/dist/src/Engine/stateProperties.d.ts +6 -0
- package/dist/src/Engine/utilityFunctions.d.ts +25 -0
- package/dist/src/UI/Composables/CustomCursor.d.ts +2 -0
- package/dist/src/UI/Composables/LocationMap.d.ts +26 -0
- package/dist/src/UI/Composables/Sound.d.ts +7 -0
- package/dist/src/UI/Composables/TextFeatures.d.ts +8 -0
- package/dist/src/UI/Composables/VisualFeatures.d.ts +7 -0
- package/dist/src/UI/Composables/index.d.ts +7 -0
- package/dist/src/UI/Composables/playStateWatch.d.ts +2 -0
- package/dist/src/UI/StateStore.d.ts +14256 -0
- package/dist/src/UI/error.d.ts +6 -0
- package/dist/src/UI/helpers.d.ts +3 -0
- package/dist/src/UI/index.d.ts +6 -0
- package/dist/src/UI/main.d.ts +1 -0
- package/dist/src/UI/startup.d.ts +2 -0
- package/dist/src/constants.d.ts +17 -0
- package/dist/src/index.d.ts +3 -0
- package/dist/storyscript.css +9566 -0
- package/dist/storyscript.js +9659 -0
- package/dist/storyscript.js.map +1 -0
- package/dist/storyscript.mjs +9569 -0
- package/dist/storyscript.mjs.map +1 -0
- package/electron.cjs +44 -0
- package/index.html +14 -0
- package/package.json +118 -4
- package/scripts/cli.js +268 -0
- package/scripts/createAsset.js +117 -0
- package/scripts/createGame.js +40 -0
- package/scripts/helpers.js +21 -0
- package/scripts/postbuild.js +179 -0
- package/scripts/setupTesting.js +17 -0
- package/shims-vue.d.ts +1 -0
- package/src/Engine/Actions/index.ts +2 -0
- package/src/Engine/Actions/open.ts +12 -0
- package/src/Engine/Actions/openWithKey.ts +23 -0
- package/src/Engine/EntityCreatorFunctions.ts +602 -0
- package/src/Engine/Interfaces/action.ts +43 -0
- package/src/Engine/Interfaces/autoplayStep.ts +13 -0
- package/src/Engine/Interfaces/barrier.ts +18 -0
- package/src/Engine/Interfaces/barrierAction.ts +21 -0
- package/src/Engine/Interfaces/character.ts +58 -0
- package/src/Engine/Interfaces/combatSetup.ts +10 -0
- package/src/Engine/Interfaces/combatTurn.ts +45 -0
- package/src/Engine/Interfaces/combatWinnings.ts +7 -0
- package/src/Engine/Interfaces/combinations/activeCombination.ts +16 -0
- package/src/Engine/Interfaces/combinations/combinable.ts +21 -0
- package/src/Engine/Interfaces/combinations/combinationAction.ts +45 -0
- package/src/Engine/Interfaces/combinations/combinationMatchResult.ts +16 -0
- package/src/Engine/Interfaces/combinations/combinations.ts +19 -0
- package/src/Engine/Interfaces/combinations/combine.ts +25 -0
- package/src/Engine/Interfaces/combinations/combineResult.ts +21 -0
- package/src/Engine/Interfaces/combinations/gameCombinations.ts +48 -0
- package/src/Engine/Interfaces/compiledLocation.ts +37 -0
- package/src/Engine/Interfaces/conversations/conversation.ts +47 -0
- package/src/Engine/Interfaces/conversations/conversationLogEntry.ts +14 -0
- package/src/Engine/Interfaces/conversations/conversationNode.ts +26 -0
- package/src/Engine/Interfaces/conversations/conversationReply.ts +59 -0
- package/src/Engine/Interfaces/createCharacter/createCharacter.ts +23 -0
- package/src/Engine/Interfaces/createCharacter/createCharacterAttribute.ts +21 -0
- package/src/Engine/Interfaces/createCharacter/createCharacterAttributeEntry.ts +21 -0
- package/src/Engine/Interfaces/createCharacter/createCharacterQuestion.ts +21 -0
- package/src/Engine/Interfaces/createCharacter/createCharacterQuestionEntry.ts +25 -0
- package/src/Engine/Interfaces/createCharacter/createCharacterStep.ts +47 -0
- package/src/Engine/Interfaces/customCursor.ts +5 -0
- package/src/Engine/Interfaces/defaultEquipment.ts +32 -0
- package/src/Engine/Interfaces/definitions.ts +48 -0
- package/src/Engine/Interfaces/destination.ts +37 -0
- package/src/Engine/Interfaces/dynamicStyle.ts +11 -0
- package/src/Engine/Interfaces/enemy.ts +54 -0
- package/src/Engine/Interfaces/enumerations/actionStatus.ts +20 -0
- package/src/Engine/Interfaces/enumerations/actionType.ts +9 -0
- package/src/Engine/Interfaces/enumerations/equipmentType.ts +61 -0
- package/src/Engine/Interfaces/enumerations/gameState.ts +11 -0
- package/src/Engine/Interfaces/enumerations/playState.ts +10 -0
- package/src/Engine/Interfaces/enumerations/targetType.ts +9 -0
- package/src/Engine/Interfaces/equipment.ts +44 -0
- package/src/Engine/Interfaces/feature.ts +43 -0
- package/src/Engine/Interfaces/featureCollection.ts +8 -0
- package/src/Engine/Interfaces/game.ts +201 -0
- package/src/Engine/Interfaces/gameEvents.ts +11 -0
- package/src/Engine/Interfaces/groupableItem.ts +37 -0
- package/src/Engine/Interfaces/helpers.ts +55 -0
- package/src/Engine/Interfaces/index.ts +158 -0
- package/src/Engine/Interfaces/interfaceTexts.ts +142 -0
- package/src/Engine/Interfaces/item.ts +111 -0
- package/src/Engine/Interfaces/key.ts +18 -0
- package/src/Engine/Interfaces/location.ts +92 -0
- package/src/Engine/Interfaces/maps/map.ts +55 -0
- package/src/Engine/Interfaces/maps/mapLocation.ts +28 -0
- package/src/Engine/Interfaces/party.ts +40 -0
- package/src/Engine/Interfaces/person.ts +29 -0
- package/src/Engine/Interfaces/quest.ts +60 -0
- package/src/Engine/Interfaces/rules/characterRules.ts +96 -0
- package/src/Engine/Interfaces/rules/combatRules.ts +52 -0
- package/src/Engine/Interfaces/rules/combinationRules.ts +17 -0
- package/src/Engine/Interfaces/rules/demoMode.ts +18 -0
- package/src/Engine/Interfaces/rules/encounterRules.ts +5 -0
- package/src/Engine/Interfaces/rules/explorationRules.ts +47 -0
- package/src/Engine/Interfaces/rules/generalRules.ts +80 -0
- package/src/Engine/Interfaces/rules/rules.ts +46 -0
- package/src/Engine/Interfaces/rules/setupRules.ts +65 -0
- package/src/Engine/Interfaces/rules/titleScreen.ts +19 -0
- package/src/Engine/Interfaces/saveGame.ts +39 -0
- package/src/Engine/Interfaces/scoreEntry.ts +14 -0
- package/src/Engine/Interfaces/services/autoplayService.ts +23 -0
- package/src/Engine/Interfaces/services/characterService.ts +35 -0
- package/src/Engine/Interfaces/services/combatService.ts +30 -0
- package/src/Engine/Interfaces/services/combinationService.ts +10 -0
- package/src/Engine/Interfaces/services/commandService.ts +75 -0
- package/src/Engine/Interfaces/services/conversationService.ts +7 -0
- package/src/Engine/Interfaces/services/dataSerializer.ts +4 -0
- package/src/Engine/Interfaces/services/dataService.ts +39 -0
- package/src/Engine/Interfaces/services/dataSynchronizer.ts +9 -0
- package/src/Engine/Interfaces/services/gameService.ts +17 -0
- package/src/Engine/Interfaces/services/index.ts +33 -0
- package/src/Engine/Interfaces/services/itemService.ts +25 -0
- package/src/Engine/Interfaces/services/localStorageService.ts +6 -0
- package/src/Engine/Interfaces/services/locationService.ts +13 -0
- package/src/Engine/Interfaces/services/soundService.ts +7 -0
- package/src/Engine/Interfaces/services/tradeService.ts +15 -0
- package/src/Engine/Interfaces/soundPlayer.ts +30 -0
- package/src/Engine/Interfaces/sprite.ts +27 -0
- package/src/Engine/Interfaces/stateList.ts +13 -0
- package/src/Engine/Interfaces/statistics.ts +14 -0
- package/src/Engine/Interfaces/stock.ts +46 -0
- package/src/Engine/Interfaces/trade.ts +72 -0
- package/src/Engine/ServiceFactory.ts +167 -0
- package/src/Engine/Services/AutoplayService.ts +59 -0
- package/src/Engine/Services/CharacterService.ts +291 -0
- package/src/Engine/Services/CombatService.ts +266 -0
- package/src/Engine/Services/CombinationService.ts +197 -0
- package/src/Engine/Services/CommandService.ts +197 -0
- package/src/Engine/Services/ConversationService.ts +406 -0
- package/src/Engine/Services/DataSerializer.ts +326 -0
- package/src/Engine/Services/DataService.ts +93 -0
- package/src/Engine/Services/DataSynchronizer.ts +216 -0
- package/src/Engine/Services/GameService.ts +554 -0
- package/src/Engine/Services/HelperService.ts +94 -0
- package/src/Engine/Services/ItemService.ts +294 -0
- package/src/Engine/Services/LocalStorageService.ts +24 -0
- package/src/Engine/Services/LocationService.ts +380 -0
- package/src/Engine/Services/SoundService.ts +54 -0
- package/src/Engine/Services/TradeService.ts +176 -0
- package/src/Engine/Services/index.ts +17 -0
- package/src/Engine/Services/serializationData.ts +8 -0
- package/src/Engine/Services/sharedFunctions.ts +296 -0
- package/src/Engine/arrayAndFunctionExtensions.ts +269 -0
- package/src/Engine/defaultTexts.ts +162 -0
- package/src/Engine/gameEvents.ts +51 -0
- package/src/Engine/index.ts +9 -0
- package/src/Engine/stateProperties.ts +9 -0
- package/src/Engine/utilityFunctions.ts +238 -0
- package/src/Games/_GameTemplate/character.ts +31 -0
- package/src/Games/_GameTemplate/customTexts.ts +8 -0
- package/src/Games/_GameTemplate/interfaces/action.ts +5 -0
- package/src/Games/_GameTemplate/interfaces/combatSetup.ts +7 -0
- package/src/Games/_GameTemplate/interfaces/combatTurn.ts +8 -0
- package/src/Games/_GameTemplate/interfaces/destination.ts +5 -0
- package/src/Games/_GameTemplate/interfaces/enemy.ts +11 -0
- package/src/Games/_GameTemplate/interfaces/equipment.ts +5 -0
- package/src/Games/_GameTemplate/interfaces/feature.ts +9 -0
- package/src/Games/_GameTemplate/interfaces/game.ts +22 -0
- package/src/Games/_GameTemplate/interfaces/interfaceTexts.ts +5 -0
- package/src/Games/_GameTemplate/interfaces/item.ts +18 -0
- package/src/Games/_GameTemplate/interfaces/key.ts +10 -0
- package/src/Games/_GameTemplate/interfaces/location.ts +22 -0
- package/src/Games/_GameTemplate/interfaces/map.ts +16 -0
- package/src/Games/_GameTemplate/interfaces/party.ts +8 -0
- package/src/Games/_GameTemplate/interfaces/person.ts +11 -0
- package/src/Games/_GameTemplate/interfaces/quest.ts +9 -0
- package/src/Games/_GameTemplate/locations/Start.html +5 -0
- package/src/Games/_GameTemplate/locations/start.ts +12 -0
- package/src/Games/_GameTemplate/rules.ts +60 -0
- package/src/Games/_GameTemplate/types.ts +55 -0
- package/src/Games/_GameTemplate/ui/styles/game.css +3 -0
- package/src/Games/_GameTemplate/webroot/favicon.ico +0 -0
- package/src/Games/_GameTemplate/webroot/gameinfo.json +10 -0
- package/src/Games/_GameTemplate/webroot/logo192.png +0 -0
- package/src/Games/_GameTemplate/webroot/logo512.png +0 -0
- package/src/Tests/Games/_GameTemplate/specs/rules.test.ts +9 -0
- package/src/UI/Components/AppShell.vue +43 -0
- package/src/UI/Components/Autoplay.vue +32 -0
- package/src/UI/Components/Combinations.vue +37 -0
- package/src/UI/Components/Common/Collapsible.vue +50 -0
- package/src/UI/Components/Common/ModalDialog.vue +54 -0
- package/src/UI/Components/Common/Sprite.vue +53 -0
- package/src/UI/Components/Description.vue +23 -0
- package/src/UI/Components/Encounter/Combat/Combat.vue +89 -0
- package/src/UI/Components/Encounter/Combat/CombatActions.vue +26 -0
- package/src/UI/Components/Encounter/Combat/CombatParticipant.vue +22 -0
- package/src/UI/Components/Encounter/Combat/CombatTargetSelect.vue +55 -0
- package/src/UI/Components/Encounter/Combat/CombatWin.vue +33 -0
- package/src/UI/Components/Encounter/Conversation.vue +66 -0
- package/src/UI/Components/Encounter/Encounter.vue +39 -0
- package/src/UI/Components/Encounter/Enemy.vue +30 -0
- package/src/UI/Components/Encounter/Trade/Stock.vue +58 -0
- package/src/UI/Components/Encounter/Trade/Trade.vue +24 -0
- package/src/UI/Components/Exploration/ActionLog.vue +17 -0
- package/src/UI/Components/Exploration/Destination.vue +66 -0
- package/src/UI/Components/Exploration/Exploration.vue +67 -0
- package/src/UI/Components/Exploration/Ground.vue +22 -0
- package/src/UI/Components/Exploration/LocationMap.vue +42 -0
- package/src/UI/Components/Exploration/LocationText.vue +39 -0
- package/src/UI/Components/Exploration/LocationVisual.vue +38 -0
- package/src/UI/Components/GameContainer.vue +49 -0
- package/src/UI/Components/GameMenu.vue +111 -0
- package/src/UI/Components/GameState/GameOver.vue +20 -0
- package/src/UI/Components/GameState/HighScores.vue +22 -0
- package/src/UI/Components/GameState/Intro.vue +17 -0
- package/src/UI/Components/GameState/TitleScreen.vue +42 -0
- package/src/UI/Components/GameState/Victory.vue +28 -0
- package/src/UI/Components/Navigation.vue +94 -0
- package/src/UI/Components/Party/Backpack.vue +68 -0
- package/src/UI/Components/Party/BuildCharacter.vue +64 -0
- package/src/UI/Components/Party/CharacterSheet.vue +57 -0
- package/src/UI/Components/Party/CreateCharacter.vue +46 -0
- package/src/UI/Components/Party/Equipment.vue +48 -0
- package/src/UI/Components/Party/EquipmentSlot.vue +31 -0
- package/src/UI/Components/Party/LevelUp.vue +27 -0
- package/src/UI/Components/Party/Party.vue +29 -0
- package/src/UI/Components/Party/Quests.vue +48 -0
- package/src/UI/Components/Sound.vue +42 -0
- package/src/UI/Composables/CustomCursor.ts +60 -0
- package/src/UI/Composables/LocationMap.ts +315 -0
- package/src/UI/Composables/Sound.ts +111 -0
- package/src/UI/Composables/TextFeatures.ts +148 -0
- package/src/UI/Composables/VisualFeatures.ts +220 -0
- package/src/UI/Composables/index.ts +15 -0
- package/src/UI/Composables/playStateWatch.ts +31 -0
- package/src/UI/StateStore.ts +237 -0
- package/src/UI/error.ts +6 -0
- package/src/UI/helpers.ts +62 -0
- package/src/UI/index.ts +13 -0
- package/src/UI/main.ts +62 -0
- package/src/UI/startup.ts +58 -0
- package/src/UI/styles/bootstrap-storyscript.scss +31 -0
- package/src/UI/styles/empty.css +3 -0
- package/src/UI/styles/lookinglass.png +0 -0
- package/src/UI/styles/storyscript.css +735 -0
- package/typeExtensions.d.ts +25 -0
- package/vite-env.d.ts +1 -0
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import {IGame, IRules, ISoundPlayer, ISoundService, selectStateListEntry} from 'storyScript';
|
|
2
|
+
|
|
3
|
+
export class SoundService implements ISoundService {
|
|
4
|
+
private _musicStopped: boolean = false;
|
|
5
|
+
|
|
6
|
+
constructor(private _game: IGame, private _rules: IRules) {
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
getSounds = (): ISoundPlayer => {
|
|
10
|
+
return {
|
|
11
|
+
startMusic: this.startMusic,
|
|
12
|
+
stopMusic: this.stopMusic,
|
|
13
|
+
playSound: this.playSound,
|
|
14
|
+
soundQueue: new Map<number, { value: string, playing: boolean, completeCallBack?: () => void }>,
|
|
15
|
+
playedAudio: []
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
getCurrentMusic = (): string => {
|
|
20
|
+
if (this._musicStopped || !this._rules.setup?.playList || Object.keys(this._rules.setup.playList).length === undefined) {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return selectStateListEntry(this._game, this._rules.setup.playList);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
private startMusic = (): boolean => this._musicStopped = false;
|
|
28
|
+
|
|
29
|
+
private stopMusic = (): boolean => this._musicStopped = true;
|
|
30
|
+
|
|
31
|
+
private playSound = (fileName: string, completeCallBack?: () => void): void => {
|
|
32
|
+
this._game.sounds.soundQueue.set(this.createHash(fileName + Math.floor(Math.random() * 1000)), {
|
|
33
|
+
value: fileName,
|
|
34
|
+
playing: false,
|
|
35
|
+
completeCallBack: completeCallBack
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
private createHash(value: string): number {
|
|
40
|
+
let hash = 0;
|
|
41
|
+
|
|
42
|
+
if (!value || value.length == 0) {
|
|
43
|
+
return hash;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
for (let i = 0; i < value.length; i++) {
|
|
47
|
+
const char = value.charCodeAt(i);
|
|
48
|
+
hash = ((hash << 5) - hash) + char;
|
|
49
|
+
hash = hash & hash; // Convert to 32bit integer
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return hash;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import {
|
|
2
|
+
gameEvents,
|
|
3
|
+
IAction,
|
|
4
|
+
ICharacter,
|
|
5
|
+
IDefinitions,
|
|
6
|
+
IGame,
|
|
7
|
+
IGroupableItem,
|
|
8
|
+
IInterfaceTexts,
|
|
9
|
+
IItem,
|
|
10
|
+
IItemService,
|
|
11
|
+
IPerson,
|
|
12
|
+
IRules,
|
|
13
|
+
ITrade,
|
|
14
|
+
ITradeService,
|
|
15
|
+
PlayState,
|
|
16
|
+
randomList
|
|
17
|
+
} from 'storyScript';
|
|
18
|
+
import {StateProperties} from "src/Engine/stateProperties";
|
|
19
|
+
|
|
20
|
+
const tradeEvent = 'trade';
|
|
21
|
+
|
|
22
|
+
export class TradeService implements ITradeService {
|
|
23
|
+
private _activeTrader: IPerson;
|
|
24
|
+
|
|
25
|
+
constructor(private readonly _itemService: IItemService, private readonly _game: IGame, private readonly _rules: IRules, private readonly _texts: IInterfaceTexts, private readonly _definitions: IDefinitions) {
|
|
26
|
+
gameEvents.register(tradeEvent);
|
|
27
|
+
gameEvents.subscribe(tradeEvent, (game, data: [string, IAction]) => {
|
|
28
|
+
const trader = game.currentLocation.trade.find(t => t.id === data[0]);
|
|
29
|
+
this.trade(trader);
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
trade = (trade: IPerson | ITrade): void => {
|
|
34
|
+
const isPerson = trade && trade['type'] === 'person';
|
|
35
|
+
const person = <IPerson>trade;
|
|
36
|
+
|
|
37
|
+
if (isPerson) {
|
|
38
|
+
this._activeTrader = this._game.person = person;
|
|
39
|
+
this._game.trade = person.trade;
|
|
40
|
+
this._game.trade.currency = person.currency ?? 0;
|
|
41
|
+
|
|
42
|
+
if (!this._game.trade.name) {
|
|
43
|
+
this._game.trade.name = this._texts.format(this._texts.trade, [person.name]);
|
|
44
|
+
}
|
|
45
|
+
} else {
|
|
46
|
+
trade.currency ??= 0;
|
|
47
|
+
this._activeTrader = <IPerson>{currency: trade.currency};
|
|
48
|
+
this._game.trade = trade;
|
|
49
|
+
this._game.trade.ownItemsOnly = false;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
this.initTrade();
|
|
53
|
+
this._game.playState = PlayState.Trade;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
canPay = (item: IItem, buyer: ITrade | ICharacter, seller: ITrade | ICharacter): boolean => {
|
|
57
|
+
if (this._rules.general.canBuyItem && !this._rules.general.canBuyItem(this._game, item, buyer)) {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const trader = buyer as ITrade;
|
|
62
|
+
const currency = trader.buy ? trader.currency : this._game.party.currency;
|
|
63
|
+
const price = this.actualPrice(item, buyer, seller);
|
|
64
|
+
return (price !== undefined && currency !== undefined && currency >= price) || price === 0;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
actualPrice = (item: IItem, buyer: ITrade | ICharacter, seller: ITrade | ICharacter): number => {
|
|
68
|
+
let resolvedModifier: number;
|
|
69
|
+
const buyerTrade = buyer as ITrade;
|
|
70
|
+
const sellerTrade = seller as ITrade;
|
|
71
|
+
const modifier = buyerTrade.sell?.priceModifier ?? sellerTrade.buy?.priceModifier;
|
|
72
|
+
|
|
73
|
+
if (modifier === undefined) {
|
|
74
|
+
resolvedModifier = 1;
|
|
75
|
+
} else if (typeof modifier === 'function') {
|
|
76
|
+
resolvedModifier = (<((game: IGame) => number)>modifier)(this._game)
|
|
77
|
+
} else {
|
|
78
|
+
resolvedModifier = modifier;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const members = <IItem[]>(item as IGroupableItem<IItem>).members;
|
|
82
|
+
const values = members ? members.concat([item]).map(m => m.value) : [item.value];
|
|
83
|
+
const totalValue = values.reduce((t, c) => t + c, 0);
|
|
84
|
+
return Math.round(totalValue * resolvedModifier);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
displayPrice = (item: IItem, actualPrice: number): string => actualPrice > 0 ? this._texts.format(this._texts.stockItemDisplayText, [this._itemService.getItemName(item), actualPrice.toString(), this._texts.currency]) : this._itemService.getItemName(item);
|
|
88
|
+
|
|
89
|
+
buy = (item: IItem, trade: ITrade): boolean => {
|
|
90
|
+
if (!this.canPay(item, this._game.activeCharacter, trade)) {
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const price = this.actualPrice(item, this._game.activeCharacter, trade);
|
|
95
|
+
trade.currency += price;
|
|
96
|
+
this._game.party.currency -= price;
|
|
97
|
+
this._activeTrader.currency = trade.currency;
|
|
98
|
+
trade.buy.items.delete(item);
|
|
99
|
+
this._game.activeCharacter.items.add(item);
|
|
100
|
+
|
|
101
|
+
if (trade.onBuy) {
|
|
102
|
+
trade.onBuy(this._game, item);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return true;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
sell = (item: IItem, trade: ITrade): boolean => {
|
|
109
|
+
if (!this.canPay(item, trade, this._game.activeCharacter)) {
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const price = this.actualPrice(item, trade, this._game.activeCharacter);
|
|
114
|
+
trade.currency -= price;
|
|
115
|
+
this._game.party.currency += price;
|
|
116
|
+
this._activeTrader.currency = trade.currency;
|
|
117
|
+
this._game.activeCharacter.items.delete(item);
|
|
118
|
+
trade.sell.items.delete(item);
|
|
119
|
+
trade.buy.items.add(item);
|
|
120
|
+
|
|
121
|
+
if (trade.onSell) {
|
|
122
|
+
trade.onSell(this._game, item);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
return true;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
private initTrade = (): ITrade => {
|
|
129
|
+
const trader = this._game.trade;
|
|
130
|
+
|
|
131
|
+
if (!trader) {
|
|
132
|
+
return null;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
let itemsForSale: IItem[];
|
|
136
|
+
|
|
137
|
+
if (trader.buy.items) {
|
|
138
|
+
itemsForSale = trader.buy.items.slice();
|
|
139
|
+
} else if (trader[StateProperties.Triggered]) {
|
|
140
|
+
itemsForSale = []
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const buySelector = (item: IItem) => {
|
|
144
|
+
return trader.buy.itemSelector(this._game, item);
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
// When visiting a trader for the first time and he has an initCollection function set, set the items for sale.
|
|
148
|
+
if (trader.buy.initCollection?.(this._game, trader) || !itemsForSale) {
|
|
149
|
+
const collection = <any>(trader.ownItemsOnly ? this._game.person.items : this._definitions.items);
|
|
150
|
+
itemsForSale = randomList<IItem>(collection, trader.buy.maxItems, buySelector);
|
|
151
|
+
trader[StateProperties.Triggered] = true;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
const sellSelector = (item: IItem) => {
|
|
155
|
+
return trader.sell.itemSelector(this._game, item);
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
const itemsToSell = randomList<IItem>(this._game.activeCharacter.items, trader.sell.maxItems, sellSelector);
|
|
159
|
+
trader.buy.items ??= []
|
|
160
|
+
|
|
161
|
+
// Filter existing items using the buy selector, also when edits are made, so items that were
|
|
162
|
+
// added before but should not be available from the trader anymore are removed. Also do apply
|
|
163
|
+
// the maxItems property on edits as well.
|
|
164
|
+
trader.buy.items.length = 0;
|
|
165
|
+
itemsForSale?.filter(buySelector).slice(0, trader.buy.maxItems).forEach(i => trader.buy.items.add(i));
|
|
166
|
+
|
|
167
|
+
trader.sell.items ??= [];
|
|
168
|
+
trader.sell.items.length = 0;
|
|
169
|
+
itemsToSell.forEach(i => trader.sell.items.push(i));
|
|
170
|
+
|
|
171
|
+
trader.buy.confirmationText ??= this._texts.buyConfirmationText;
|
|
172
|
+
trader.sell.confirmationText ??= this._texts.sellConfirmationText;
|
|
173
|
+
|
|
174
|
+
return trader;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export { AutoplayService } from './AutoplayService';
|
|
2
|
+
export { CharacterService } from './CharacterService';
|
|
3
|
+
export { CombatService } from './CombatService';
|
|
4
|
+
export { CombinationService } from './CombinationService';
|
|
5
|
+
export { CommandService } from './CommandService';
|
|
6
|
+
export { ConversationService } from './ConversationService';
|
|
7
|
+
export { DataSerializer } from './DataSerializer';
|
|
8
|
+
export { DataService } from './DataService';
|
|
9
|
+
export { DataSynchronizer } from './DataSynchronizer';
|
|
10
|
+
export { GameService } from './GameService';
|
|
11
|
+
export { HelperService } from './HelperService';
|
|
12
|
+
export { ItemService } from './ItemService';
|
|
13
|
+
export { LocalStorageService } from './LocalStorageService';
|
|
14
|
+
export { LocationService } from './LocationService';
|
|
15
|
+
export { SoundService } from './SoundService';
|
|
16
|
+
export { TradeService } from './TradeService';
|
|
17
|
+
export * from './sharedFunctions';
|
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
import {
|
|
2
|
+
GameState,
|
|
3
|
+
ICharacter,
|
|
4
|
+
IDefinitions,
|
|
5
|
+
IGame,
|
|
6
|
+
IItem,
|
|
7
|
+
ILocation,
|
|
8
|
+
IParty,
|
|
9
|
+
PlayState,
|
|
10
|
+
StateList,
|
|
11
|
+
StateListEntry
|
|
12
|
+
} from 'storyScript';
|
|
13
|
+
import {compareString} from "src/Engine/utilityFunctions";
|
|
14
|
+
import {getParsedDocument} from "src/Engine/EntityCreatorFunctions";
|
|
15
|
+
import {DescriptionProperty} from 'src/constants';
|
|
16
|
+
|
|
17
|
+
const parsedDescriptions = new Map<string, boolean>();
|
|
18
|
+
|
|
19
|
+
export function hasDescription(entity: { id?: string, description?: string }): boolean {
|
|
20
|
+
if (!entity.description) {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (!parsedDescriptions.get(entity.id)) {
|
|
25
|
+
const descriptionNode = getParsedDocument(DescriptionProperty, entity.description)[0];
|
|
26
|
+
parsedDescriptions.set(entity.id, descriptionNode?.innerHTML?.trim() !== '');
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return parsedDescriptions.get(entity.id);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function random<T>(type: string, definitions: IDefinitions, selector?: (item: T) => boolean): T {
|
|
33
|
+
const collection = definitions[type];
|
|
34
|
+
|
|
35
|
+
if (!collection) {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const selection = getFilteredInstantiatedCollection<T>(collection, selector);
|
|
40
|
+
|
|
41
|
+
if (selection.length == 0) {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const index = Math.floor(Math.random() * selection.length);
|
|
46
|
+
return selection[index];
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function randomList<T>(collection: T[] | ([() => T]), count: number, selector?: (item: T) => boolean): T[] {
|
|
50
|
+
const selection = getFilteredInstantiatedCollection<T>(collection, selector);
|
|
51
|
+
const results = <T[]>[];
|
|
52
|
+
|
|
53
|
+
if (count === undefined) {
|
|
54
|
+
count = selection.length;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (selection.length > 0) {
|
|
58
|
+
while (results.length < count && results.length < selection.length) {
|
|
59
|
+
const index = Math.floor(Math.random() * selection.length);
|
|
60
|
+
|
|
61
|
+
if (results.indexOf(selection[index]) == -1) {
|
|
62
|
+
results.push(selection[index]);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return results;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// This allows deserializing functions added at runtime without using eval.
|
|
71
|
+
// Found at https://stackoverflow.com/questions/7650071/is-there-a-way-to-create-a-function-from-a-string-with-javascript
|
|
72
|
+
export function parseFunction<T extends Function>(text: string) {
|
|
73
|
+
const funcReg = /function[\s]*([a-z\d]*)(\([\s\w\d,]*\))[\s]*({[\S\s]*})/gmi;
|
|
74
|
+
const match = funcReg.exec(text);
|
|
75
|
+
|
|
76
|
+
if (match) {
|
|
77
|
+
const args = match[2].substring(1, match[2].length - 1);
|
|
78
|
+
return <T>(new Function(args, match[3]));
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* This function creates a new function with the callback embedded. This makes the new function safe for serialization.
|
|
86
|
+
* @param functionDefinition The main function to make safe for serialization.
|
|
87
|
+
* @param callback The callback function to embed.
|
|
88
|
+
* @returns The main function with the callback embedded.
|
|
89
|
+
*/
|
|
90
|
+
export function makeSerializeSafe<T extends Function>(functionDefinition: T, callback: Function): T {
|
|
91
|
+
let serialized = serializeFunction(functionDefinition);
|
|
92
|
+
|
|
93
|
+
if (callback) {
|
|
94
|
+
const functionSignature = /function(\((?:[a-zA-Z]+[, )]+)*)/.exec(serialized);
|
|
95
|
+
const functionParams = functionSignature[1];
|
|
96
|
+
const callbackSignature = Array.from(serialized.matchAll(new RegExp('([a-zA-z]+)[\?\.]{0,2}\\(' + functionParams + '\\)', 'gm')))[1];
|
|
97
|
+
|
|
98
|
+
if (callbackSignature) {
|
|
99
|
+
const callbackName = callbackSignature[1];
|
|
100
|
+
const startIndex = serialized.indexOf('{') + 1;
|
|
101
|
+
serialized = serialized.substring(0, startIndex) + `const ${callbackName} = ${serializeFunction(callback)};` + serialized.substring(startIndex);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return parseFunction<T>(serialized);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export function serializeFunction(value: Function) {
|
|
109
|
+
const _functionArgumentRegex = /\([a-z-A-Z0-9:, ]+\)/;
|
|
110
|
+
|
|
111
|
+
// Functions added during runtime must be serialized using the function() notation in order to be deserialized back
|
|
112
|
+
// to a function. Convert values that have an arrow notation.
|
|
113
|
+
let functionString = value.toString();
|
|
114
|
+
const argumentString = functionString.substring(0, functionString.indexOf('{'));
|
|
115
|
+
|
|
116
|
+
if (argumentString.indexOf('function') == -1) {
|
|
117
|
+
const arrowIndex = argumentString.indexOf('=>');
|
|
118
|
+
|
|
119
|
+
// The arguments regex will fail when no arguments are used in production mode. Use empty brackets in that case.
|
|
120
|
+
const args = _functionArgumentRegex.exec(functionString)?.[0] || '()';
|
|
121
|
+
|
|
122
|
+
functionString = 'function' + args + functionString.substring(arrowIndex + 2).trim();
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
return functionString;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export function parseGamePropertiesInTemplate(lines: string, game?: IGame): string {
|
|
129
|
+
const propertyRegex = /{(?:[a-zA-Z\[\]0-9]+[.]?)+}/g;
|
|
130
|
+
const indexRegex = /\[\d+]/g;
|
|
131
|
+
let result = lines;
|
|
132
|
+
let parseMatch = null;
|
|
133
|
+
|
|
134
|
+
while ((parseMatch = propertyRegex.exec(lines)) !== null) {
|
|
135
|
+
let property = <unknown>game;
|
|
136
|
+
let replacement = parseMatch[0];
|
|
137
|
+
let index = null;
|
|
138
|
+
let propertyFound = false;
|
|
139
|
+
|
|
140
|
+
parseMatch[0].replace(/{|}/g, '').split('.').forEach((e: string) => {
|
|
141
|
+
index = indexRegex.exec(e);
|
|
142
|
+
|
|
143
|
+
if (index) {
|
|
144
|
+
e = e.replace(index, '');
|
|
145
|
+
index = parseInt(index[0].replace(/\[|\]/g, ''));
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
if (property.hasOwnProperty(e)) {
|
|
149
|
+
property = property[e];
|
|
150
|
+
propertyFound = true;
|
|
151
|
+
} else {
|
|
152
|
+
propertyFound = false;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
if (!isNaN(index) && Array.isArray(property)) {
|
|
156
|
+
property = property[index];
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
if (propertyFound) {
|
|
161
|
+
replacement = property;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
lines = lines.replace(`${parseMatch[0]}`, '');
|
|
165
|
+
result = result.replace(`${parseMatch[0]}`, replacement);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
return result;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
export function selectStateListEntry(game: IGame, stateList: StateList) {
|
|
172
|
+
// Evaluate custom functions first.
|
|
173
|
+
const customFunctions = stateList[''];
|
|
174
|
+
let result = null;
|
|
175
|
+
|
|
176
|
+
customFunctions?.filter(f => typeof f === 'function').forEach(f => {
|
|
177
|
+
result = f(game);
|
|
178
|
+
})
|
|
179
|
+
|
|
180
|
+
if (result) {
|
|
181
|
+
return result;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// Next, get the entries in this order: Location, PlayState, GameState.
|
|
185
|
+
const filteredEntries = Object.keys(stateList)
|
|
186
|
+
.map(e => mapPlaylistEntries(game, e, stateList[e]))
|
|
187
|
+
.filter(e => e);
|
|
188
|
+
|
|
189
|
+
result = filteredEntries.map(e => selectCandidate(game, e.key, e.item))
|
|
190
|
+
.filter(i => i.order > 0)
|
|
191
|
+
.sort((a, b) => a.order - b.order)[0];
|
|
192
|
+
|
|
193
|
+
return result?.key;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function mapPlaylistEntries(game: IGame, key: string, entry: StateListEntry) {
|
|
197
|
+
return entry.map(i => selectCandidate(game, key, i))
|
|
198
|
+
.filter(i => i.order > 0)
|
|
199
|
+
.sort((a, b) => a.order - b.order)[0];
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
export function getItemFromParty(party: IParty, item: string | (() => IItem)): IItem {
|
|
203
|
+
let foundItem: IItem;
|
|
204
|
+
|
|
205
|
+
party.characters.forEach(c => {
|
|
206
|
+
foundItem = foundItem ?? getItemFromItemsAndEquipment(c, item);
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
return foundItem;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
export function removeItemFromParty(party: IParty, item: IItem | (() => IItem)) {
|
|
213
|
+
let deleted = false;
|
|
214
|
+
|
|
215
|
+
party.characters.forEach(c => {
|
|
216
|
+
if (deleted) {
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
deleted = removeItemFromItemsAndEquipment(c, item);
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
export function removeItemFromItemsAndEquipment(character: ICharacter, item: IItem | (() => IItem)): boolean {
|
|
225
|
+
let deleted = false;
|
|
226
|
+
|
|
227
|
+
if (character.items.get(item)) {
|
|
228
|
+
character.items.delete(item);
|
|
229
|
+
deleted = true;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
if (character.equipment) {
|
|
233
|
+
for (const n in character.equipment) {
|
|
234
|
+
if (item === character.equipment[n]) {
|
|
235
|
+
character.equipment[n] = null;
|
|
236
|
+
deleted = true;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
if (deleted) {
|
|
240
|
+
break;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
return deleted;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
function getItemFromItemsAndEquipment(character: ICharacter, item: string | (() => IItem)): IItem {
|
|
249
|
+
let foundItem = character.items.get(item);
|
|
250
|
+
|
|
251
|
+
if (foundItem) {
|
|
252
|
+
return foundItem;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
if (character.equipment) {
|
|
256
|
+
for (const n in character.equipment) {
|
|
257
|
+
const currentItem = character.equipment[n] as IItem;
|
|
258
|
+
|
|
259
|
+
if ((typeof item === 'function' && currentItem.id == item.name) || (currentItem.id == item)) {
|
|
260
|
+
return character.equipment[n];
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
return null;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
function getFilteredInstantiatedCollection<T>(collection: T[] | (() => T)[], selector?: (item: T) => boolean) {
|
|
269
|
+
let collectionToFilter = <T[]>[];
|
|
270
|
+
|
|
271
|
+
if (typeof collection[0] === 'function') {
|
|
272
|
+
(<[() => T]>collection).forEach((def: () => T) => {
|
|
273
|
+
collectionToFilter.push(def());
|
|
274
|
+
});
|
|
275
|
+
} else {
|
|
276
|
+
collectionToFilter = <T[]>collection;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
return selector ? collectionToFilter.filter(selector) : collectionToFilter;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
function selectCandidate(game: IGame, key: string, item: (GameState | PlayState | (() => ILocation) | ((game: IGame) => string) | string)) {
|
|
283
|
+
const functionName = (<Function>item)?.name;
|
|
284
|
+
const currentLocationId = game.currentLocation?.id;
|
|
285
|
+
let order: number;
|
|
286
|
+
|
|
287
|
+
if (item === game.state) {
|
|
288
|
+
order = 3;
|
|
289
|
+
} else if (item === game.playState) {
|
|
290
|
+
order = 2;
|
|
291
|
+
} else {
|
|
292
|
+
order = functionName && currentLocationId && compareString(functionName, currentLocationId) ? 1 : 0
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
return {key, item, order};
|
|
296
|
+
}
|