diff --git a/src/electron.renderer/data/Level.hx b/src/electron.renderer/data/Level.hx index 991069006..e7e5011cc 100644 --- a/src/electron.renderer/data/Level.hx +++ b/src/electron.renderer/data/Level.hx @@ -85,14 +85,38 @@ class Level { List nearby levels as JSON **/ public function getNeighboursJson() : Array { - var neighbours : Array = switch _world.worldLayout { + var neighbours : Array = []; + + // Overlaps in world layers + neighbours = neighbours.concat( switch _world.worldLayout { + case Free, GridVania: + var nears = _world.levels.filter( (ol)-> + ol!=this + && M.iabs(worldDepth-ol.worldDepth)<=1 + && dn.Lib.rectangleOverlaps(worldX,worldY,pxWid,pxHei, ol.worldX,ol.worldY,ol.pxWid,ol.pxHei) + ); + nears.map( (l)->{ + var dir = l.worldDepth==worldDepth ? "o" : l.worldDepth>worldDepth? ">" : "<"; + var nl : ldtk.Json.NeighbourLevel = { + levelIid: l.iid, + dir: dir, + } + return nl; + }); + + case LinearHorizontal, LinearVertical: + []; + } ); + + // Touching neighbours + neighbours = neighbours.concat( switch _world.worldLayout { case Free, GridVania: var nears = _world.levels.filter( (ol)-> ol!=this && getBoundsDist(ol)==0 && ol.worldDepth==worldDepth && !( ( ol.worldX>=worldX+pxWid || ol.worldX+ol.pxWid<=worldX ) - && ( ol.worldY>=worldY+pxHei || ol.worldY+ol.pxHei<=worldY ) - ) + && ( ol.worldY>=worldY+pxHei || ol.worldY+ol.pxHei<=worldY ) ) + && !dn.Lib.rectangleOverlaps(worldX,worldY,pxWid,pxHei, ol.worldX,ol.worldY,ol.pxWid,ol.pxHei) ); nears.map( (l)->{ var dir = l.worldX>=worldX+pxWid ? "e" @@ -108,12 +132,13 @@ class Level { case LinearHorizontal, LinearVertical: []; - } + }); return neighbours; } + public function toJson(ignoreCache=false) : ldtk.Json.LevelJson { if( !ignoreCache && hasJsonCache() ) { var o = getCacheJsonObject();