-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUniPy.py
More file actions
186 lines (151 loc) · 5.9 KB
/
UniPy.py
File metadata and controls
186 lines (151 loc) · 5.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
import engineUI as eui
import settings as st
import os, inspect, collections, re
import pather as pt
from objects import camera
from modules import Math
OON = []
objClass = []
objName = []
objects = []
fingersPos = [None] * 10
OWS = []
Camera = camera.Camera(st.AppWidth, st.AppHeight)
STARTGRAVITY = 0.48
GRAVITY = STARTGRAVITY
TERMINALVELOCITY = 48
wWidth, wHeight = st.AppWidth, st.AppHeight
pWidth, pHeight = st.projectSize
textures = {}
texturesTSP = {}
audios = {}
_audioTypes = ["mp3", "ogg", "wav", "flac"]
_imgTypes = ["png", "jpg", "jpeg", "bmp"]
_bodyTypes = ["None", "dynamic", "static", "kinematic"]
_mathSybs = {*"01234567890+-*/.()^ "}
def Error(file, line, error, _type):
if _type == "error": eui.error = True
eui._console.Log(f"UniPy {_type.capitalize()}: in script \"{file.split(pt.s)[-1]}\": in line [{line}]\n{error}", _type)
def GetObj(name: str):
if name in objName:
idx = objName.index(name)
return objects[idx]
else:
caller_frame = inspect.currentframe().f_back
file = caller_frame.f_code.co_filename
line = caller_frame.f_lineno
Error(file, line, f"\"{name}\" is not defined", "error")
def SetBgColor(color: tuple):
if all(isinstance(c, int) and 0 <= c <= 255 for c in color):
st.GBGC = color
else:
caller_frame = inspect.currentframe().f_back
file = caller_frame.f_code.co_filename
line = caller_frame.f_lineno
Error(file, line, f"\"{color}\" invalid color", "warning")
def __isRGB(s):
formats = [
r"(\d+)\s*,\s*(\d+)\s*,\s*(\d+)",
r"\((\d+)\s*,\s*(\d+)\s*,\s*(\d+)\)",
r"\[(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\]"
]
for fmt in formats:
match = re.fullmatch(fmt, s)
if match:
r, g, b = map(int, match.groups())
if 0 <= r <= 255 and 0 <= g <= 255 and 0 <= b <= 255:
return True
return False
def SaveVariable(key: str, value: any, _type: any):
path = f".{pt.s}projects{pt.s}{st.projects[st.projectIdx]}{pt.s}$data"
if not os.path.exists(path):
os.makedirs(path)
with open(f"{path}{pt.s}{key}.txt", "w") as f:
f.write(f"{_type.__name__}: {value}")
def LoadVariable(key: str, notFoundValue = 0):
try:
with open(f".{pt.s}projects{pt.s}{st.projects[st.projectIdx]}{pt.s}$data{pt.s}{key}.txt", "r") as f:
get = f.read().split(":", 1)
value = f"{get[0].strip()}({get[1].strip()})"
return eval(value)
except:
caller_frame = inspect.currentframe().f_back
file = caller_frame.f_code.co_filename
line = caller_frame.f_lineno
Error(file, line, f"\"{key}\" is not defined", "warning")
return notFoundValue
def GetModule(name: str):
for module in st.modules:
if name == module.__name__.split(".")[-1]: return module
caller_frame = inspect.currentframe().f_back
file = caller_frame.f_code.co_filename
line = caller_frame.f_lineno
Error(file, line, f"\"{name}\" is not defined", "warning")
def log(text: str):
caller_frame = inspect.currentframe().f_back
file = caller_frame.f_code.co_filename
line = caller_frame.f_lineno
eui._console.Log(text, "log", file.split(pt.s)[-1], line)
def CloneObject(name):
global objLayers
if name in OON:
if OWS != []: owsIdx = OWS.index(OWS[-1])+1
else: owsIdx = 0
eui.ouar.loadObjs(eui.pe, f"{eui.PATH}{pt.s}{st.projects[st.projectIdx]}{pt.s}ObjectInfo.txt", OON.index(name))
objects[-1].setPos()
objects[-1].setPosObject()
eui.loadObjectScriptLinks(True)
for i in OWS[owsIdx:]:
if hasattr(i, "Start"): i.Start()
if hasattr(i, "Update"): st.MHFU.append(i)
return objects[-1]
else:
caller_frame = inspect.currentframe().f_back
file = caller_frame.f_code.co_filename
line = caller_frame.f_lineno
Error(file, line, f"\"{name}\" is not defined", "warning")
def GetTexture(name: str, fullAlpha: bool = False):
ftxs = [i for i in textures] if not fullAlpha else [i for i in texturesTSP]
txs = [i.split(pt.s)[-1].rsplit(".", 1)[0] for i in textures] if not fullAlpha else [i for i in texturesTSP]
if name in txs:
return textures[ftxs[txs.index(name)]] if not fullAlpha else texturesTSP[ftxs[txs.index(name)]]
else:
caller_frame = inspect.currentframe().f_back
file = caller_frame.f_code.co_filename
line = caller_frame.f_lineno
Error(file, line, f"\"{name}\" is not defined", "warning")
def GetSound(name: str):
faus = [i for i in audios]
aus = [i.split(pt.s)[-1].rsplit(".", 1)[0] for i in audios]
if name in aus:
return audios[faus[aus.index(name)]]
else:
caller_frame = inspect.currentframe().f_back
file = caller_frame.f_code.co_filename
line = caller_frame.f_lineno
Error(file, line, f"\"{name}\" is not defined", "warning")
def SetCamera(name: str):
if name in objName:
Camera.target = objects[objName.index(name)]
else:
caller_frame = inspect.currentframe().f_back
file = caller_frame.f_code.co_filename
line = caller_frame.f_lineno
Error(file, line, f"\"{name}\" is not defined", "warning")
def DelObj(obj):
global objects, OWS, objLayers
if obj in objects:
for script in obj.S_LINKS:
OWS.remove(script)
if script in st.MHFU: st.MHFU.remove(script)
if obj.PARENT in objName: objName.remove(obj.PARENT)
objects.remove(obj)
else:
caller_frame = inspect.currentframe().f_back
file = caller_frame.f_code.co_filename
line = caller_frame.f_lineno
Error(file, line, f"\"{obj}\" is not defined", "warning")
def GetObjectsWithTag(name: str):
return [obj for obj in objects if obj.tag == name]
def appQuit(): eui.returnToEditor()
def reloadApp(): eui.startApp()