playerTextures metadata is being loaded via Phaser.Loader
This commit is contained in:
parent
52e15eccfa
commit
063de6d1ca
@ -1,5 +1,7 @@
|
|||||||
//The list of all the player textures, both the default models and the partial textures used for customization
|
//The list of all the player textures, both the default models and the partial textures used for customization
|
||||||
|
|
||||||
|
import { PUSHER_URL } from "../../Enum/EnvironmentVariable";
|
||||||
|
|
||||||
export interface BodyResourceDescriptionListInterface {
|
export interface BodyResourceDescriptionListInterface {
|
||||||
[key: string]: BodyResourceDescriptionInterface;
|
[key: string]: BodyResourceDescriptionInterface;
|
||||||
}
|
}
|
||||||
@ -49,46 +51,30 @@ export class PlayerTextures {
|
|||||||
public static ACCESSORIES_RESOURCES: BodyResourceDescriptionListInterface;
|
public static ACCESSORIES_RESOURCES: BodyResourceDescriptionListInterface;
|
||||||
public static LAYERS: BodyResourceDescriptionListInterface[];
|
public static LAYERS: BodyResourceDescriptionListInterface[];
|
||||||
|
|
||||||
public static loadPlayerTexturesMetadata(url: string): Promise<boolean> {
|
public loadPlayerTexturesMetadata(metadata: PlayerTexturesMetadata): void {
|
||||||
return new Promise<boolean>((resolve, reject) => {
|
this.mapTexturesMetadataIntoResources(metadata);
|
||||||
fetch(url, {
|
|
||||||
method: "GET",
|
|
||||||
// mode: 'no-cors',
|
|
||||||
headers: {
|
|
||||||
Host: "pusher.workadventure.localhost",
|
|
||||||
},
|
|
||||||
})
|
|
||||||
.then((response) => response.json())
|
|
||||||
.then((data: PlayerTexturesMetadata) => {
|
|
||||||
this.mapTexturesMetadataIntoResources(data);
|
|
||||||
resolve(true);
|
|
||||||
})
|
|
||||||
.catch((reason) => {
|
|
||||||
reject(reason);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static mapTexturesMetadataIntoResources(metadata: PlayerTexturesMetadata): void {
|
private mapTexturesMetadataIntoResources(metadata: PlayerTexturesMetadata): void {
|
||||||
this.PLAYER_RESOURCES = this.getMappedResources(metadata.woka);
|
PlayerTextures.PLAYER_RESOURCES = this.getMappedResources(metadata.woka);
|
||||||
this.COLOR_RESOURCES = this.getMappedResources(metadata.body);
|
PlayerTextures.COLOR_RESOURCES = this.getMappedResources(metadata.body);
|
||||||
this.EYES_RESOURCES = this.getMappedResources(metadata.eyes);
|
PlayerTextures.EYES_RESOURCES = this.getMappedResources(metadata.eyes);
|
||||||
this.HAIR_RESOURCES = this.getMappedResources(metadata.hair);
|
PlayerTextures.HAIR_RESOURCES = this.getMappedResources(metadata.hair);
|
||||||
this.CLOTHES_RESOURCES = this.getMappedResources(metadata.clothes);
|
PlayerTextures.CLOTHES_RESOURCES = this.getMappedResources(metadata.clothes);
|
||||||
this.HATS_RESOURCES = this.getMappedResources(metadata.hat);
|
PlayerTextures.HATS_RESOURCES = this.getMappedResources(metadata.hat);
|
||||||
this.ACCESSORIES_RESOURCES = this.getMappedResources(metadata.accessory);
|
PlayerTextures.ACCESSORIES_RESOURCES = this.getMappedResources(metadata.accessory);
|
||||||
|
|
||||||
this.LAYERS = [
|
PlayerTextures.LAYERS = [
|
||||||
this.COLOR_RESOURCES,
|
PlayerTextures.COLOR_RESOURCES,
|
||||||
this.EYES_RESOURCES,
|
PlayerTextures.EYES_RESOURCES,
|
||||||
this.HAIR_RESOURCES,
|
PlayerTextures.HAIR_RESOURCES,
|
||||||
this.CLOTHES_RESOURCES,
|
PlayerTextures.CLOTHES_RESOURCES,
|
||||||
this.HATS_RESOURCES,
|
PlayerTextures.HATS_RESOURCES,
|
||||||
this.ACCESSORIES_RESOURCES,
|
PlayerTextures.ACCESSORIES_RESOURCES,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
private static getMappedResources(category: PlayerTexturesCategory): BodyResourceDescriptionListInterface {
|
private getMappedResources(category: PlayerTexturesCategory): BodyResourceDescriptionListInterface {
|
||||||
const resources: BodyResourceDescriptionListInterface = {};
|
const resources: BodyResourceDescriptionListInterface = {};
|
||||||
for (const collection of category.collections) {
|
for (const collection of category.collections) {
|
||||||
for (const texture of collection.textures) {
|
for (const texture of collection.textures) {
|
||||||
|
@ -8,6 +8,7 @@ import LL from "../../i18n/i18n-svelte";
|
|||||||
import { get } from "svelte/store";
|
import { get } from "svelte/store";
|
||||||
import { localeDetector } from "../../i18n/locales";
|
import { localeDetector } from "../../i18n/locales";
|
||||||
import { PlayerTextures } from "../Entity/PlayerTextures";
|
import { PlayerTextures } from "../Entity/PlayerTextures";
|
||||||
|
import { PUSHER_URL } from "../../Enum/EnvironmentVariable";
|
||||||
|
|
||||||
export const EntrySceneName = "EntryScene";
|
export const EntrySceneName = "EntryScene";
|
||||||
|
|
||||||
@ -16,7 +17,6 @@ export const EntrySceneName = "EntryScene";
|
|||||||
* and to route to the next correct scene.
|
* and to route to the next correct scene.
|
||||||
*/
|
*/
|
||||||
export class EntryScene extends Scene {
|
export class EntryScene extends Scene {
|
||||||
private texturesMetadataLoaded: boolean = false;
|
|
||||||
private localeLoaded: boolean = false;
|
private localeLoaded: boolean = false;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
@ -31,21 +31,10 @@ export class EntryScene extends Scene {
|
|||||||
// Note: arcade.png from the Phaser 3 examples at: https://github.com/photonstorm/phaser3-examples/tree/master/public/assets/fonts/bitmap
|
// Note: arcade.png from the Phaser 3 examples at: https://github.com/photonstorm/phaser3-examples/tree/master/public/assets/fonts/bitmap
|
||||||
this.load.bitmapFont(ReconnectingTextures.mainFont, "resources/fonts/arcade.png", "resources/fonts/arcade.xml");
|
this.load.bitmapFont(ReconnectingTextures.mainFont, "resources/fonts/arcade.png", "resources/fonts/arcade.xml");
|
||||||
this.load.spritesheet("cat", "resources/characters/pipoya/Cat 01-1.png", { frameWidth: 32, frameHeight: 32 });
|
this.load.spritesheet("cat", "resources/characters/pipoya/Cat 01-1.png", { frameWidth: 32, frameHeight: 32 });
|
||||||
|
|
||||||
void PlayerTextures.loadPlayerTexturesMetadata("http://pusher.workadventure.localhost/woka-list").then(
|
|
||||||
(success) => {
|
|
||||||
this.texturesMetadataLoaded = success;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
create() {}
|
create() {
|
||||||
|
this.loadLocale();
|
||||||
public update(): void {
|
|
||||||
if (this.texturesMetadataLoaded && !this.localeLoaded) {
|
|
||||||
this.localeLoaded = true;
|
|
||||||
this.loadLocale();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private loadLocale(): void {
|
private loadLocale(): void {
|
||||||
|
@ -5,7 +5,7 @@ import { CustomizeSceneName } from "./CustomizeScene";
|
|||||||
import { localUserStore } from "../../Connexion/LocalUserStore";
|
import { localUserStore } from "../../Connexion/LocalUserStore";
|
||||||
import { loadAllDefaultModels } from "../Entity/PlayerTexturesLoadingManager";
|
import { loadAllDefaultModels } from "../Entity/PlayerTexturesLoadingManager";
|
||||||
import { Loader } from "../Components/Loader";
|
import { Loader } from "../Components/Loader";
|
||||||
import type { BodyResourceDescriptionInterface } from "../Entity/PlayerTextures";
|
import { BodyResourceDescriptionInterface, PlayerTextures } from "../Entity/PlayerTextures";
|
||||||
import { AbstractCharacterScene } from "./AbstractCharacterScene";
|
import { AbstractCharacterScene } from "./AbstractCharacterScene";
|
||||||
import { areCharacterLayersValid } from "../../Connexion/LocalUser";
|
import { areCharacterLayersValid } from "../../Connexion/LocalUser";
|
||||||
import { touchScreenManager } from "../../Touch/TouchScreenManager";
|
import { touchScreenManager } from "../../Touch/TouchScreenManager";
|
||||||
@ -14,6 +14,7 @@ import { selectCharacterSceneVisibleStore } from "../../Stores/SelectCharacterSt
|
|||||||
import { waScaleManager } from "../Services/WaScaleManager";
|
import { waScaleManager } from "../Services/WaScaleManager";
|
||||||
import { analyticsClient } from "../../Administration/AnalyticsClient";
|
import { analyticsClient } from "../../Administration/AnalyticsClient";
|
||||||
import { isMediaBreakpointUp } from "../../Utils/BreakpointsUtils";
|
import { isMediaBreakpointUp } from "../../Utils/BreakpointsUtils";
|
||||||
|
import { PUSHER_URL } from "../../Enum/EnvironmentVariable";
|
||||||
|
|
||||||
//todo: put this constants in a dedicated file
|
//todo: put this constants in a dedicated file
|
||||||
export const SelectCharacterSceneName = "SelectCharacterScene";
|
export const SelectCharacterSceneName = "SelectCharacterScene";
|
||||||
@ -32,28 +33,34 @@ export class SelectCharacterScene extends AbstractCharacterScene {
|
|||||||
|
|
||||||
protected lazyloadingAttempt = true; //permit to update texture loaded after renderer
|
protected lazyloadingAttempt = true; //permit to update texture loaded after renderer
|
||||||
private loader: Loader;
|
private loader: Loader;
|
||||||
|
private playerTextures: PlayerTextures;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super({
|
super({
|
||||||
key: SelectCharacterSceneName,
|
key: SelectCharacterSceneName,
|
||||||
});
|
});
|
||||||
this.loader = new Loader(this);
|
this.loader = new Loader(this);
|
||||||
|
this.playerTextures = new PlayerTextures();
|
||||||
}
|
}
|
||||||
|
|
||||||
preload() {
|
preload() {
|
||||||
this.loadSelectSceneCharacters()
|
this.load.json("woka-list", `${PUSHER_URL}/woka-list`);
|
||||||
.then((bodyResourceDescriptions) => {
|
this.load.on("filecomplete-json-woka-list", () => {
|
||||||
bodyResourceDescriptions.forEach((bodyResourceDescription) => {
|
this.playerTextures.loadPlayerTexturesMetadata(this.cache.json.get("woka-list"));
|
||||||
this.playerModels.push(bodyResourceDescription);
|
this.loadSelectSceneCharacters()
|
||||||
});
|
.then((bodyResourceDescriptions) => {
|
||||||
this.lazyloadingAttempt = true;
|
bodyResourceDescriptions.forEach((bodyResourceDescription) => {
|
||||||
})
|
this.playerModels.push(bodyResourceDescription);
|
||||||
.catch((e) => console.error(e));
|
});
|
||||||
this.playerModels = loadAllDefaultModels(this.load);
|
this.lazyloadingAttempt = true;
|
||||||
this.lazyloadingAttempt = false;
|
})
|
||||||
|
.catch((e) => console.error(e));
|
||||||
|
this.playerModels = loadAllDefaultModels(this.load);
|
||||||
|
this.lazyloadingAttempt = false;
|
||||||
|
|
||||||
//this function must stay at the end of preload function
|
//this function must stay at the end of preload function
|
||||||
this.loader.addLoader();
|
this.loader.addLoader();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
create() {
|
create() {
|
||||||
|
Loading…
Reference in New Issue
Block a user