inventory-items-2 #44

Closed
sebastian wants to merge 32 commits from inventory-items-2 into inventory
9 changed files with 23 additions and 8 deletions
Showing only changes of commit ddcbfc5bb3 - Show all commits

View File

@ -274,6 +274,7 @@ function recieveGameModelToStore(gameModel: StoredGameModel) {
const itemgroupStorage = new ItemgroupStorage(path.join(projectDirectory, ModelComponentFileDirectory.ITEMGROUP_DIR_NAME))
itemgroupStorage.storeItemgroups(gameModel.storedItemgroups);
itemgroupStorage.storeItems(gameModel.storedItems)
}
/*function deleteComponent(component: DeleteModel) {

View File

@ -2,12 +2,13 @@
Object.defineProperty(exports, "__esModule", { value: true });
exports.StoredGameModel = void 0;
class StoredGameModel {
constructor(gameModelName, storedScriptAccounts, storedGamesystems, storedCharacters, storedItemgroups) {
constructor(gameModelName, storedScriptAccounts, storedGamesystems, storedCharacters, storedItemgroups, storedItems) {
this.gameModelName = gameModelName;
this.storedGamesystems = storedGamesystems;
this.storedScriptAccounts = storedScriptAccounts;
this.storedCharacters = storedCharacters;
this.storedItemgroups = storedItemgroups;
this.storedItems = storedItems;
}
}
exports.StoredGameModel = StoredGameModel;

View File

@ -7,14 +7,16 @@ export class StoredGameModel {
storedScriptAccounts: StoreComponent[]
storedCharacters: StoreComponent[]
storedItemgroups: StoreComponent[]
storedItems: StoreComponent[]
constructor(gameModelName: string, storedScriptAccounts: StoreComponent[], storedGamesystems: StoreComponent[],
storedCharacters: StoreComponent[], storedItemgroups: StoreComponent[]) {
storedCharacters: StoreComponent[], storedItemgroups: StoreComponent[], storedItems: StoreComponent[]) {
this.gameModelName = gameModelName;
this.storedGamesystems = storedGamesystems;
this.storedScriptAccounts = storedScriptAccounts;
this.storedCharacters = storedCharacters;
this.storedItemgroups = storedItemgroups;
this.storedItems = storedItems;
}
}

View File

@ -16,7 +16,7 @@ class GameModelLoader {
const storedScriptAccounts = this.loadScriptAccountComponents();
const storedGamesystems = this.loadGamesystems();
const storedCharacters = this.loadCharacters();
return new StoredGameModel_1.StoredGameModel(gameModelName, storedScriptAccounts, storedGamesystems, storedCharacters, []);
return new StoredGameModel_1.StoredGameModel(gameModelName, storedScriptAccounts, storedGamesystems, storedCharacters, [], []);
}
loadScriptAccountComponents() {
const scriptAccountDir = path.join(this.gameModelDir, ModelComponentFileDirectory_1.ModelComponentFileDirectory.SCRIPTACCOUNT_DIR_NAME);

View File

@ -22,7 +22,7 @@ export class GameModelLoader {
const storedGamesystems = this.loadGamesystems();
const storedCharacters = this.loadCharacters()
return new StoredGameModel(gameModelName, storedScriptAccounts, storedGamesystems, storedCharacters, []);
return new StoredGameModel(gameModelName, storedScriptAccounts, storedGamesystems, storedCharacters, [], []);
}
private loadScriptAccountComponents() {

View File

@ -10,7 +10,6 @@ class ItemgroupStorage {
FileUtils_1.FileUtils.prepareDirectoryFroWriting(this.itemgroupDir);
}
storeItemgroups(itemgroups) {
console.log("Store Itemgroups");
itemgroups.forEach(itemgroup => {
this.storeItemgroup(itemgroup);
});
@ -24,6 +23,9 @@ class ItemgroupStorage {
FileUtils_1.FileUtils.prepareDirectoryFroWriting(completeItemgroupDirectory);
fs.writeFileSync(completeFileName + ".json", itemgroup.jsonString, "utf-8");
}
storeItems(storedItems) {
storedItems.forEach(item => this.storeItemgroup(item));
}
}
exports.ItemgroupStorage = ItemgroupStorage;
//# sourceMappingURL=ItemgroupStorage.js.map

View File

@ -13,7 +13,6 @@ export class ItemgroupStorage {
}
public storeItemgroups(itemgroups: StoreComponent[]) {
console.log("Store Itemgroups")
itemgroups.forEach(itemgroup => {
this.storeItemgroup(itemgroup)
})
@ -31,4 +30,7 @@ export class ItemgroupStorage {
}
storeItems(storedItems: StoreComponent[]) {
storedItems.forEach(item => this.storeItemgroup(item))
}
}

View File

@ -235,7 +235,9 @@ export class AppComponent implements OnInit{
const itemSerializer = new ItemSerializer();
const storedItemgroups: StoreComponent[] = itemSerializer.serializeItemgroups(this.gameModel!.itemgroups);
const storeModel = new StoredGameModel(this.gameModel.gameModelName, storedScriptAccounts, storedGamesystems, storedCharacters, storedItemgroups)
const storedItems: StoreComponent[] = itemSerializer.getSerializedItems()
const storeModel = new StoredGameModel(this.gameModel.gameModelName, storedScriptAccounts, storedGamesystems, storedCharacters, storedItemgroups, storedItems)
if(this.electronService.isElectron) {
this.electronService.ipcRenderer.send('save-model', storeModel)

View File

@ -9,6 +9,7 @@ import {Item} from "../game-model/inventory/Item";
export class ItemSerializer {
private serializedItemgroups: StoreComponent[] = []
private serializedItems: StoreComponent[] = []
private static ignoredGroupKeys: string[] = ['type', 'unsaved', 'children', "itemgroup", "manuallyInheritedGroups", "hierarchyInheritedGroups", "items"]
private static ignoredItemKeys: string[] = ['type', 'unsaved', 'hierarchyInheritedGroups']
@ -73,7 +74,7 @@ export class ItemSerializer {
const fileName = ItemSerializer.computeItemgroupPath(itemgroup, true);
itemgroup.items.forEach(item => {
const storeComponent = this.serializeSingleItem(fileName, item);
this.serializedItemgroups.push(storeComponent)
this.serializedItems.push(storeComponent)
})
@ -100,4 +101,8 @@ export class ItemSerializer {
return new StoreComponent(jsonString, itemFile, ModelComponentType.ITEM)
}
getSerializedItems() {
return this.serializedItems;
}
}