Skip to content

Commit a8787e9

Browse files
committed
Fixed entity rendering
1 parent bef83f8 commit a8787e9

File tree

2 files changed

+263
-231
lines changed

2 files changed

+263
-231
lines changed

src/Map.js

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
MAGICAL_ZONE_LAYER_ID,
77
getSelectedLayer
88
} from './js/ui/LayersPalette';
9-
9+
import { v4 as uuidv4 } from 'uuid';
1010
import { ShaderProgram } from './ShaderProgram.js';
1111
import { updateRstringInfo, updateInfoDims, updateLocationText, updateZoomText } from './Tools.js';
1212
import { getZoneVisibility, getZoneAlpha } from './js/ui/ZonesPalette';
@@ -572,6 +572,22 @@ export function Map(mapfile, mapdatafile, updateLocationFunction) {
572572
}
573573

574574
this.toLoad++;
575+
this.entityTexturesKeynameInEntityData = 'MAPED_ENTITYTEXTURE_KEY';
576+
577+
// sets entityData, returns the key for the corresponding this.entityTexture
578+
this.setEntityDataEntry = function(key, data) {
579+
// entityData's filename-based key SHOULD be fine for now.
580+
// TODO: make this not based on filename
581+
this.entityData[key] = data;
582+
583+
let uuid = this.entityData[key][this.entityTexturesKeynameInEntityData];
584+
if (!uuid) {
585+
uuid = uuidv4();
586+
this.entityData[key][this.entityTexturesKeynameInEntityData] = uuid;
587+
}
588+
return uuid;
589+
};
590+
575591
this.entityTextures = {
576592
__default__: { img: new window.Image() }
577593
};
@@ -966,7 +982,7 @@ Map.prototype = {
966982
throw Error(msg);
967983
}
968984

969-
this.entityData[filename] = data;
985+
const textureKey = this.setEntityDataEntry(filename, data);
970986

971987
for (const name in data.animations) {
972988
// convert short-hand to useful-hand
@@ -983,8 +999,8 @@ Map.prototype = {
983999

9841000
/// TODO: for gods sake put this all under test dammit
9851001
/// TODO: this is a bad scheme for storing entity textures. If there's the same filename but different paths, there'll be a colission. Change to full normalized path maybe?
986-
LOG(`this.entityTextures[${data.image}] ${this.entityTextures[data.image]}`);
987-
if (!this.entityTextures[data.image]) {
1002+
LOG(`this.entityTextures[${textureKey}] ${this.entityTextures[textureKey]}`);
1003+
if (!this.entityTextures[textureKey]) {
9881004
// TODO maybe make this definable in this.mapedConfigData too?
9891005
let imagePath = imageFilename;
9901006

@@ -1005,20 +1021,22 @@ Map.prototype = {
10051021

10061022
INFO(`Adding '${imagePath}' to entityTextures cache...`);
10071023
this.toLoad++;
1008-
this.entityTextures[data.image] = {};
1009-
this.entityTextures[data.image].img = new window.Image();
1024+
this.entityTextures[textureKey] = {};
1025+
this.entityTextures[textureKey].img = new window.Image();
10101026
const fn = this.doneLoading;
1011-
this.entityTextures[data.image].img.onload = function() {
1027+
this.entityTextures[textureKey].img.onload = function() {
10121028
fn(data.image);
10131029
};
1014-
this.entityTextures[data.image].img.src = imagePath;
1030+
this.entityTextures[textureKey].img.src = imagePath;
10151031
}
10161032

10171033
if (entity) {
10181034
entity.MAPED_USEDEFAULT = false;
10191035
}
10201036
LOG('NOT USING DEFAULT ENTITY FOR ', data.image);
10211037
} catch (e) {
1038+
alert(e);
1039+
10221040
debugger;
10231041
}
10241042
},
@@ -2170,7 +2188,9 @@ Map.prototype = {
21702188
}
21712189

21722190
const entityData = this._getEntityData(entity);
2173-
const entityTexture = this.entityTextures[entityData.image]; // || this.entityTextures["__default__"];
2191+
const entityTexture = this.entityTextures[
2192+
entityData[this.entityTexturesKeynameInEntityData]
2193+
]; // || this.entityTextures["__default__"];
21742194
if (!entityTexture) {
21752195
alert(
21762196
`Entity '${entity.name}' at (TX(${entity.location.tx},${entity.location.ty}) PX(${entity.location.px},${entity.location.py})) with image path \`${entityData.image}\` tried to render without an assigned asset! Make sure the appropriate asset (png?) exists.`
@@ -2345,7 +2365,9 @@ Map.prototype = {
23452365
}
23462366

23472367
const entityData = this._getEntityData(entity);
2348-
const entityTexture = this.entityTextures[entityData.image]; // || this.entityTextures["__default__"];
2368+
const entityTexture = this.entityTextures[
2369+
entityData[this.entityTexturesKeynameInEntityData]
2370+
]; // || this.entityTextures["__default__"];
23492371
if (!entityTexture) {
23502372
alert(
23512373
`Entity '${entity.name}' at (${entity.location.tx},${entity.location.ty}) with image path \`${entityData.image}\` tried to render without an assigned asset! Make sure the appropriate asset (png?) exists.`
@@ -2437,7 +2459,9 @@ Map.prototype = {
24372459
}
24382460

24392461
const entityData = this._getEntityData(entity);
2440-
const entityTexture = this.entityTextures[entityData.image]; // || this.entityTextures["__default__"];
2462+
const entityTexture = this.entityTextures[
2463+
entityData[this.entityTexturesKeynameInEntityData]
2464+
]; // || this.entityTextures["__default__"];
24412465
if (!entityTexture) {
24422466
alert(
24432467
`Entity '${entity.name}' at (${entity.location.tx},${entity.location.ty}) with image path \`${entityData.image}\` tried to render without an assigned asset! Make sure the appropriate asset (png?) exists.`
@@ -2524,7 +2548,9 @@ Map.prototype = {
25242548
layerOffsetTy = layer.offset.Y / tilesize.height;
25252549
}
25262550
const entityData = this._getEntityData(entity);
2527-
const entityTexture = this.entityTextures[entityData.image]; // || this.entityTextures["__default__"];
2551+
const entityTexture = this.entityTextures[
2552+
entityData[this.entityTexturesKeynameInEntityData]
2553+
]; // || this.entityTextures["__default__"];
25282554
if (!entityTexture) {
25292555
alert(
25302556
`Entity '${entity.name}' at (${entity.location.tx},${entity.location.ty}) with image path \`${entityData.image}\` tried to render without an assigned asset! Make sure the appropriate asset (png?) exists.`

0 commit comments

Comments
 (0)