inventory-slots #49

Merged
sebastian merged 13 commits from inventory-slots into main 2024-05-11 15:36:10 +02:00
4 changed files with 85 additions and 8 deletions
Showing only changes of commit 216d9aec07 - Show all commits

View File

@ -215,11 +215,6 @@ export class AppComponent implements OnInit{
gameModel.gamesystems = gamesystems gameModel.gamesystems = gamesystems
gameModel.generateProductSystemContents() gameModel.generateProductSystemContents()
const characterTemplateSystems = gameModel.getTemplateSystems(TemplateType.CHARACTER).map(templateSystem => templateSystem as SimpleTemplateGamesystem)
const characterRelationTemplateSystems = gameModel.getTemplateSystems(TemplateType.CHARACTER_RELATION).map(templateSystem => templateSystem as SimpleTemplateGamesystem)
const characterParser = new CharacterParser(characterTemplateSystems, characterRelationTemplateSystems, gameModel.scriptAccounts);
gameModel.characters = characterParser.parseCharacters(storedGameModel.storedCharacters)
const itemgroupParser = new ItemgroupParser(); const itemgroupParser = new ItemgroupParser();
itemgroupParser.parseItemgroups(storedGameModel.storedItemgroups); itemgroupParser.parseItemgroups(storedGameModel.storedItemgroups);
gameModel.itemgroups = itemgroupParser.getParsedTopItemgroups(); gameModel.itemgroups = itemgroupParser.getParsedTopItemgroups();
@ -227,6 +222,13 @@ export class AppComponent implements OnInit{
const itemParser = new ItemParser(itemgroupParser.getParsedItemgroups()) const itemParser = new ItemParser(itemgroupParser.getParsedItemgroups())
itemParser.parseItems(storedGameModel.storedItems); itemParser.parseItems(storedGameModel.storedItems);
const characterTemplateSystems = gameModel.getTemplateSystems(TemplateType.CHARACTER).map(templateSystem => templateSystem as SimpleTemplateGamesystem)
const characterRelationTemplateSystems = gameModel.getTemplateSystems(TemplateType.CHARACTER_RELATION).map(templateSystem => templateSystem as SimpleTemplateGamesystem)
const characterParser = new CharacterParser(characterTemplateSystems, characterRelationTemplateSystems, gameModel.scriptAccounts, itemgroupParser.getCharacteristics(), itemgroupParser.getParsedItemgroups());
gameModel.characters = characterParser.parseCharacters(storedGameModel.storedCharacters)
this.gameModel = gameModel; this.gameModel = gameModel;
} }

View File

@ -7,8 +7,9 @@ import {ScriptAccount} from "../../game-model/scriptAccounts/ScriptAccount";
import {SimpleTemplateState} from "../../game-model/templates/simpleGamesystem/SimpleTemplateState"; import {SimpleTemplateState} from "../../game-model/templates/simpleGamesystem/SimpleTemplateState";
import {SimpleTemplateTransition} from "../../game-model/templates/simpleGamesystem/SimpleTemplateTransition"; import {SimpleTemplateTransition} from "../../game-model/templates/simpleGamesystem/SimpleTemplateTransition";
import {CharacterRelation} from "../../game-model/characters/CharacterRelation"; import {CharacterRelation} from "../../game-model/characters/CharacterRelation";
import {load} from "@angular-devkit/build-angular/src/utils/server-rendering/esm-in-memory-loader/loader-hooks"; import {InventorySlotParser} from "./InventorySlotParser";
import {Gamesystem} from "../../game-model/gamesystems/Gamesystem"; import {ItemGroupCharacteristic} from "../../game-model/inventory/ItemgroupCharacteristic";
import {ItemGroup} from "../../game-model/inventory/ItemGroup";
export class CharacterParser { export class CharacterParser {
@ -17,12 +18,14 @@ export class CharacterParser {
characterRelationSpecificGamesystems: SimpleTemplateGamesystem[] characterRelationSpecificGamesystems: SimpleTemplateGamesystem[]
scriptAccountConditionParser: ScriptAccountConditionParser scriptAccountConditionParser: ScriptAccountConditionParser
scriptAccountActionParser: ScriptAccountActionParser scriptAccountActionParser: ScriptAccountActionParser
inventorySlotParser: InventorySlotParser
constructor(characterSpecificGamesystems: SimpleTemplateGamesystem[], characterRelationSpecificGamesystems: SimpleTemplateGamesystem[], scriptAccounts: ScriptAccount[]) { constructor(characterSpecificGamesystems: SimpleTemplateGamesystem[], characterRelationSpecificGamesystems: SimpleTemplateGamesystem[], scriptAccounts: ScriptAccount[], characteristics: ItemGroupCharacteristic[], itemgroups: ItemGroup[]) {
this.characterSpecificGamesystems = characterSpecificGamesystems; this.characterSpecificGamesystems = characterSpecificGamesystems;
this.characterRelationSpecificGamesystems = characterRelationSpecificGamesystems; this.characterRelationSpecificGamesystems = characterRelationSpecificGamesystems;
this.scriptAccountActionParser = new ScriptAccountActionParser(scriptAccounts); this.scriptAccountActionParser = new ScriptAccountActionParser(scriptAccounts);
this.scriptAccountConditionParser = new ScriptAccountConditionParser(scriptAccounts) this.scriptAccountConditionParser = new ScriptAccountConditionParser(scriptAccounts)
this.inventorySlotParser = new InventorySlotParser(characteristics, itemgroups);
} }
@ -46,6 +49,8 @@ export class CharacterParser {
const characterRelationGamesystems = this.parseCharacterSpecificGamesystems(character, characterData.characterRelationGamesystems, this.characterRelationSpecificGamesystems) const characterRelationGamesystems = this.parseCharacterSpecificGamesystems(character, characterData.characterRelationGamesystems, this.characterRelationSpecificGamesystems)
characterRelationGamesystems.forEach(gamesystem => character.addAsymetricCharacterRelationGamesystem(gamesystem)) characterRelationGamesystems.forEach(gamesystem => character.addAsymetricCharacterRelationGamesystem(gamesystem))
character.inventorySlots = this.inventorySlotParser.parseInventorySlots(characterData.inventorySlots);
return character; return character;
} }

View File

@ -0,0 +1,64 @@
import {ItemGroupCharacteristic} from "../../game-model/inventory/ItemgroupCharacteristic";
import {ItemGroup} from "../../game-model/inventory/ItemGroup";
import {InventorySlot} from "../../game-model/inventory/intentory-slots/InventorySlot";
import {InventorySlotSerializer} from "../../serializer/InventorySlotSerializer";
import {InventoryCharacteristic} from "../../game-model/inventory/intentory-slots/InventoryCharacteristic";
export class InventorySlotParser {
private parsedCharacteristics: ItemGroupCharacteristic[]
private parsedItemgroups: ItemGroup[]
constructor(parsedCharacteristics: ItemGroupCharacteristic[], parsedItemgroups: ItemGroup[]) {
this.parsedCharacteristics = parsedCharacteristics;
this.parsedItemgroups = parsedItemgroups;
}
parseInventorySlots(inventorySlotData: any): InventorySlot[] {
const result: InventorySlot[] = []
for(let i=0; i<inventorySlotData.length; i++) {
result.push(this.parseSingleInventorySlot(inventorySlotData[i]))
}
return result;
}
private parseSingleInventorySlot(inventorySlotData: any): InventorySlot {
const slotName = inventorySlotData.slotName;
const slotCharacteristics = this.parseSlotCharacteristics(inventorySlotData.slotCharacteristics)
const inheritedGroups = this.parseRequieredInheritedItemgroups(inventorySlotData.requiredInheritances);
const inventorySlot = new InventorySlot(slotName);
inventorySlot.slotCharacteristics = slotCharacteristics;
inventorySlot.requiredInheritances = inheritedGroups;
return inventorySlot;
}
private parseSlotCharacteristics(slotCharacteristicsData: any): InventoryCharacteristic[] {
const characteristics: InventoryCharacteristic[] = []
for(let i=0; i<slotCharacteristicsData.length; i++) {
const increasingCharacteristic = this.findReferencedCharacteristic(slotCharacteristicsData[i].increasingCharacteristic);
const decreasingCharacteristic = this.findReferencedCharacteristic(slotCharacteristicsData[i].decreasingCharacteristic);
characteristics.push(new InventoryCharacteristic(increasingCharacteristic!, decreasingCharacteristic!))
}
return characteristics;
}
private parseRequieredInheritedItemgroups(inheritanceData: any): ItemGroup[] {
const result: ItemGroup[] = []
for(let i=0; i<inheritanceData.length; i++) {
const inheritedGroup = this.findReferencedItemgroup(inheritanceData[i]);
if(inheritedGroup != undefined) {
result.push(inheritedGroup);
}
}
return result;
}
private findReferencedCharacteristic(characteristicName: string) {
return this.parsedCharacteristics.find(characteristic => characteristic.characteristicName === characteristicName);
}
private findReferencedItemgroup(groupName: string) {
return this.parsedItemgroups.find(group => group.componentName === groupName);
}
}

View File

@ -9,6 +9,7 @@ export class ItemgroupParser {
private parsedItemgroups: ItemGroup[] = [] private parsedItemgroups: ItemGroup[] = []
private topParsedItemgroups: ItemGroup[] = [] private topParsedItemgroups: ItemGroup[] = []
private parsedCharacteristics: ItemGroupCharacteristic[] = []
parseItemgroups(storeComponents: StoreComponent[]) { parseItemgroups(storeComponents: StoreComponent[]) {
const topologicalSort = this.topologicalSort(storeComponents); const topologicalSort = this.topologicalSort(storeComponents);
@ -81,6 +82,7 @@ export class ItemgroupParser {
const characteristic = new ItemGroupCharacteristic(name, description, itemgroup); const characteristic = new ItemGroupCharacteristic(name, description, itemgroup);
characteristic.itemgroup.addItemgroupCharacteristic(characteristic); characteristic.itemgroup.addItemgroupCharacteristic(characteristic);
this.parsedCharacteristics.push(characteristic)
return characteristic; return characteristic;
} }
@ -91,4 +93,8 @@ export class ItemgroupParser {
getParsedItemgroups() { getParsedItemgroups() {
return this.parsedItemgroups; return this.parsedItemgroups;
} }
getCharacteristics() {
return this.parsedCharacteristics;
}
} }