6
6
MAGICAL_ZONE_LAYER_ID ,
7
7
getSelectedLayer
8
8
} from './js/ui/LayersPalette' ;
9
-
9
+ import { v4 as uuidv4 } from 'uuid' ;
10
10
import { ShaderProgram } from './ShaderProgram.js' ;
11
11
import { updateRstringInfo , updateInfoDims , updateLocationText , updateZoomText } from './Tools.js' ;
12
12
import { getZoneVisibility , getZoneAlpha } from './js/ui/ZonesPalette' ;
@@ -572,6 +572,22 @@ export function Map(mapfile, mapdatafile, updateLocationFunction) {
572
572
}
573
573
574
574
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
+
575
591
this . entityTextures = {
576
592
__default__ : { img : new window . Image ( ) }
577
593
} ;
@@ -966,7 +982,7 @@ Map.prototype = {
966
982
throw Error ( msg ) ;
967
983
}
968
984
969
- this . entityData [ filename ] = data ;
985
+ const textureKey = this . setEntityDataEntry ( filename , data ) ;
970
986
971
987
for ( const name in data . animations ) {
972
988
// convert short-hand to useful-hand
@@ -983,8 +999,8 @@ Map.prototype = {
983
999
984
1000
/// TODO: for gods sake put this all under test dammit
985
1001
/// 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 ] ) {
988
1004
// TODO maybe make this definable in this.mapedConfigData too?
989
1005
let imagePath = imageFilename ;
990
1006
@@ -1005,20 +1021,22 @@ Map.prototype = {
1005
1021
1006
1022
INFO ( `Adding '${ imagePath } ' to entityTextures cache...` ) ;
1007
1023
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 ( ) ;
1010
1026
const fn = this . doneLoading ;
1011
- this . entityTextures [ data . image ] . img . onload = function ( ) {
1027
+ this . entityTextures [ textureKey ] . img . onload = function ( ) {
1012
1028
fn ( data . image ) ;
1013
1029
} ;
1014
- this . entityTextures [ data . image ] . img . src = imagePath ;
1030
+ this . entityTextures [ textureKey ] . img . src = imagePath ;
1015
1031
}
1016
1032
1017
1033
if ( entity ) {
1018
1034
entity . MAPED_USEDEFAULT = false ;
1019
1035
}
1020
1036
LOG ( 'NOT USING DEFAULT ENTITY FOR ' , data . image ) ;
1021
1037
} catch ( e ) {
1038
+ alert ( e ) ;
1039
+
1022
1040
debugger ;
1023
1041
}
1024
1042
} ,
@@ -2170,7 +2188,9 @@ Map.prototype = {
2170
2188
}
2171
2189
2172
2190
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__"];
2174
2194
if ( ! entityTexture ) {
2175
2195
alert (
2176
2196
`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 = {
2345
2365
}
2346
2366
2347
2367
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__"];
2349
2371
if ( ! entityTexture ) {
2350
2372
alert (
2351
2373
`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 = {
2437
2459
}
2438
2460
2439
2461
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__"];
2441
2465
if ( ! entityTexture ) {
2442
2466
alert (
2443
2467
`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 = {
2524
2548
layerOffsetTy = layer . offset . Y / tilesize . height ;
2525
2549
}
2526
2550
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__"];
2528
2554
if ( ! entityTexture ) {
2529
2555
alert (
2530
2556
`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