refactor-component-creation #47

Merged
sebastian merged 9 commits from refactor-component-creation into main 2024-05-11 08:40:09 +02:00
6 changed files with 140 additions and 9 deletions
Showing only changes of commit c413c45741 - Show all commits

View File

@ -104,13 +104,13 @@ function createWindow(): BrowserWindow {
{ {
label: "Abstract Itemgroup", label: "Abstract Itemgroup",
click: () => { click: () => {
win!.webContents.send('context-menu', "new-itemgroup_abstract") win!.webContents.send('context-menu', "new-itemgroup-abstract")
} }
}, },
{ {
label: "Concrete Itemgroup", label: "Concrete Itemgroup",
click: () => { click: () => {
win!.webContents.send('context-menu', "new-itemgroup_concrete") win!.webContents.send('context-menu', "new-itemgroup-concrete")
} }
}, },
{ {

View File

@ -25,11 +25,13 @@ import {CharacterOverviewComponent} from "./side-overviews/character-overview/ch
import {CharacterSerializer} from "./project/serializer/CharacterSerializer"; import {CharacterSerializer} from "./project/serializer/CharacterSerializer";
import {CharacterParser} from "./project/parser/characterParser/CharacterParser"; import {CharacterParser} from "./project/parser/characterParser/CharacterParser";
import {TemplateType} from "./project/game-model/templates/TemplateType"; 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 {SimpleTemplateGamesystem} from "./project/game-model/templates/simpleGamesystem/SimpleTemplateGamesystem";
import {ItemSerializer} from "./project/serializer/ItemSerializer"; import {ItemSerializer} from "./project/serializer/ItemSerializer";
import {ItemgroupParser} from "./project/parser/itemParser/ItemgroupParser"; import {ItemgroupParser} from "./project/parser/itemParser/ItemgroupParser";
import {ItemParser} from "./project/parser/itemParser/ItemParser"; 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({ @Component({
selector: 'app-root', selector: 'app-root',
@ -44,6 +46,7 @@ export class AppComponent implements OnInit{
@ViewChild('scriptAccountOverview') scriptAccountOverview: ScriptAccountOverviewComponent | undefined @ViewChild('scriptAccountOverview') scriptAccountOverview: ScriptAccountOverviewComponent | undefined
@ViewChild('gamesystemOverview') gamesystemOverview: GamescriptOverviewComponent | undefined @ViewChild('gamesystemOverview') gamesystemOverview: GamescriptOverviewComponent | undefined
@ViewChild('characterOverview') characterOverview: CharacterOverviewComponent | undefined @ViewChild('characterOverview') characterOverview: CharacterOverviewComponent | undefined
@ViewChild('itemOverview') itemOverview: ItemOverviewComponent | undefined
gameModel: GameModel | undefined gameModel: GameModel | undefined
@ -82,12 +85,34 @@ export class AppComponent implements OnInit{
} else if(message.startsWith("new")) { } else if(message.startsWith("new")) {
const splittedMessage = message.split("-"); const splittedMessage = message.split("-");
const modelComponentType = ModelComponentTypeUtillities.fromString(splittedMessage[1]); const modelComponentType = ModelComponentTypeUtillities.fromString(splittedMessage[1]);
const templateType = TemplateTypeUtilities.fromString(splittedMessage[2]); if(modelComponentType) {
if(modelComponentType != undefined) { let creationContext = "";
this.onCreateModelComponent(modelComponentType, templateType); if(splittedMessage.length > 2) {
} else { creationContext = splittedMessage[2];
console.log("[ERROR] [App-Component] Unknown Context-Menu Command!") }
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; protected readonly open = open;
} }

View 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;
}
}

View File

@ -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;
}

View File

@ -0,0 +1,3 @@
export interface Overview {
refresh(): void
}

View File

@ -8,6 +8,7 @@ import {ModelComponent} from "../../project/game-model/ModelComponent";
import {ModelComponentType} from "../../project/game-model/ModelComponentType"; import {ModelComponentType} from "../../project/game-model/ModelComponentType";
import {ItemGroup} from "../../project/game-model/inventory/ItemGroup"; import {ItemGroup} from "../../project/game-model/inventory/ItemGroup";
import {Item} from "../../project/game-model/inventory/Item"; import {Item} from "../../project/game-model/inventory/Item";
import {Overview} from "../Overview";
interface FlatNode { interface FlatNode {
expandable: boolean, expandable: boolean,
@ -21,7 +22,7 @@ interface FlatNode {
templateUrl: './item-overview.component.html', templateUrl: './item-overview.component.html',
styleUrl: './item-overview.component.scss' styleUrl: './item-overview.component.scss'
}) })
export class ItemOverviewComponent implements OnInit{ export class ItemOverviewComponent implements OnInit, Overview{
@Input() gameModel: GameModel | undefined @Input() gameModel: GameModel | undefined
@Output() openItemgroupEmitter: EventEmitter<ItemGroup> = new EventEmitter(); @Output() openItemgroupEmitter: EventEmitter<ItemGroup> = new EventEmitter();
@ -120,4 +121,33 @@ export class ItemOverviewComponent implements OnInit{
} }
return undefined; 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")
}
} }