Skip to content

Commit

Permalink
Bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
HenryMarkle committed Oct 11, 2024
1 parent 67e86df commit 852823f
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 27 deletions.
2 changes: 1 addition & 1 deletion Leditor.Serialization/TileImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);;

Expand Down
24 changes: 13 additions & 11 deletions Leditor/Pages/Props.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions Leditor/Pages/Start.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ private TileCheckResult CheckTileIntegrity(in LoadFileResult res)
HashSet<string> missingTextures = [];
HashSet<string> 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++)
{
Expand Down
4 changes: 2 additions & 2 deletions Leditor/Printers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
8 changes: 8 additions & 0 deletions Leditor/Serialization/Importers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
15 changes: 12 additions & 3 deletions Leditor/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,15 @@ internal static async Task<LoadFileResult> 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);
Expand All @@ -292,11 +300,11 @@ internal static async Task<LoadFileResult> 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];

Expand Down Expand Up @@ -363,6 +371,7 @@ internal static async Task<LoadFileResult> 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;
Expand Down
45 changes: 37 additions & 8 deletions imgui.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -157,7 +157,7 @@ Collapsed=0

[Window][Start##StartupWindow]
Pos=40,40
Size=1220,770
Size=1840,911
Collapsed=0

[Window][Visuals##MainTextureVisualsWindow]
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 852823f

Please sign in to comment.