Skip to content

Commit

Permalink
Added level overlaps in __neighbours JSON (#678)
Browse files Browse the repository at this point in the history
  • Loading branch information
deepnight committed Sep 20, 2023
1 parent ae6f75d commit d69544b
Showing 1 changed file with 29 additions and 4 deletions.
33 changes: 29 additions & 4 deletions src/electron.renderer/data/Level.hx
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,38 @@ class Level {
List nearby levels as JSON
**/
public function getNeighboursJson() : Array<ldtk.Json.NeighbourLevel> {
var neighbours : Array<ldtk.Json.NeighbourLevel> = switch _world.worldLayout {
var neighbours : Array<ldtk.Json.NeighbourLevel> = [];

// 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"
Expand All @@ -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();
Expand Down

0 comments on commit d69544b

Please # to comment.