80
src/data/customWorldVisuals.ts
Normal file
80
src/data/customWorldVisuals.ts
Normal file
@@ -0,0 +1,80 @@
|
||||
import { WorldTemplateType, WorldType } from '../types';
|
||||
|
||||
const CUSTOM_WORLD_NPC_IMAGE_POOL = [
|
||||
'/character/Sword%20Princess/Original/Hero/idle/Idle01.png',
|
||||
'/character/Archer%20Hero/Original/Hero/idle/idle01.png',
|
||||
'/character/Girl%20Hero%201/Original/Hero/Idle/Idle01.png',
|
||||
'/character/Punch%20Hero%203/Original/Hero/Idle/Idle01.png',
|
||||
'/character/Fighter%204/original/Hero/idle/idle01.png',
|
||||
] as const;
|
||||
|
||||
const SCENE_BACKGROUND_PACKS = [
|
||||
{ packName: 'Pixel Battle Backgrounds - Pack 1', count: 121 },
|
||||
{ packName: 'Pixel Battle Backgrounds - Pack 2', count: 119 },
|
||||
{ packName: 'Pixel Battle Backgrounds - Pack 3', count: 170 },
|
||||
] as const;
|
||||
|
||||
function hashText(value: string) {
|
||||
let hash = 0;
|
||||
for (let index = 0; index < value.length; index += 1) {
|
||||
hash = (hash * 31 + value.charCodeAt(index)) >>> 0;
|
||||
}
|
||||
return hash >>> 0;
|
||||
}
|
||||
|
||||
function buildSceneImagePath(packName: string, imageNumber: number) {
|
||||
const filename = `${imageNumber.toString().padStart(3, '0')}.png`;
|
||||
return `/scene_bg/Pixel Battle Backgrounds Mega Pack/${packName}/${filename}`;
|
||||
}
|
||||
|
||||
export function getAllCustomWorldSceneImages() {
|
||||
const refs: string[] = [];
|
||||
|
||||
for (const pack of SCENE_BACKGROUND_PACKS) {
|
||||
for (let imageNumber = 1; imageNumber <= pack.count; imageNumber += 1) {
|
||||
refs.push(buildSceneImagePath(pack.packName, imageNumber));
|
||||
}
|
||||
}
|
||||
|
||||
return refs;
|
||||
}
|
||||
|
||||
function collectWorldSceneImagePool(worldType: WorldTemplateType) {
|
||||
const refs: string[] = [];
|
||||
let globalIndex = 0;
|
||||
|
||||
for (const pack of SCENE_BACKGROUND_PACKS) {
|
||||
for (let imageNumber = 1; imageNumber <= pack.count; imageNumber += 1) {
|
||||
const assignedWorld = globalIndex % 2 === 0 ? WorldType.WUXIA : WorldType.XIANXIA;
|
||||
if (assignedWorld === worldType) {
|
||||
refs.push(buildSceneImagePath(pack.packName, imageNumber));
|
||||
}
|
||||
globalIndex += 1;
|
||||
}
|
||||
}
|
||||
|
||||
return refs;
|
||||
}
|
||||
|
||||
export function normalizeOptionalImageSrc(value: unknown) {
|
||||
return typeof value === 'string' && value.trim() ? value.trim() : undefined;
|
||||
}
|
||||
|
||||
export function getDefaultCustomWorldNpcImage(seedKey: string, index: number) {
|
||||
const offset = hashText(`${seedKey}:npc:${index}`) % CUSTOM_WORLD_NPC_IMAGE_POOL.length;
|
||||
return CUSTOM_WORLD_NPC_IMAGE_POOL[offset];
|
||||
}
|
||||
|
||||
export function getDefaultCustomWorldSceneImage(
|
||||
seedKey: string,
|
||||
index: number,
|
||||
worldType: WorldTemplateType,
|
||||
) {
|
||||
const pool = collectWorldSceneImagePool(worldType);
|
||||
if (pool.length === 0) {
|
||||
return worldType === WorldType.WUXIA ? '/scene_bg/45_PixelSky.png' : '/scene_bg/47_PixelSky.png';
|
||||
}
|
||||
|
||||
const offset = hashText(`${seedKey}:scene:${index}`) % pool.length;
|
||||
return pool[offset];
|
||||
}
|
||||
Reference in New Issue
Block a user