]> git.lizzy.rs Git - dragonblocks.git/commitdiff
Remove entities from old map when setting a new one
authorElias Fleckenstein <eliasfleckenstein@web.de>
Wed, 30 Jun 2021 12:49:41 +0000 (14:49 +0200)
committerElias Fleckenstein <eliasfleckenstein@web.de>
Wed, 30 Jun 2021 12:49:41 +0000 (14:49 +0200)
engine/init.js
engine/spawned_entity.js

index 44359e8afac748f5d3ba01d8216a522d9d84daab..e8daae4db7d877803d86165d9ec5b636c169bd00 100644 (file)
 
                if (dragonblocks.loggedin)
                        setTimeout(_ => {
-                               dragonblocks.player.despawn();
+                               dragonblocks.player.removeFromMap();
                                dragonblocks.world.save();
                                location.reload();
                        });
index 47969059010b806a628d804337f73897193f60e9..bdc5153469cfec9df22250710c53c5ca87744395 100644 (file)
@@ -72,10 +72,22 @@ dragonblocks.SpawnedEntity = class
                return dragonblocks.entities[this.name];
        }
 
+       removeFromMap()
+       {
+               let self = this;
+               this.map.entities = this.map.entities.filter(entity => {
+                       return entity != self;
+               });
+       }
+
        setMap(map, x, y)
        {
-               this.tmp.display = map.entityContainer.appendChild(this.display);
+               this.removeFromMap();
+               map.entities.push(this);
+
                this.tmp.map = map;
+               this.tmp.display = map.entityContainer.appendChild(this.display);
+
                this.teleport(x, y);
        }
 
@@ -84,10 +96,7 @@ dragonblocks.SpawnedEntity = class
                let entityDef = this.toEntity();
                entityDef.ondespawn && entityDef.ondespawn(this);
 
-               let self = this;
-               this.map.entities = this.map.entities.filter(entity => {
-                       return entity != self;
-               });
+               this.removeFromMap();
 
                clearInterval(this.physicInterval);
                clearInterval(this.tickInterval);