From 852823f4e7525e3513c6c8813ddc1625d1ba8a6d Mon Sep 17 00:00:00 2001 From: HenryMarkle Date: Fri, 11 Oct 2024 13:51:22 +0300 Subject: [PATCH] Bug fix --- Leditor.Serialization/TileImporter.cs | 2 +- Leditor/Pages/Props.cs | 24 +++++++------- Leditor/Pages/Start.cs | 4 +-- Leditor/Printers.cs | 4 +-- Leditor/Serialization/Importers.cs | 8 +++++ Leditor/Utils.cs | 15 +++++++-- imgui.ini | 45 ++++++++++++++++++++++----- 7 files changed, 75 insertions(+), 27 deletions(-) diff --git a/Leditor.Serialization/TileImporter.cs b/Leditor.Serialization/TileImporter.cs index cc796dd..f320e38 100644 --- a/Leditor.Serialization/TileImporter.cs +++ b/Leditor.Serialization/TileImporter.cs @@ -564,7 +564,7 @@ public static Tile GetTileCell_NoExcept( logger?.Warning($"[TileImporter::GetTileCell_NoExcept] Undefined tile \"{name2}\""); } - var secondChainHolder = (tileDefinition!.Tags.Contains("Chain Holder") && asList.Length > 2) + var secondChainHolder = ((tileDefinition?.Tags.Contains("Chain Holder") ?? false) && asList.Length > 2) ? (asList[2] is AstNode.GlobalCall gc ? Utils.GetIntPair(gc) : (-1, -1)) : (-1, -1);; diff --git a/Leditor/Pages/Props.cs b/Leditor/Pages/Props.cs index a50949e..cb5af19 100644 --- a/Leditor/Pages/Props.cs +++ b/Leditor/Pages/Props.cs @@ -3481,21 +3481,23 @@ fetchedSelected[0].prop.Type is InitPropType_Legacy.Rope or InitPropType_Legacy. } ); } else if (current.model.EditType == RopeModel.EditTypeEnum.BezierPaths) { - var (pA, pB) = Utils.RopeEnds(fetchedSelected[0].prop.Quad); - - fetchedSelected[0].prop.Extras.RopePoints = Utils.Casteljau(fetchedSelected[0].prop.Extras.RopePoints.Length, [ pA, ..current.model.BezierHandles, pB ]); + if (fetchedSelected.Length > 0) { + var (pA, pB) = Utils.RopeEnds(fetchedSelected[0].prop.Quad); + + fetchedSelected[0].prop.Extras.RopePoints = Utils.Casteljau(fetchedSelected[0].prop.Extras.RopePoints.Length, [ pA, ..current.model.BezierHandles, pB ]); - if ((IsMouseButtonPressed(_shortcuts.SelectProps.Button) || IsKeyPressed(_shortcuts.SelectPropsAlt.Key)) && _bezierHandleLock != -1) - _bezierHandleLock = -1; + if ((IsMouseButtonPressed(_shortcuts.SelectProps.Button) || IsKeyPressed(_shortcuts.SelectPropsAlt.Key)) && _bezierHandleLock != -1) + _bezierHandleLock = -1; - if (IsMouseButtonDown(_shortcuts.SelectProps.Button)) - { - for (var b = 0; b < current.model.BezierHandles.Length; b++) + if (IsMouseButtonDown(_shortcuts.SelectProps.Button)) { - if (_bezierHandleLock == -1 && CheckCollisionPointCircle(tileMouseWorld, current.model.BezierHandles[b], 5f)) - _bezierHandleLock = b; + for (var b = 0; b < current.model.BezierHandles.Length; b++) + { + if (_bezierHandleLock == -1 && CheckCollisionPointCircle(tileMouseWorld, current.model.BezierHandles[b], 5f)) + _bezierHandleLock = b; - if (_bezierHandleLock == b) current.model.BezierHandles[b] = tileMouseWorld; + if (_bezierHandleLock == b) current.model.BezierHandles[b] = tileMouseWorld; + } } } } diff --git a/Leditor/Pages/Start.cs b/Leditor/Pages/Start.cs index 2a8b8c9..3500288 100644 --- a/Leditor/Pages/Start.cs +++ b/Leditor/Pages/Start.cs @@ -48,9 +48,9 @@ private TileCheckResult CheckTileIntegrity(in LoadFileResult res) HashSet missingTextures = []; HashSet missingMaterials = []; - for (int y = 0; y < res.Height; y++) + for (int y = 0; y < res.TileMatrix.GetLength(0); y++) { - for (int x = 0; x < res.Width; x++) + for (int x = 0; x < res.TileMatrix.GetLength(1); x++) { for (int z = 0; z < 3; z++) { diff --git a/Leditor/Printers.cs b/Leditor/Printers.cs index 02deb6f..a1d7848 100644 --- a/Leditor/Printers.cs +++ b/Leditor/Printers.cs @@ -1135,9 +1135,9 @@ internal static void DrawTileLayer( Color? unifiedTileColor = null, int materialColorSpace = 6) { - for (var y = 0; y < GLOBALS.Level.Height; y++) + for (var y = 0; y < GLOBALS.Level.TileMatrix.GetLength(0); y++) { - for (var x = 0; x < GLOBALS.Level.Width; x++) + for (var x = 0; x < GLOBALS.Level.TileMatrix.GetLength(1); x++) { if (grid) DrawRectangleLinesEx( new(x * scale, y * scale, scale, scale), diff --git a/Leditor/Serialization/Importers.cs b/Leditor/Serialization/Importers.cs index df14ddc..cd9487e 100644 --- a/Leditor/Serialization/Importers.cs +++ b/Leditor/Serialization/Importers.cs @@ -886,4 +886,12 @@ public static string GetDefaultMaterial(AstNode.Base @base) return materialBase.Value; } + + public static (int, int) GetLevelDimensions(AstNode.Base node) + { + var szAst = (node as AstNode.PropertyList)!.Values.FirstOrDefault(k => string.Equals((k.Key as AstNode.Symbol)!.Value, "size", StringComparison.OrdinalIgnoreCase)).Value; + var point = (AstNode.GlobalCall)szAst; + + return ((point.Arguments[0] as AstNode.Number)!.Value.IntValue, (point.Arguments[1] as AstNode.Number)!.Value.IntValue); + } } \ No newline at end of file diff --git a/Leditor/Utils.cs b/Leditor/Utils.cs index d27418f..8e83b7e 100644 --- a/Leditor/Utils.cs +++ b/Leditor/Utils.cs @@ -283,7 +283,15 @@ internal static async Task LoadProjectAsync(string filePath) // throw new Exception("Failed to parse level project file at line 9", e); } + var (foundWidth, foundHeight) = Serialization.Importers.GetLevelDimensions(obj2); + + var mtx = Serialization.Importers.GetGeoMatrix(obj, out int givenHeight, out int givenWidth); + if (foundWidth <= 0 || foundHeight <= 0) + { + foundWidth = givenWidth; + foundHeight = givenHeight; + } // var tlMtx = Serialization.Importers.GetTileMatrix(tilesObj, out _, out _); var tlMtx2 = Serialization.TileImporter.GetTileMatrix_NoExcept(tilesObj, GLOBALS.MaterialDex!.DefMap, GLOBALS.TileDex!.DefMap); var defaultMaterial = Serialization.Importers.GetDefaultMaterial(tilesObj); @@ -292,11 +300,11 @@ internal static async Task LoadProjectAsync(string filePath) var lightMode = Serialization.Importers.GetLightMode(obj2); var seed = Serialization.Importers.GetSeed(obj2); var waterData = Serialization.Importers.GetWaterData(waterObj); - var effects = Serialization.Importers.GetEffects(effObj, givenWidth, givenHeight); + var effects = Serialization.Importers.GetEffects(effObj, foundWidth, foundHeight); var cams = Serialization.Importers.GetCameras(camsObj); - for (var x = 0; x < givenWidth; x++) { - for (var y = 0; y < givenHeight; y++) { + for (var x = 0; x < foundWidth; x++) { + for (var y = 0; y < foundHeight; y++) { for (var z = 0; z < 3; z++) { var body = tlMtx2[y, x, z]; @@ -363,6 +371,7 @@ internal static async Task LoadProjectAsync(string filePath) { for (int z = 0; z < 3; z++) { + if (x < 0 || x >= tlMtx2.GetLength(1) || y < 0 || y >= tlMtx2.GetLength(0)) continue; var cell = tlMtx2[y, x, z]; if (cell.Type is not TileCellType.Material) continue; diff --git a/imgui.ini b/imgui.ini index 1dd132d..41a3c5c 100644 --- a/imgui.ini +++ b/imgui.ini @@ -34,12 +34,12 @@ Size=170,187 Collapsed=0 [Window][Blocks##GeoBlocks] -Pos=942,19 +Pos=1522,57 Size=338,252 Collapsed=0 [Window][Settings##NewGeoSettings] -Pos=942,273 +Pos=1520,309 Size=338,527 Collapsed=0 @@ -99,8 +99,8 @@ Collapsed=0 DockId=0x00000012,0 [Window][Settings##EditorSettings] -Pos=111,67 -Size=1052,653 +Pos=40,40 +Size=1840,911 Collapsed=0 [Window][New Effect##NewEffectMenu] @@ -157,7 +157,7 @@ Collapsed=0 [Window][Start##StartupWindow] Pos=40,40 -Size=1220,770 +Size=1840,911 Collapsed=0 [Window][Visuals##MainTextureVisualsWindow] @@ -176,9 +176,10 @@ Size=1920,972 Collapsed=0 [Window][Shortcuts##EditorShortcuts] -Pos=60,60 -Size=304,341 +Pos=0,650 +Size=1395,341 Collapsed=0 +DockId=0x00000002,0 [Window][Textures##TileEditorTileTexturesWin] Pos=60,586 @@ -190,8 +191,36 @@ Pos=60,60 Size=256,477 Collapsed=0 +[Window][Levels##LevelsSelectionWindow] +Pos=60,60 +Size=269,200 +Collapsed=0 + +[Window][Mirror Tools##GeometryEditorMirrorWindow] +Pos=60,60 +Size=130,146 +Collapsed=0 + +[Window][Props Menu##PropsPlacementPanel] +Pos=1605,19 +Size=315,972 +Collapsed=0 +DockId=0x00000006,0 + +[Window][Props List##PropsListWindow] +Pos=1397,19 +Size=206,972 +Collapsed=0 +DockId=0x00000005,0 + [Docking][Data] -DockSpace ID=0x7C6B3D9B Window=0xA87D555D Pos=0,19 Size=1920,972 CentralNode=1 +DockSpace ID=0x7C6B3D9B Window=0xA87D555D Pos=0,19 Size=1920,972 Split=X + DockNode ID=0x00000003 Parent=0x7C6B3D9B SizeRef=1395,972 Split=Y + DockNode ID=0x00000001 Parent=0x00000003 SizeRef=1300,488 CentralNode=1 + DockNode ID=0x00000002 Parent=0x00000003 SizeRef=1300,341 Selected=0x21189C27 + DockNode ID=0x00000004 Parent=0x7C6B3D9B SizeRef=523,972 Split=X Selected=0x865376BD + DockNode ID=0x00000005 Parent=0x00000004 SizeRef=206,972 Selected=0xDBC4B8D7 + DockNode ID=0x00000006 Parent=0x00000004 SizeRef=315,972 Selected=0x865376BD DockSpace ID=0x8B93E3BD Pos=0,19 Size=1280,781 Split=X DockNode ID=0x0000001B Parent=0x8B93E3BD SizeRef=939,800 Split=X DockNode ID=0x00000011 Parent=0x0000001B SizeRef=887,991 Split=X