Files
partey_workadventure/pusher/src/Services/LocalWokaService.ts
T
Alexis Faizeau d1e8243c47 Zod EVERYWHERE (#2027)
* Zod EVERYWHERE

* Add no-unused-vars rule to eslint in front

* Add no-unused-vars rule to eslint in pusher

* Add no-unused-vars rule to eslint in back

* Remove unused PlayerTexture guards

* Fix data providing on room connection

Co-authored-by: Alexis Faizeau <a.faizeau@workadventu.re>
2022-04-12 14:21:19 +02:00

76 lines
2.3 KiB
TypeScript

import { WokaDetail, WokaList, wokaPartNames } from "../Messages/JsonMessages/PlayerTextures";
import { WokaServiceInterface } from "./WokaServiceInterface";
class LocalWokaService implements WokaServiceInterface {
/**
* Returns the list of all available Wokas & Woka Parts for the current user.
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars
async getWokaList(roomId: string, token: string): Promise<WokaList | undefined> {
const wokaData: WokaList = await require("../../data/woka.json");
if (!wokaData) {
return undefined;
}
return wokaData;
}
/**
* Returns the URL of all the images for the given texture ids.
*
* Key: texture id
* Value: URL
*
* If one of the textures cannot be found, undefined is returned (and the user should be redirected to Woka choice page!)
*/
async fetchWokaDetails(textureIds: string[]): Promise<WokaDetail[] | undefined> {
const wokaData: WokaList = await require("../../data/woka.json");
const textures = new Map<
string,
{
url: string;
layer: string;
}
>();
const searchIds = new Set(textureIds);
for (const part of wokaPartNames) {
const wokaPartType = wokaData[part];
if (!wokaPartType) {
continue;
}
for (const collection of wokaPartType.collections) {
for (const id of searchIds) {
const texture = collection.textures.find((texture) => texture.id === id);
if (texture) {
textures.set(id, {
url: texture.url,
layer: part,
});
searchIds.delete(id);
}
}
}
}
if (textureIds.length !== textures.size) {
return undefined;
}
const details: WokaDetail[] = [];
textures.forEach((value, key) => {
details.push({
id: key,
url: value.url,
layer: value.layer,
});
});
return details;
}
}
export const localWokaService = new LocalWokaService();