refactor-component-creation #47
@ -104,13 +104,13 @@ function createWindow(): BrowserWindow {
|
||||
{
|
||||
label: "Abstract Itemgroup",
|
||||
click: () => {
|
||||
win!.webContents.send('context-menu', "new-itemgroup_abstract")
|
||||
win!.webContents.send('context-menu', "new-itemgroup-abstract")
|
||||
}
|
||||
},
|
||||
{
|
||||
label: "Concrete Itemgroup",
|
||||
click: () => {
|
||||
win!.webContents.send('context-menu', "new-itemgroup_concrete")
|
||||
win!.webContents.send('context-menu', "new-itemgroup-concrete")
|
||||
}
|
||||
},
|
||||
{
|
||||
|
@ -25,11 +25,13 @@ import {CharacterOverviewComponent} from "./side-overviews/character-overview/ch
|
||||
import {CharacterSerializer} from "./project/serializer/CharacterSerializer";
|
||||
import {CharacterParser} from "./project/parser/characterParser/CharacterParser";
|
||||
import {TemplateType} from "./project/game-model/templates/TemplateType";
|
||||
import {TemplateTypeUtilities} from "./project/game-model/templates/TemplateTypeUtilities";
|
||||
import {SimpleTemplateGamesystem} from "./project/game-model/templates/simpleGamesystem/SimpleTemplateGamesystem";
|
||||
import {ItemSerializer} from "./project/serializer/ItemSerializer";
|
||||
import {ItemgroupParser} from "./project/parser/itemParser/ItemgroupParser";
|
||||
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";
|
||||
|
||||
@Component({
|
||||
selector: 'app-root',
|
||||
@ -44,6 +46,7 @@ export class AppComponent implements OnInit{
|
||||
@ViewChild('scriptAccountOverview') scriptAccountOverview: ScriptAccountOverviewComponent | undefined
|
||||
@ViewChild('gamesystemOverview') gamesystemOverview: GamescriptOverviewComponent | undefined
|
||||
@ViewChild('characterOverview') characterOverview: CharacterOverviewComponent | undefined
|
||||
@ViewChild('itemOverview') itemOverview: ItemOverviewComponent | undefined
|
||||
|
||||
gameModel: GameModel | undefined
|
||||
|
||||
@ -82,12 +85,34 @@ export class AppComponent implements OnInit{
|
||||
} else if(message.startsWith("new")) {
|
||||
const splittedMessage = message.split("-");
|
||||
const modelComponentType = ModelComponentTypeUtillities.fromString(splittedMessage[1]);
|
||||
const templateType = TemplateTypeUtilities.fromString(splittedMessage[2]);
|
||||
if(modelComponentType != undefined) {
|
||||
this.onCreateModelComponent(modelComponentType, templateType);
|
||||
} else {
|
||||
console.log("[ERROR] [App-Component] Unknown Context-Menu Command!")
|
||||
if(modelComponentType) {
|
||||
let creationContext = "";
|
||||
if(splittedMessage.length > 2) {
|
||||
creationContext = splittedMessage[2];
|
||||
}
|
||||
|
||||
let componentCreator;
|
||||
switch (modelComponentType) {
|
||||
case ModelComponentType.ITEMGROUP: {
|
||||
componentCreator = new ItemgroupCreator(creationContext, this.gameModel!, this.selectedModelComponent);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if(componentCreator) {
|
||||
const createdModel = componentCreator.createModelComponent();
|
||||
this.openModelComponent(createdModel!)
|
||||
|
||||
const openedOverview = this.openedOverview;
|
||||
if(openedOverview) {
|
||||
openedOverview.refresh()
|
||||
}
|
||||
|
||||
} else {
|
||||
console.log("[ERROR] Unknown Creation Command: ", message)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -303,6 +328,25 @@ export class AppComponent implements OnInit{
|
||||
}
|
||||
}
|
||||
|
||||
get selectedModelComponent(): ModelComponent | undefined {
|
||||
switch (this.openContent) {
|
||||
case ModelComponentType.GAMESYTEM: return this.gamesystemOverview!.getSelectedGamesystem();
|
||||
case ModelComponentType.CHARACTER: return this.characterOverview!.selectedCharacter;
|
||||
case ModelComponentType.SCRIPTACCOUNT: return this.scriptAccountOverview!.selectedScriptAccount;
|
||||
case ModelComponentType.ITEMGROUP: return this.itemOverview!.selectedModelComponent;
|
||||
case ModelComponentType.ITEM: return this.itemOverview!.selectedModelComponent;
|
||||
default: return undefined
|
||||
}
|
||||
}
|
||||
|
||||
get openedOverview(): Overview | undefined {
|
||||
if(this.openContent === ModelComponentType.ITEMGROUP || this.openContent === ModelComponentType.ITEM) {
|
||||
return this.itemOverview;
|
||||
} else {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected readonly open = open;
|
||||
}
|
||||
|
36
src/app/project/game-model/utils/creator/ItemgroupCreator.ts
Normal file
36
src/app/project/game-model/utils/creator/ItemgroupCreator.ts
Normal file
@ -0,0 +1,36 @@
|
||||
import {ModelComponentCreator} from "./ModelComponentCreator";
|
||||
import {ModelComponent} from "../../ModelComponent";
|
||||
import {GameModel} from "../../GameModel";
|
||||
import {AbstractItemGroup} from "../../inventory/AbstractItemGroup";
|
||||
import {ModelComponentType} from "../../ModelComponentType";
|
||||
import {ConcreteItemGroup} from "../../inventory/ConcreteItemGroup";
|
||||
|
||||
export class ItemgroupCreator extends ModelComponentCreator {
|
||||
|
||||
|
||||
|
||||
constructor(context: string, gameModel: GameModel, selectedComponent: ModelComponent | undefined) {
|
||||
super(context, gameModel, selectedComponent);
|
||||
}
|
||||
|
||||
createModelComponent(): ModelComponent | undefined{
|
||||
let itemgroup;
|
||||
if(this.context === 'abstract') {
|
||||
itemgroup = new AbstractItemGroup("New Abstract Itemgroup", "", ModelComponentType.ITEMGROUP);
|
||||
} else if(this.context === 'concrete') {
|
||||
itemgroup = new ConcreteItemGroup("New Concrete Itemgroup", "", ModelComponentType.ITEMGROUP);
|
||||
} else {
|
||||
return undefined
|
||||
}
|
||||
|
||||
if(this.selectedComponent != null && this.selectedComponent instanceof AbstractItemGroup) {
|
||||
this.selectedComponent.addChildItemgroup(itemgroup);
|
||||
} else {
|
||||
this.gameModel.itemgroups.push(itemgroup);
|
||||
}
|
||||
|
||||
return itemgroup;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
import {ModelComponent} from "../../ModelComponent";
|
||||
import {GameModel} from "../../GameModel";
|
||||
import {Overview} from "../../../../side-overviews/Overview";
|
||||
|
||||
export abstract class ModelComponentCreator {
|
||||
context: string;
|
||||
gameModel: GameModel
|
||||
selectedComponent: ModelComponent | undefined
|
||||
|
||||
|
||||
protected constructor(context: string, gameModel: GameModel, selectedComponent: ModelComponent | undefined) {
|
||||
this.context = context;
|
||||
this.gameModel = gameModel;
|
||||
this.selectedComponent = selectedComponent;
|
||||
}
|
||||
|
||||
abstract createModelComponent(): ModelComponent | undefined;
|
||||
}
|
3
src/app/side-overviews/Overview.ts
Normal file
3
src/app/side-overviews/Overview.ts
Normal file
@ -0,0 +1,3 @@
|
||||
export interface Overview {
|
||||
refresh(): void
|
||||
}
|
@ -8,6 +8,7 @@ import {ModelComponent} from "../../project/game-model/ModelComponent";
|
||||
import {ModelComponentType} from "../../project/game-model/ModelComponentType";
|
||||
import {ItemGroup} from "../../project/game-model/inventory/ItemGroup";
|
||||
import {Item} from "../../project/game-model/inventory/Item";
|
||||
import {Overview} from "../Overview";
|
||||
|
||||
interface FlatNode {
|
||||
expandable: boolean,
|
||||
@ -21,7 +22,7 @@ interface FlatNode {
|
||||
templateUrl: './item-overview.component.html',
|
||||
styleUrl: './item-overview.component.scss'
|
||||
})
|
||||
export class ItemOverviewComponent implements OnInit{
|
||||
export class ItemOverviewComponent implements OnInit, Overview{
|
||||
|
||||
@Input() gameModel: GameModel | undefined
|
||||
@Output() openItemgroupEmitter: EventEmitter<ItemGroup> = new EventEmitter();
|
||||
@ -120,4 +121,33 @@ export class ItemOverviewComponent implements OnInit{
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
get selectedModelComponent() {
|
||||
if(this.selectedItem) {
|
||||
if(this.selectedItem.type === ModelComponentType.ITEMGROUP) {
|
||||
let groupQueue: ItemGroup[] = this.gameModel!.itemgroups.concat();
|
||||
while(groupQueue.length > 0) {
|
||||
const currentGroup = groupQueue.shift()!;
|
||||
|
||||
if(currentGroup.componentName === this.selectedItem.name) {
|
||||
return currentGroup;
|
||||
}
|
||||
|
||||
if(currentGroup instanceof AbstractItemGroup) {
|
||||
groupQueue = groupQueue.concat(currentGroup.children);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return this.searchItemByName(this.selectedItem!.name)
|
||||
}
|
||||
} else {
|
||||
return undefined
|
||||
}
|
||||
}
|
||||
|
||||
refresh(): void {
|
||||
this.dataSource.data = this.gameModel!.itemgroups;
|
||||
console.log("Opened Refreshed")
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user