inventory-items-2 #44

Closed
sebastian wants to merge 32 commits from inventory-items-2 into inventory
7 changed files with 113 additions and 1 deletions
Showing only changes of commit bf4c6bd19c - Show all commits

View File

@ -11,6 +11,11 @@ import {SimpleTemplateGamesystem} from "./templates/simpleGamesystem/SimpleTempl
import {ProductTemplateSystem} from "./templates/productGamesystem/ProductTemplateSystem"; import {ProductTemplateSystem} from "./templates/productGamesystem/ProductTemplateSystem";
import {ProductTemplateCreator} from "./templates/productGamesystem/ProductTemplateCreator"; import {ProductTemplateCreator} from "./templates/productGamesystem/ProductTemplateCreator";
import {CharacterRelation} from "./characters/CharacterRelation"; import {CharacterRelation} from "./characters/CharacterRelation";
import {ItemGroup} from "./inventory/ItemGroup";
import {AbstractItemGroup} from "./inventory/AbstractItemGroup";
import {GameModelLoader} from "../../../../app/storage/loader/GameModelLoader";
import {ConcreteItemGroup} from "./inventory/ConcreteItemGroup";
import {Item} from "./inventory/Item";
export class GameModel { export class GameModel {
gameModelName: string gameModelName: string
@ -18,9 +23,63 @@ export class GameModel {
gamesystems: Gamesystem<any, any>[] = []; gamesystems: Gamesystem<any, any>[] = [];
scriptAccounts: ScriptAccount[] = []; scriptAccounts: ScriptAccount[] = [];
characters: Character[] = [] characters: Character[] = []
itemgroups: ItemGroup[] = []
constructor(gameModelName: string) { constructor(gameModelName: string) {
this.gameModelName = gameModelName; this.gameModelName = gameModelName;
this.addAbstractItemgroup("Clothing", undefined);
this.addAbstractItemgroup("Inventory", undefined);
this.addConcreteItemgroup("Oberteil", GameModel.findItemgroupByName("Clothing", this.itemgroups)! as AbstractItemGroup);
this.addConcreteItemgroup("Hose", GameModel.findItemgroupByName("Clothing", this.itemgroups)! as AbstractItemGroup);
}
addAbstractItemgroup(groupName: string, parentgroup: AbstractItemGroup | undefined) {
//Ensure that Itemgroup does not exist
if(parentgroup == undefined) {
if(GameModel.findItemgroupByName(groupName, this.itemgroups) == undefined) {
this.itemgroups.push(new AbstractItemGroup(groupName, "", ModelComponentType.ITEMGROUP));
}
} else {
if(GameModel.findItemgroupByName(groupName, parentgroup.children) == undefined) {
parentgroup.addChildItemgroup(new AbstractItemGroup(groupName, "", ModelComponentType.ITEMGROUP));
}
}
}
addConcreteItemgroup(groupName: string, parentgroup: AbstractItemGroup) {
//Ensure that Itemgroup does not exist
if(parentgroup == undefined) {
if(GameModel.findItemgroupByName(groupName, this.itemgroups) == undefined) {
this.itemgroups.push(new ConcreteItemGroup(groupName, "", ModelComponentType.ITEMGROUP));
}
} else {
if(GameModel.findItemgroupByName(groupName, parentgroup.children) == undefined) {
parentgroup.addChildItemgroup(new ConcreteItemGroup(groupName, "", ModelComponentType.ITEMGROUP));
}
}
}
addItem(itemName: string, conceteItemgroupName: string) {
const itemgroup = GameModel.findItemgroupByName(conceteItemgroupName, this.itemgroups);
if(itemgroup instanceof ConcreteItemGroup) {
itemgroup.addItem(new Item(itemName, "", ModelComponentType.ITEM ))
}
}
private static findItemgroupByName(name: string, itemgroups: ItemGroup[]) {
const itemgroupQueue: ItemGroup[] = itemgroups.concat();
while(itemgroupQueue.length > 0 ) {
const currentItemgroup = itemgroupQueue.shift()!;
if(currentItemgroup.componentName === name) {
return currentItemgroup;
}
if(currentItemgroup instanceof AbstractItemGroup) {
currentItemgroup.children.forEach(itemgroup => itemgroupQueue.push(itemgroup));
}
}
} }
addGamesystem(gamesystem: Gamesystem<any, any>) { addGamesystem(gamesystem: Gamesystem<any, any>) {

View File

@ -1,6 +1,8 @@
export enum ModelComponentType { export enum ModelComponentType {
SCRIPTACCOUNT, SCRIPTACCOUNT,
GAMESYTEM, GAMESYTEM,
CHARACTER CHARACTER,
ITEMGROUP,
ITEM
} }

View File

@ -0,0 +1,10 @@
import {ItemGroup} from "./ItemGroup";
export class AbstractItemGroup extends ItemGroup {
children: ItemGroup[] = [];
addChildItemgroup(itemGroup: ItemGroup) {
this.children.push(itemGroup)
}
}

View File

@ -0,0 +1,17 @@
import {ItemGroup} from "./ItemGroup";
import {Item} from "./Item";
export class ConcreteItemGroup extends ItemGroup {
items: Item[] = [];
addItem(item: Item) {
if(this.findItemByName(item.componentName) == undefined) {
this.items.push(item);
}
}
findItemByName(itemName: string) {
return this.items.find(item => item.componentName === itemName);
}
}

View File

@ -0,0 +1,7 @@
import {ModelComponent} from "../ModelComponent";
import {ItemGroup} from "./ItemGroup";
export class Item extends ModelComponent {
inheritedGroups: ItemGroup[] = []
}

View File

@ -0,0 +1,7 @@
import {ModelComponent} from "../ModelComponent";
import {ItemQuality} from "./ItemQuality";
export abstract class ItemGroup extends ModelComponent {
requiredItemQualities: ItemQuality[] = []
}

View File

@ -0,0 +1,10 @@
export class ItemQuality {
key: string
value: number
constructor(key: string, value: number) {
this.key = key;
this.value = value;
}
}