From 10b87249dfcfd32c2f8f98b2b1c474e92b17d6d0 Mon Sep 17 00:00:00 2001 From: Mayberry Date: Fri, 2 Feb 2024 01:57:32 -0500 Subject: [PATCH 1/2] Catch AttributeError when changing CLogicShapeComponent type --- dread_editor/level_data.py | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/dread_editor/level_data.py b/dread_editor/level_data.py index 563cb22..717bc54 100644 --- a/dread_editor/level_data.py +++ b/dread_editor/level_data.py @@ -290,18 +290,21 @@ def lerp_y(y): and actor.pComponents.LOGICSHAPE["@type"] == 'CLogicShapeComponent'): shape = actor.pComponents.LOGICSHAPE.pLogicShape if shape is not None and shape["@type"] == 'game::logic::collision::CPolygonCollectionShape': - for poly in shape.oPolyCollection.vPolys: - vertices = [] - for p in poly.oSegmentData: - vertices.append( - (lerp_x(p.vPos[0] + actor.vPos[0]), - lerp_y(p.vPos[1] + actor.vPos[1])) + try: + for poly in shape.oPolyCollection.vPolys: + vertices = [] + for p in poly.oSegmentData: + vertices.append( + (lerp_x(p.vPos[0] + actor.vPos[0]), + lerp_y(p.vPos[1] + actor.vPos[1])) + ) + draw_list.add_polyline( + vertices, color, + closed=poly.bClosed, + thickness=3, ) - draw_list.add_polyline( - vertices, color, - closed=poly.bClosed, - thickness=3, - ) + except AttributeError: + pass if self.highlighted_actors_in_canvas and imgui.is_window_hovered(): imgui.begin_tooltip() From d65e5645fa3f97524d6537127240f4e46517cd0c Mon Sep 17 00:00:00 2001 From: Mayberry Date: Fri, 2 Feb 2024 02:30:20 -0500 Subject: [PATCH 2/2] Render AABox, Circle, and OBox logic shape types --- dread_editor/level_data.py | 50 +++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/dread_editor/level_data.py b/dread_editor/level_data.py index 717bc54..2c1d018 100644 --- a/dread_editor/level_data.py +++ b/dread_editor/level_data.py @@ -1,6 +1,7 @@ import colorsys import copy import hashlib +import math import os import struct import typing @@ -289,7 +290,54 @@ def lerp_y(y): if ("LOGICSHAPE" in actor.pComponents and actor.pComponents.LOGICSHAPE["@type"] == 'CLogicShapeComponent'): shape = actor.pComponents.LOGICSHAPE.pLogicShape - if shape is not None and shape["@type"] == 'game::logic::collision::CPolygonCollectionShape': + + + if shape is not None and shape["@type"] == 'game::logic::collision::CAABoxShape2D': + try: + draw_list.add_rect( + lerp_x(shape.v2Min[0] + actor.vPos[0]), + lerp_y(shape.v2Min[1] + actor.vPos[1]), + lerp_x(shape.v2Max[0] + actor.vPos[0]), + lerp_y(shape.v2Max[1] + actor.vPos[1]), + color, + thickness=3, + ) + except AttributeError: + pass + elif shape is not None and shape["@type"] == 'game::logic::collision::CCircleShape2D': + try: + draw_list.add_circle( + lerp_x(actor.vPos[0]), + lerp_y(actor.vPos[1]), + shape.fRadius, + color, + num_segments=32, + thickness=3, + ) + except AttributeError: + pass + elif shape is not None and shape["@type"] == 'game::logic::collision::COBoxShape2D': + try: + angleSin = math.sin(shape.fDegrees) + angleCos = math.cos(shape.fDegrees) + draw_list.add_polyline( + [ + (lerp_x((shape.v2Extent[0] * -1 * angleCos) - (shape.v2Extent[1] * angleSin) + actor.vPos[0]), + lerp_y((shape.v2Extent[0] * -1 * angleSin) + (shape.v2Extent[1] * angleCos) + actor.vPos[1])), + (lerp_x((shape.v2Extent[0] * angleCos) - (shape.v2Extent[1] * angleSin) + actor.vPos[0]), + lerp_y((shape.v2Extent[0] * angleSin) + (shape.v2Extent[1] * angleCos) + actor.vPos[1])), + (lerp_x((shape.v2Extent[0] * angleCos) - (shape.v2Extent[1] * -1 * angleSin) + actor.vPos[0]), + lerp_y((shape.v2Extent[0] * angleSin) + (shape.v2Extent[1] * -1 * angleCos) + actor.vPos[1])), + (lerp_x((shape.v2Extent[0] * -1 * angleCos) - (shape.v2Extent[1] * -1 * angleSin) + actor.vPos[0]), + lerp_y((shape.v2Extent[0] * -1 * angleSin) + (shape.v2Extent[1] * -1 * angleCos) + actor.vPos[1])) + ], + color, + closed=poly.bClosed, + thickness=3, + ) + except AttributeError: + pass + elif shape is not None and shape["@type"] == 'game::logic::collision::CPolygonCollectionShape': try: for poly in shape.oPolyCollection.vPolys: vertices = []