implemented feedback

This commit is contained in:
Johannes Berthel 2021-04-06 18:54:45 +02:00
parent 7c6b73efdb
commit e5a196a42b
9 changed files with 31 additions and 35 deletions

View file

@ -52,7 +52,13 @@ class LocalUserStore {
return localStorage.setItem(companionKey, JSON.stringify(companion));
}
getCompanion(): string|null {
return JSON.parse(localStorage.getItem(companionKey) || "null");
const companion = JSON.parse(localStorage.getItem(companionKey) || "null");
if (typeof companion !== "string" || companion === "") {
return null;
}
return companion;
}
wasCompanionSet(): boolean {
return localStorage.getItem(companionKey) ? true : false;

View file

@ -1,6 +1,6 @@
import Sprite = Phaser.GameObjects.Sprite;
import Container = Phaser.GameObjects.Container;
import { lazyLoadResource } from "./CompanionTexturesLoadingManager";
import { lazyLoadCompanionResource } from "./CompanionTexturesLoadingManager";
import { PlayerAnimationDirections, PlayerAnimationTypes } from "../Player/Animation";
export interface CompanionStatus {
@ -37,7 +37,7 @@ export class Companion extends Container {
this.companionName = name;
lazyLoadResource(this.scene.load, this.companionName)
lazyLoadCompanionResource(this.scene.load, this.companionName)
.then(resource => {
this.addResource(resource);
this.invisible = false;

View file

@ -1,23 +1,15 @@
import LoaderPlugin = Phaser.Loader.LoaderPlugin;
import { COMPANION_RESOURCES, CompanionResourceDescriptionInterface } from "./CompanionTextures";
export const getAllResources = (): CompanionResourceDescriptionInterface[] => {
export const getAllCompanionResources = (loader: LoaderPlugin): CompanionResourceDescriptionInterface[] => {
COMPANION_RESOURCES.forEach((resource: CompanionResourceDescriptionInterface) => {
lazyLoadCompanionResource(loader, resource.name);
});
return COMPANION_RESOURCES;
}
export const lazyLoadAllResources = (loader: LoaderPlugin): Promise<CompanionResourceDescriptionInterface[]> => {
const promises: Promise<string>[] = [];
COMPANION_RESOURCES.forEach((resource: CompanionResourceDescriptionInterface) => {
promises.push(lazyLoadResource(loader, resource.name));
});
return Promise.all(promises).then(() => {
return COMPANION_RESOURCES;
});
}
export const lazyLoadResource = (loader: LoaderPlugin, name: string): Promise<string> => {
export const lazyLoadCompanionResource = (loader: LoaderPlugin, name: string): Promise<string> => {
return new Promise((resolve, reject) => {
const resource = COMPANION_RESOURCES.find(item => item.name === name);

View file

@ -7,7 +7,7 @@ import { TextField } from "../Components/TextField";
import { EnableCameraSceneName } from "./EnableCameraScene";
import { localUserStore } from "../../Connexion/LocalUserStore";
import { CompanionResourceDescriptionInterface } from "../Companion/CompanionTextures";
import { getAllResources, lazyLoadAllResources } from "../Companion/CompanionTexturesLoadingManager";
import { getAllCompanionResources } from "../Companion/CompanionTexturesLoadingManager";
export const SelectCompanionSceneName = "SelectCompanionScene";
@ -38,11 +38,9 @@ export class SelectCompanionScene extends ResizableScene {
}
preload() {
lazyLoadAllResources(this.load).then(() => {
console.log("Loaded all companion textures.");
});
addLoader(this);
getAllResources().forEach(model => {
getAllCompanionResources(this.load).forEach(model => {
this.companionModels.push(model);
});