Skip to content

Instantly share code, notes, and snippets.

@user-grinch
Created July 22, 2021 15:38
Show Gist options
  • Save user-grinch/b12fd8c8f6b6612b158af14112682901 to your computer and use it in GitHub Desktop.
Save user-grinch/b12fd8c8f6b6612b158af14112682901 to your computer and use it in GitHub Desktop.
import dearpygui.dearpygui as dpg
from scipy.spatial.transform import Rotation
###############################################
# Constants
VIEWPORT_HEIGHT :int = 500
VIEWPORT_WIDTH :int = 900
VIEWPORT_TITLE :str = "IPL 2 PAWN"
INPUT_TEXT : str = ""
OUTPUT_TEXT : str = ""
###############################################
def input_callback(sender):
global INPUT_TEXT
INPUT_TEXT = dpg.get_value(sender)
def parseIpl(sender, app_data , user_data):
global INPUT_TEXT
global OUTPUT_TEXT
inst_section :bool = False
OUTPUT_TEXT = "// PAWN generated by IPL 2 PAWN by Grinch_\n"
for line in INPUT_TEXT.splitlines():
if line == "inst":
inst_section = True
continue
if inst_section:
if line == "end":
inst_section = False
break
if not line.startswith('#'):
data :list = line.split(',')
if len(data) == 11:
rot = Rotation.from_quat([data[6], data[7], data[8], data[9]])
rot_euler = rot.as_euler('zyx', degrees=True)
new_line = "CreateObject({0:}, {1:}, {2:}, {3:}, {4:0.5f}, {5:0.5f}, {6:0.5f});\n".format(data[0], data[3], data[4], data[5], -rot_euler[2], -rot_euler[1], -rot_euler[0])
OUTPUT_TEXT = OUTPUT_TEXT + new_line
dpg.set_value(user_data, OUTPUT_TEXT)
def savePwn():
f = open("output.pwn", "w")
f.write(OUTPUT_TEXT)
f.close()
dpg.popup("Saved output")
with dpg.font_registry():
dpg.add_font("C:/Windows/Fonts/trebucbd.ttf", 16, default_font=True)
with dpg.window(label=VIEWPORT_TITLE, width= 900, height=500, no_resize=True) as main_window:
input_width :int = VIEWPORT_WIDTH-30
btn_width :int = int(VIEWPORT_WIDTH/2-19)
item_height :int = int(VIEWPORT_HEIGHT/2 - 75)
dpg.add_text("IPL Lines:")
dpg.add_input_text(label="###IPL Lines", multiline=True, width= input_width, height=item_height, callback=input_callback)
dpg.add_spacing()
dpg.add_text("PAWN Lines:")
out = dpg.add_input_text(label="###PAWN Lines", multiline=True, width= input_width, height=item_height, readonly=True)
dpg.add_button(label="Convert",width= btn_width, height= 30, callback=parseIpl, user_data= out)
dpg.add_same_line()
dpg.add_button(label="Save",width= btn_width, height= 30, callback=savePwn)
dpg.setup_viewport()
dpg.set_viewport_title(title=VIEWPORT_TITLE)
dpg.set_viewport_width(VIEWPORT_WIDTH)
dpg.set_viewport_height(VIEWPORT_HEIGHT)
dpg.set_primary_window(main_window, True)
dpg.start_dearpygui()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment