main #48
@ -32,6 +32,7 @@ import {ItemParser} from "./project/parser/itemParser/ItemParser";
 | 
			
		||||
import {ItemgroupCreator} from "./project/game-model/utils/creator/ItemgroupCreator";
 | 
			
		||||
import {ItemOverviewComponent} from "./side-overviews/item-overview/item-overview.component";
 | 
			
		||||
import {Overview} from "./side-overviews/Overview";
 | 
			
		||||
import {ItemCreator} from "./project/game-model/utils/creator/ItemCreator";
 | 
			
		||||
 | 
			
		||||
@Component({
 | 
			
		||||
  selector: 'app-root',
 | 
			
		||||
@ -95,12 +96,15 @@ export class AppComponent implements OnInit{
 | 
			
		||||
        switch (modelComponentType) {
 | 
			
		||||
          case ModelComponentType.ITEMGROUP: {
 | 
			
		||||
            componentCreator = new ItemgroupCreator(creationContext, this.gameModel!, this.selectedModelComponent);
 | 
			
		||||
 | 
			
		||||
          }
 | 
			
		||||
          } break
 | 
			
		||||
          case ModelComponentType.ITEM: {
 | 
			
		||||
            componentCreator = new ItemCreator(creationContext, this.gameModel!, this.selectedModelComponent);
 | 
			
		||||
          } break
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if(componentCreator) {
 | 
			
		||||
          const createdModel = componentCreator.createModelComponent();
 | 
			
		||||
          console.log(createdModel)
 | 
			
		||||
          this.openModelComponent(createdModel!)
 | 
			
		||||
 | 
			
		||||
          const openedOverview = this.openedOverview;
 | 
			
		||||
 | 
			
		||||
@ -30,47 +30,6 @@ export class GameModel {
 | 
			
		||||
    this.gameModelName = gameModelName;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  addAbstractItemgroup(groupName: string, parentgroup: AbstractItemGroup | undefined) {
 | 
			
		||||
    //Ensure that Itemgroup does not exist
 | 
			
		||||
    if(parentgroup == undefined) {
 | 
			
		||||
      if(GameModel.findItemgroupByName(groupName, this.itemgroups) == undefined) {
 | 
			
		||||
        const itemgroup = new AbstractItemGroup(groupName, "", ModelComponentType.ITEMGROUP)
 | 
			
		||||
        this.itemgroups.push(itemgroup);
 | 
			
		||||
        itemgroup.addItemgroupCharacteristic(new ItemGroupCharacteristic("Test0", "", itemgroup));
 | 
			
		||||
      }
 | 
			
		||||
    } else {
 | 
			
		||||
      if(GameModel.findItemgroupByName(groupName, parentgroup.children) == undefined) {
 | 
			
		||||
        parentgroup.addChildItemgroup(new AbstractItemGroup(groupName, "", ModelComponentType.ITEMGROUP));
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  addConcreteItemgroup(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 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) {
 | 
			
		||||
      const itemgroups: ItemGroup[] = ItemgroupUtilities.findItemgroupPathToItemgroup(conceteItemgroupName, this.itemgroups);
 | 
			
		||||
 | 
			
		||||
      if(itemgroups.length > 0) {
 | 
			
		||||
        const item = new Item(itemName, "", ModelComponentType.ITEM )
 | 
			
		||||
        itemgroup.addItem(item, itemgroups)
 | 
			
		||||
        return item;
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
  public static findItemgroupByName(name: string, itemgroups: ItemGroup[]) {
 | 
			
		||||
    const itemgroupQueue: ItemGroup[] = itemgroups.concat();
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										38
									
								
								src/app/project/game-model/utils/creator/ItemCreator.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										38
									
								
								src/app/project/game-model/utils/creator/ItemCreator.ts
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,38 @@
 | 
			
		||||
import {ModelComponentCreator} from "./ModelComponentCreator";
 | 
			
		||||
import {GameModel} from "../../GameModel";
 | 
			
		||||
import {ModelComponent} from "../../ModelComponent";
 | 
			
		||||
import {Item} from "../../inventory/Item";
 | 
			
		||||
import {ModelComponentType} from "../../ModelComponentType";
 | 
			
		||||
import {ConcreteItemGroup} from "../../inventory/ConcreteItemGroup";
 | 
			
		||||
import {ItemGroup} from "../../inventory/ItemGroup";
 | 
			
		||||
 | 
			
		||||
export class ItemCreator extends ModelComponentCreator {
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
  constructor(context: string, gameModel: GameModel, selectedComponent: ModelComponent | undefined) {
 | 
			
		||||
    super(context, gameModel, selectedComponent);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  createModelComponent(): ModelComponent | undefined {
 | 
			
		||||
    if(this.selectedComponent != undefined && this.selectedComponent instanceof ConcreteItemGroup) {
 | 
			
		||||
      const item =  new Item("New Item", "", ModelComponentType.ITEM);
 | 
			
		||||
      this.selectedComponent.addItem(item, this.getInheritedGroups(this.selectedComponent))
 | 
			
		||||
      return item;
 | 
			
		||||
    } else {
 | 
			
		||||
      console.log(this.selectedComponent)
 | 
			
		||||
      return undefined
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private getInheritedGroups(baseGroup: ItemGroup): ItemGroup[] {
 | 
			
		||||
    const itemgroups: ItemGroup[] = []
 | 
			
		||||
    let currentGroup: ItemGroup | undefined = baseGroup;
 | 
			
		||||
    while(currentGroup != undefined) {
 | 
			
		||||
      itemgroups.push(currentGroup);
 | 
			
		||||
      currentGroup = currentGroup.parentGroup;
 | 
			
		||||
    }
 | 
			
		||||
    return itemgroups;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@ -7,5 +7,5 @@
 | 
			
		||||
            "characteristicDescription": ""
 | 
			
		||||
        }
 | 
			
		||||
    ],
 | 
			
		||||
    "itemgroupType": 1
 | 
			
		||||
    "itemgroupType": 0
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user