From 8eca21f121da48ef1cc2f42baf6d84b56d3fbacf Mon Sep 17 00:00:00 2001 From: VladiStep Date: Tue, 28 Jun 2022 16:55:00 +0300 Subject: [PATCH] Fixed not working global grid width/height if there are no tiles in the room; fixed crash on negative room grid values --- UndertaleModLib/Models/UndertaleRoom.cs | 13 +++++++++---- UndertaleModTool/Settings.cs | 6 ++++-- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/UndertaleModLib/Models/UndertaleRoom.cs b/UndertaleModLib/Models/UndertaleRoom.cs index 3ceb58b0f..351b1c0e0 100644 --- a/UndertaleModLib/Models/UndertaleRoom.cs +++ b/UndertaleModLib/Models/UndertaleRoom.cs @@ -101,6 +101,9 @@ public enum RoomEntryFlags : uint public uint Right { get; set; } = 1024; public uint Bottom { get; set; } = 768; + private double _gridWidth = 16.0; + private double _gridHeight = 16.0; + /// /// The gravity towards x axis using room physics in m/s. /// @@ -119,12 +122,12 @@ public enum RoomEntryFlags : uint /// /// The width of the room grid in pixels. /// - public double GridWidth { get; set; } = 16d; + public double GridWidth { get => _gridWidth; set { if (value >= 0) _gridWidth = value; } } /// /// The height of the room grid in pixels. /// - public double GridHeight { get; set; } = 16d; + public double GridHeight { get => _gridHeight; set { if (value >= 0) _gridHeight = value; } } /// /// The thickness of the room grid in pixels. @@ -416,8 +419,10 @@ public void SetupRoom(bool calculateGridWidth = true, bool calculateGridHeight = if (tileSizes.Count <= 0) { - GridWidth = 16; - GridHeight = 16; + if (calculateGridWidth) + GridWidth = 16; + if (calculateGridHeight) + GridHeight = 16; return; } diff --git a/UndertaleModTool/Settings.cs b/UndertaleModTool/Settings.cs index 20f643756..3f12fab86 100644 --- a/UndertaleModTool/Settings.cs +++ b/UndertaleModTool/Settings.cs @@ -42,9 +42,11 @@ public class Settings public bool DeleteOldProfileOnSave { get; set; } = false; public bool WarnOnClose { get; set; } = true; - public double GlobalGridWidth { get; set; } = 20; + private double _globalGridWidth = 20; + private double _globalGridHeight = 20; + public double GlobalGridWidth { get => _globalGridWidth; set { if (value >= 0) _globalGridWidth = value; } } public bool GridWidthEnabled { get; set; } = false; - public double GlobalGridHeight { get; set; } = 20; + public double GlobalGridHeight { get => _globalGridHeight; set { if (value >= 0) _globalGridHeight = value; } } public bool GridHeightEnabled { get; set; } = false; public double GlobalGridThickness { get; set; } = 1;