Skip to content

Commit 947bdd9

Browse files
committed
cut the world neighbours code for now
1 parent 0d47cb5 commit 947bdd9

File tree

2 files changed

+199
-164
lines changed

2 files changed

+199
-164
lines changed

datafiles/LDtkTest.ldtk

Lines changed: 199 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"iid": "a1125330-7820-11ed-85db-21c3ce148e1f",
1212
"jsonVersion": "1.5.3",
1313
"appBuildId": 473703,
14-
"nextUid": 47,
14+
"nextUid": 48,
1515
"identifierStyle": "Capitalize",
1616
"toc": [],
1717
"worldLayout": "Free",
@@ -628,16 +628,14 @@
628628
{ "px": [32,64], "src": [32,0], "f": 0, "t": 1, "d": [29], "a": 1 },
629629
{ "px": [128,64], "src": [0,0], "f": 0, "t": 0, "d": [32], "a": 1 },
630630
{ "px": [160,64], "src": [0,0], "f": 0, "t": 0, "d": [33], "a": 1 },
631-
{ "px": [384,64], "src": [32,0], "f": 0, "t": 1, "d": [40], "a": 1 },
632-
{ "px": [416,64], "src": [32,0], "f": 0, "t": 1, "d": [41], "a": 1 },
633631
{ "px": [0,96], "src": [32,0], "f": 0, "t": 1, "d": [42], "a": 1 },
634632
{ "px": [32,96], "src": [32,0], "f": 0, "t": 1, "d": [43], "a": 1 },
635-
{ "px": [384,96], "src": [32,0], "f": 0, "t": 1, "d": [54], "a": 1 },
633+
{ "px": [384,96], "src": [0,96], "f": 0, "t": 12, "d": [54], "a": 1 },
636634
{ "px": [416,96], "src": [32,0], "f": 0, "t": 1, "d": [55], "a": 1 },
637635
{ "px": [0,128], "src": [32,0], "f": 0, "t": 1, "d": [56], "a": 1 },
638636
{ "px": [32,128], "src": [32,0], "f": 0, "t": 1, "d": [57], "a": 1 },
639637
{ "px": [64,128], "src": [32,96], "f": 0, "t": 13, "d": [58], "a": 1 },
640-
{ "px": [384,128], "src": [32,0], "f": 0, "t": 1, "d": [68], "a": 1 },
638+
{ "px": [384,128], "src": [64,96], "f": 0, "t": 14, "d": [68], "a": 1 },
641639
{ "px": [416,128], "src": [32,0], "f": 0, "t": 1, "d": [69], "a": 1 },
642640
{ "px": [0,160], "src": [32,0], "f": 0, "t": 1, "d": [70], "a": 1 },
643641
{ "px": [32,160], "src": [32,0], "f": 0, "t": 1, "d": [71], "a": 1 },
@@ -697,7 +695,202 @@
697695
"entityInstances": []
698696
}
699697
],
700-
"__neighbours": []
698+
"__neighbours": [{ "levelIid": "236eaec0-3740-11f0-b1af-19eb6ab872a7", "dir": "e" }]
699+
},
700+
{
701+
"identifier": "Test1",
702+
"iid": "236eaec0-3740-11f0-b1af-19eb6ab872a7",
703+
"uid": 47,
704+
"worldX": 624,
705+
"worldY": -384,
706+
"worldDepth": 0,
707+
"pxWid": 224,
708+
"pxHei": 288,
709+
"__bgColor": "#696A79",
710+
"bgColor": null,
711+
"useAutoIdentifier": true,
712+
"bgRelPath": null,
713+
"bgPos": null,
714+
"bgPivotX": 0.5,
715+
"bgPivotY": 0.5,
716+
"__smartColor": "#ADADB5",
717+
"__bgPos": null,
718+
"externalRelPath": null,
719+
"fieldInstances": [],
720+
"layerInstances": [
721+
{
722+
"__identifier": "Entities",
723+
"__type": "Entities",
724+
"__cWid": 14,
725+
"__cHei": 18,
726+
"__gridSize": 16,
727+
"__opacity": 1,
728+
"__pxTotalOffsetX": 0,
729+
"__pxTotalOffsetY": 0,
730+
"__tilesetDefUid": null,
731+
"__tilesetRelPath": null,
732+
"iid": "236ed5d0-3740-11f0-b1af-a39e085c9136",
733+
"levelId": 47,
734+
"layerDefUid": 3,
735+
"pxOffsetX": 0,
736+
"pxOffsetY": 0,
737+
"visible": true,
738+
"optionalRules": [],
739+
"intGridCsv": [],
740+
"autoLayerTiles": [],
741+
"seed": 2299130,
742+
"overrideTilesetUid": null,
743+
"gridTiles": [],
744+
"entityInstances": []
745+
},
746+
{
747+
"__identifier": "Tiles",
748+
"__type": "Tiles",
749+
"__cWid": 7,
750+
"__cHei": 9,
751+
"__gridSize": 32,
752+
"__opacity": 1,
753+
"__pxTotalOffsetX": 0,
754+
"__pxTotalOffsetY": 0,
755+
"__tilesetDefUid": 1,
756+
"__tilesetRelPath": "../sprites/sTiles/21121d05-069b-4cac-a7f4-29276ef81c64.png",
757+
"iid": "236ed5d1-3740-11f0-b1af-1d0782122a5e",
758+
"levelId": 47,
759+
"layerDefUid": 2,
760+
"pxOffsetX": 0,
761+
"pxOffsetY": 0,
762+
"visible": true,
763+
"optionalRules": [],
764+
"intGridCsv": [],
765+
"autoLayerTiles": [],
766+
"seed": 2516401,
767+
"overrideTilesetUid": null,
768+
"gridTiles": [
769+
{ "px": [0,0], "src": [32,0], "f": 0, "t": 1, "d": [0], "a": 1 },
770+
{ "px": [32,0], "src": [32,0], "f": 0, "t": 1, "d": [1], "a": 1 },
771+
{ "px": [64,0], "src": [32,0], "f": 0, "t": 1, "d": [2], "a": 1 },
772+
{ "px": [96,0], "src": [32,0], "f": 0, "t": 1, "d": [3], "a": 1 },
773+
{ "px": [128,0], "src": [32,0], "f": 0, "t": 1, "d": [4], "a": 1 },
774+
{ "px": [160,0], "src": [32,0], "f": 0, "t": 1, "d": [5], "a": 1 },
775+
{ "px": [192,0], "src": [32,0], "f": 0, "t": 1, "d": [6], "a": 1 },
776+
{ "px": [0,32], "src": [32,0], "f": 0, "t": 1, "d": [7], "a": 1 },
777+
{ "px": [192,32], "src": [32,0], "f": 0, "t": 1, "d": [13], "a": 1 },
778+
{ "px": [0,64], "src": [32,0], "f": 0, "t": 1, "d": [14], "a": 1 },
779+
{ "px": [192,64], "src": [32,0], "f": 0, "t": 1, "d": [20], "a": 1 },
780+
{ "px": [0,96], "src": [32,0], "f": 0, "t": 1, "d": [21], "a": 1 },
781+
{ "px": [192,96], "src": [32,0], "f": 0, "t": 1, "d": [27], "a": 1 },
782+
{ "px": [0,128], "src": [0,64], "f": 0, "t": 8, "d": [28], "a": 1 },
783+
{ "px": [32,128], "src": [32,96], "f": 0, "t": 13, "d": [29], "a": 1 },
784+
{ "px": [192,128], "src": [32,0], "f": 0, "t": 1, "d": [34], "a": 1 },
785+
{ "px": [0,160], "src": [0,64], "f": 0, "t": 8, "d": [35], "a": 1 },
786+
{ "px": [32,160], "src": [96,96], "f": 0, "t": 15, "d": [36], "a": 1 },
787+
{ "px": [192,160], "src": [32,0], "f": 0, "t": 1, "d": [41], "a": 1 },
788+
{ "px": [192,192], "src": [32,0], "f": 0, "t": 1, "d": [48], "a": 1 },
789+
{ "px": [0,224], "src": [0,64], "f": 0, "t": 8, "d": [49], "a": 1 },
790+
{ "px": [32,224], "src": [96,96], "f": 0, "t": 15, "d": [50], "a": 1 },
791+
{ "px": [160,224], "src": [64,0], "f": 0, "t": 2, "d": [54], "a": 1 },
792+
{ "px": [192,224], "src": [32,0], "f": 0, "t": 1, "d": [55], "a": 1 },
793+
{ "px": [0,256], "src": [32,0], "f": 0, "t": 1, "d": [56], "a": 1 },
794+
{ "px": [32,256], "src": [32,0], "f": 0, "t": 1, "d": [57], "a": 1 },
795+
{ "px": [64,256], "src": [32,0], "f": 0, "t": 1, "d": [58], "a": 1 },
796+
{ "px": [96,256], "src": [32,0], "f": 0, "t": 1, "d": [59], "a": 1 },
797+
{ "px": [128,256], "src": [32,0], "f": 0, "t": 1, "d": [60], "a": 1 },
798+
{ "px": [160,256], "src": [32,0], "f": 0, "t": 1, "d": [61], "a": 1 },
799+
{ "px": [192,256], "src": [32,0], "f": 0, "t": 1, "d": [62], "a": 1 }
800+
],
801+
"entityInstances": []
802+
},
803+
{
804+
"__identifier": "IntGrid",
805+
"__type": "IntGrid",
806+
"__cWid": 7,
807+
"__cHei": 9,
808+
"__gridSize": 32,
809+
"__opacity": 1,
810+
"__pxTotalOffsetX": 0,
811+
"__pxTotalOffsetY": 0,
812+
"__tilesetDefUid": null,
813+
"__tilesetRelPath": null,
814+
"iid": "236ed5d2-3740-11f0-b1af-05cb7ca1e96b",
815+
"levelId": 47,
816+
"layerDefUid": 27,
817+
"pxOffsetX": 0,
818+
"pxOffsetY": 0,
819+
"visible": true,
820+
"optionalRules": [],
821+
"intGridCsv": [
822+
0,
823+
0,
824+
0,
825+
0,
826+
0,
827+
0,
828+
0,
829+
0,
830+
0,
831+
0,
832+
0,
833+
0,
834+
0,
835+
0,
836+
0,
837+
0,
838+
0,
839+
0,
840+
0,
841+
0,
842+
0,
843+
0,
844+
0,
845+
0,
846+
0,
847+
0,
848+
0,
849+
0,
850+
0,
851+
0,
852+
0,
853+
0,
854+
0,
855+
0,
856+
0,
857+
0,
858+
0,
859+
0,
860+
0,
861+
0,
862+
0,
863+
0,
864+
0,
865+
0,
866+
0,
867+
0,
868+
0,
869+
0,
870+
0,
871+
0,
872+
0,
873+
0,
874+
0,
875+
0,
876+
0,
877+
0,
878+
0,
879+
0,
880+
0,
881+
0,
882+
0,
883+
0,
884+
0
885+
],
886+
"autoLayerTiles": [],
887+
"seed": 3584419,
888+
"overrideTilesetUid": null,
889+
"gridTiles": [],
890+
"entityInstances": []
891+
}
892+
],
893+
"__neighbours": [{ "levelIid": "3f259711-b4d0-11ec-b21c-bd9e94dca9dd", "dir": "w" }]
701894
}
702895
],
703896
"worlds": [],

scripts/LDtkParser/LDtkParser.gml

Lines changed: 0 additions & 158 deletions
Original file line numberDiff line numberDiff line change
@@ -719,164 +719,6 @@ function LDtkReloadFields() {
719719
}
720720
}
721721

722-
#region
723-
724-
/// @function LDtkChangeLevel(level_name)
725-
/// @desc Clears existing LDtk instances and loads a new level
726-
/// @param {String} level_name
727-
function LDtkChangeLevel(_level_name) {
728-
729-
with (all){
730-
if (object_index != oLDtk && object_index != oLink){
731-
instance_destroy()
732-
}
733-
}
734-
735-
// Update config and load new level
736-
global.__ldtk_config.level_name = _level_name;
737-
LDtkLoad(_level_name);
738-
739-
}
740-
741-
742-
743-
744-
745-
/// @func LDtkGetLevelByIid(_iid)
746-
/// @arg _iid the IID of the level in LDtk
747-
/// @return the level struct, or undefined if not found
748-
function LDtkGetLevelByIid(_iid) {
749-
var levels = global.ldtk_data.levels;
750-
for (var i = 0; i < array_length(levels); ++i) {
751-
var lvl = levels[i];
752-
if (lvl.iid == _iid) {
753-
return lvl; // found it!
754-
}
755-
}
756-
return undefined; // no matching IID
757-
}
758-
759-
760-
761-
/// @func LDtkFindNeighbor(_dir)
762-
/// @arg _dir one of "n","s","e","w"
763-
/// @return a neighbor record with levelIid, or undefined
764-
function LDtkFindNeighbor(_dir) {
765-
var list = global.current_ldtk_level.__neighbours; // raw neighbor array from JSON
766-
767-
// 1) collect all iids for that direction
768-
var candidates = [];
769-
for (var i = 0; i < array_length(list); ++i) {
770-
if (list[i].dir == _dir) {
771-
array_push(candidates, list[i].levelIid);
772-
773-
}
774-
}
775-
// 2) none or single → easy
776-
if (array_length(candidates) == 0) return undefined;
777-
778-
if (array_length(candidates) == 1) return { levelIid: candidates[0] };
779-
780-
// 3) multiple → choose by player's world Y
781-
var worldY = oLink.y + global.current_ldtk_level.worldY;
782-
783-
// try to find which neighbor's vertical span contains worldY
784-
for (var i = 0; i < array_length(candidates); ++i) {
785-
var _iid = candidates[i];
786-
var _lvlName = LDtkGetLevelByIid(_iid); // This returns the level name from a struct containing iids with their identifiers
787-
788-
// var lvl = LDtkGetLevelByIid(iid);
789-
if (worldY >= _lvlName.worldY && worldY < _lvlName.worldY + _lvlName.pxHei) {
790-
return { levelIid: _iid };
791-
}
792-
}
793-
794-
// 4) fallback: pick the neighbor whose midpoint is closest
795-
var best = -1;
796-
var bestDist = power(10, 9); // supposed to be a high number so the room height will never reach this
797-
for (var i = 0; i < array_length(candidates); ++i) {
798-
var _iid = candidates[i];
799-
var _lvlName = LDtkGetLevelByIid(_iid); // This returns the level name from a struct containing iids with their identifiers
800-
// var lvl = LDtkGetLevelByIid(iid);
801-
var midY = _lvlName.worldY + _lvlName.pxHei * 0.5;
802-
var d = abs(worldY - midY);
803-
if (d < bestDist) {
804-
bestDist = d;
805-
best = _iid;
806-
}
807-
}
808-
return { levelIid: best };
809-
}
810-
811-
812-
813-
814-
815-
816-
/// @func LDtkGoToNeighbor(dir)
817-
/// @arg dir string: direction badge ("n","s","e","w","nw","se", etc)
818-
/// @ret bool true if we found & loaded, false otherwise
819-
820-
function LDtkGoToNeighbor(_dir) {
821-
var _neighbor = LDtkFindNeighbor(_dir);
822-
if (_neighbor == undefined) {
823-
return false;
824-
}
825-
826-
var _iid = _neighbor.levelIid;
827-
// show_message($"iid is {_iid} and struct = {global.ldtk_iid_to_level_struct}")
828-
var _lvlName = global.ldtk_iid_to_level_struct[$ _iid]; // This returns the level name from a struct containing iids with their identifiers
829-
var _target_level_width = -1;
830-
var _target_level_height = -1;
831-
var _target_level_world_x = -1;
832-
var _target_level_world_y = -1;
833-
// Iterate through all levels in the new global variable
834-
for (var i = 0; i < array_length(global.ldtk_data.levels); ++i) {
835-
836-
// Check if the identifier matches
837-
if (global.ldtk_data.levels[i].identifier == _lvlName) {
838-
// Now you have access to the level data
839-
_target_level_width = global.ldtk_data.levels[i].pxWid; // The pixel width of the level
840-
_target_level_height = global.ldtk_data.levels[i].pxHei; // The pixel height of the level
841-
_target_level_world_x = global.ldtk_data.levels[i].worldX; // The world X coordinate of the level
842-
_target_level_world_y = global.ldtk_data.levels[i].worldY; // The world Y coordinate of the level
843-
844-
}
845-
}
846-
// Handling player spawn point (door-to-door transitions)
847-
848-
var _player_world_x = oLink.x + global.current_ldtk_level.worldX;
849-
var _player_world_y = oLink.y + global.current_ldtk_level.worldY;
850-
var _player_world_spawn_x = _player_world_x - _target_level_world_x;
851-
var _player_world_spawn_y = _player_world_y - _target_level_world_y;
852-
853-
854-
switch (_dir) {
855-
case "n": _player_world_spawn_y = _target_level_height - 12; break;
856-
case "s": _player_world_spawn_y = 12; break;
857-
case "e": _player_world_spawn_x = 12; break;
858-
case "w": _player_world_spawn_x = _target_level_width - 12; break;
859-
}
860-
861-
862-
if (_lvlName == undefined) {
863-
__LDtkTrace("LDtk neighbor IID not found: " + iid);
864-
return false;
865-
}
866-
867-
868-
LDtkChangeLevel(_lvlName);
869-
__LDtkTrace($"Changing level to {_lvlName}")
870-
oLink.x = _player_world_spawn_x;
871-
oLink.y = _player_world_spawn_y;
872-
873-
874-
return true;
875-
}
876-
877-
878-
879-
#endregion
880722
#region Utility functions
881723

882724
function __LDtkTrace(str) {

0 commit comments

Comments
 (0)