Skip to content

Commit 5e5b307

Browse files
committed
Linux fixes
1 parent 5bb086a commit 5e5b307

File tree

10 files changed

+79
-71
lines changed

10 files changed

+79
-71
lines changed

HK.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class HK(Menu):
55
def __init__(self, process, openmenu="MN"):
66
self.menu = "HK"
77
self.m = openmenu
8-
self.keys = json.load(open(path2hotkeys / globalsettings["hotkeydescfile"]))
8+
self.keys = json.load(open(os.path.join(path2hotkeys, globalsettings["hotkeydescfile"])))
99
self.scroll = 0
1010
self.lines = 0
1111

@@ -90,6 +90,6 @@ def goback(self):
9090

9191
def edit(self):
9292
if islinux:
93-
os.system(f"open {path / 'files/hotkeys.json'}")
93+
os.system(f"open {os.path.join(path, 'files/hotkeys.json')}")
9494
else:
95-
os.system(f"\"{path / 'hotkeys.json'}\"")
95+
os.system(f"\"{os.path.join(path, 'hotkeys.json')}\"")

LE.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ def __init__(self,process):
3939
self.images = {True: [], False: []}
4040

4141
for i in globalsettings["shadowimages"]:
42-
img = loadimage(path2cast / i)
42+
img = loadimage(os.path.join(path2cast, i))
4343
img.set_colorkey(white)
4444
self.images[True].append(img)
4545

46-
img = loadimage(path2cast / i)
46+
img = loadimage(os.path.join(path2cast, i))
4747
arr = pg.pixelarray.PixelArray(img)
4848
arr.replace(black, red)
4949
arr.replace(white, black)
@@ -180,7 +180,7 @@ def save(self):
180180
pg.draw.circle(self.field2.field, black, [0, self.field2.field.get_height()], 1)
181181
pg.draw.circle(self.field2.field, black, [self.field2.field.get_width(), self.field2.field.get_height()], 1)
182182
if self.data["path"] == "":
183-
if globalsettings["rwefilebrowser"]:
183+
if globalsettings["rwefilebrowser"] or islinux:
184184
level = self.asksaveasfilename(defaultextension=[".wep"])
185185
else:
186186
level = filedialog.asksaveasfilename(filetypes=[("World Editor Project", ".wep")],

LevelProcess.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from menuclass import Menu, MenuWithField
33
import time
44
import requests
5+
from tkinter import filedialog
56

67

78
class ProcessManager:
@@ -13,11 +14,11 @@ def __init__(self):
1314
self.keys = [pg.K_LCTRL, pg.K_LALT, pg.K_LSHIFT]
1415
self.movekeys = [pg.K_LEFT, pg.K_UP, pg.K_DOWN, pg.K_RIGHT]
1516
self.fullscreen = settings["global"]["fullscreen"]
16-
loadi = loadimage(path / "load.png")
17+
loadi = loadimage(os.path.join(path, "load.png"))
1718
self.window = pg.display.set_mode(loadi.get_size(), flags=pg.NOFRAME)
1819
self.window.blit(loadi, [0, 0])
1920

20-
pg.display.set_icon(loadimage(path / "icon.png"))
21+
pg.display.set_icon(loadimage(os.path.join(path, "icon.png")))
2122
pg.display.flip()
2223
pg.display.update()
2324
self.tiles = inittolist(self.window)
@@ -122,7 +123,7 @@ def mainprocessupdate(self):
122123
self.mainprocess.update()
123124
except Exception as e:
124125
# extra save level in case of eny crashes
125-
f = open(application_path / "CrashLog.txt", "w")
126+
f = open(os.path.join(application_path, "CrashLog.txt"), "w")
126127
f.write(traceback.format_exc())
127128
f.write("This is why RWE+ crashed^^^\nSorry")
128129
saved = False
@@ -245,7 +246,7 @@ def asktoexit(self):
245246

246247
def launchload(self, level):
247248
if level == -1:
248-
self.file = turntoproject(open(path / "default.txt", "r").read())
249+
self.file = turntoproject(open(os.path.join(path, "default.txt"), "r").read())
249250
self.file["level"] = ""
250251
self.file["path"] = ""
251252
self.file["dir"] = ""
@@ -314,7 +315,7 @@ def recievemessage(self, message):
314315
case "new":
315316
self.__init__(self.manager, -1)
316317
case "openNewProcess":
317-
if globalsettings["rwefilebrowser"]:
318+
if globalsettings["rwefilebrowser"] or islinux:
318319
file = self.menu.asksaveasfilename(defaultextension=[".txt", ".wep"])
319320
else:
320321
file = filedialog.askopenfilename(initialdir=path2levels,
@@ -324,7 +325,7 @@ def recievemessage(self, message):
324325
if file is not None and os.path.exists(file):
325326
self.manager.newprocess(file)
326327
case "open":
327-
if globalsettings["rwefilebrowser"]:
328+
if globalsettings["rwefilebrowser"] or islinux:
328329
file = self.menu.asksaveasfilename(defaultextension=[".txt", ".wep"])
329330
else:
330331
file = filedialog.askopenfilename(initialdir=path2levels,

MN.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
class MN(MenuWithField):
77
def __init__(self, process):
88
super().__init__(process, "MN")
9-
tips = set(open(path / "tips.txt", "r").readlines())
9+
tips = set(open(os.path.join(path, "tips.txt"), "r").readlines())
1010
self.tips = list(tips)
1111
self.mousp = True
1212
self.mousp1 = True

TE.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,15 @@ def __init__(self, process):
4141

4242
self.items: ItemData = process.renderer.tiles
4343
self.codes = {}
44-
p: dict = jsonc.load(open(path / "patterns.json", "r"))
44+
p: dict = jsonc.load(open(os.path.join(path, "patterns.json"), "r"))
4545
if "special" not in self.items.categories:
4646
self.items.append({"name": "special", "color": black, "items": p["patterns"]})
4747
for indx, pattern in enumerate(p["patterns"]):
4848
self.items[-1]["items"][indx]["cat"] = [len(self.items), indx + 1]
4949

5050
# loading code presets
5151
for pat in pattern.get("codenames", []):
52-
self.codes[pat] = open(path2patterns / pat, "r").read()
52+
self.codes[pat] = open(os.path.join(path2patterns, pat), "r").read()
5353
self.blocks = p["blocks"]
5454
self.brushmode = False
5555
self.squarebrush = False

files.py

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66
import sys
77
import math
88
import time
9-
from tkinter import filedialog
9+
1010
import jsonc # it's so fucking dumb that i use 3 json libraries in this project why
11-
from pathlib import Path
1211

1312
# determine if application is a script file or frozen exe
13+
1414
if getattr(sys, 'frozen', False):
15-
application_path = Path(os.path.dirname(sys.executable))
15+
application_path = os.path.dirname(sys.executable)
1616
else:
17-
application_path = Path(os.path.dirname(__file__))
17+
application_path = os.path.dirname(__file__)
1818

1919
islinux = os.name == "posix"
2020

@@ -23,7 +23,8 @@ def resolvepath(input_path): # Thanks to someone... someone nice
2323
# returning function back for compatibility
2424
if not islinux:
2525
return str(input_path)
26-
path = input_path.replace("\\", "/")
26+
#path = input_path.replace("\\", "/")
27+
path = input_path
2728
if os.path.isdir(path):
2829
return path
2930
directory, filename = os.path.split(path)
@@ -36,49 +37,49 @@ def resolvepath(input_path): # Thanks to someone... someone nice
3637

3738
allleters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.,- =+_*()[]{}#@"
3839

39-
path = application_path / "files"
40-
path2favs = path / "favourites"
41-
path2tutorial = path / "tutorial"
42-
path2ui = path / "ui"
43-
path2graphics = application_path / "drizzle" / "Data" / "Graphics"
44-
path2cast = application_path / "drizzle" / "Data" / "Cast"
45-
path2renderedlevels = application_path / "drizzle" / "Data" / "Levels"
46-
path2props = application_path / "drizzle" / "Data" / "Props"
47-
path2levels = application_path / "LevelEditorProjects"
48-
path2hotkeys = path /"hotkeys"
49-
50-
path2effectPreviews = path / "effectPreviews"
51-
path2materialPreviews = path / "materialPreviews"
52-
path2patterns = path / "patternScripts"
53-
path2gifs = path / "gifs"
40+
path = os.path.join(application_path, "files")
41+
path2favs = os.path.join(path, "favourites")
42+
path2tutorial = os.path.join(path, "tutorial")
43+
path2ui = os.path.join(path, "ui")
44+
path2graphics = os.path.join(application_path, "drizzle", "Data", "Graphics")
45+
path2cast = os.path.join(application_path, "drizzle", "Data", "Cast")
46+
path2renderedlevels = os.path.join(application_path, "drizzle", "Data", "Levels")
47+
path2props = os.path.join(application_path, "drizzle", "Data", "Props")
48+
path2levels = os.path.join(application_path, "LevelEditorProjects")
49+
path2hotkeys = os.path.join(path, "hotkeys")
50+
51+
path2effectPreviews = os.path.join(path, "effectPreviews")
52+
path2materialPreviews = os.path.join(path, "materialPreviews")
53+
path2patterns = os.path.join(path, "patternScripts")
54+
path2gifs = os.path.join(path, "gifs")
5455

5556
pg.font.init()
5657

57-
globalsettings : dict = jsonc.load(open(path / "settings.json", "r"))
58-
settings: dict = jsonc.load(open(path2ui / globalsettings["uifile"], "r"))
59-
hotkeys: dict = jsonc.load(open(path2hotkeys / globalsettings["hotkeyfile"], "r"))
60-
e = jsonc.load(open(path / "effects.json", "r"))
58+
globalsettings: dict = jsonc.load(open(os.path.join(path, "settings.json"), "r"))
59+
settings: dict = jsonc.load(open(os.path.join(path2ui, globalsettings["uifile"]), "r"))
60+
hotkeys: dict = jsonc.load(open(os.path.join(path2hotkeys, globalsettings["hotkeyfile"]), "r"))
61+
e = jsonc.load(open(os.path.join(path, "effects.json"), "r"))
6162

6263

6364
def loadimage(filepath):
64-
if filepath != path / globalsettings["godimage"] and globalsettings["godmode"]:
65+
if filepath != os.path.join(path, globalsettings["godimage"]) and globalsettings["godmode"]:
6566
global god
6667
return god
6768
if not os.path.exists(filepath):
6869
newpath = resolvepath(filepath)
6970
if newpath is not None:
7071
return pg.image.load(newpath)
71-
raise FileNotFoundError(f"Image by path {os.path.relpath(path.absolute(), application_path.absolute())} does not exist", path)
72+
raise FileNotFoundError(f"Image by path {os.path.relpath(path, application_path)} does not exist", path)
7273
return pg.image.load(filepath)
7374

7475

75-
god = loadimage(path / globalsettings["godimage"])
76+
god = loadimage(os.path.join(path, globalsettings["godimage"]))
7677
if god is None:
7778
raise Exception("how dare you")
7879
godres = pg.Surface([0, 0])
7980

80-
tooltiles = loadimage(path / globalsettings["tooltiles"])
81-
toolmenu = loadimage(path / globalsettings["toolmenu"])
81+
tooltiles = loadimage(os.path.join(path, globalsettings["tooltiles"]))
82+
toolmenu = loadimage(os.path.join(path, globalsettings["toolmenu"]))
8283

8384
load_error_count = 0
8485

@@ -161,7 +162,7 @@ def fs(sz) -> list[pg.font.Font, int]:
161162
if sz in fonts.keys():
162163
return fonts[sz]
163164
else:
164-
f = pg.font.Font(path / settings["global"]["font"], sz)
165+
f = pg.font.Font(os.path.join(path, settings["global"]["font"]), sz)
165166
fonts[sz] = [f, f.size(allleters)[1]]
166167
return fonts[sz]
167168

@@ -285,7 +286,7 @@ def tutorial():
285286

286287
def log_to_load_log(message, error=False, nl=True):
287288
global load_error_count
288-
with open(application_path / "loadLog.txt", "a") as load_log:
289+
with open(os.path.join(application_path, "loadLog.txt"), "a") as load_log:
289290
load_log.write(f"{'[ERROR]: ' if error else ''}{message}")
290291
if nl:
291292
load_log.write("\n")

lingotojson.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from files import *
1212
import math
1313

14-
notfound = loadimage(path / "notfound.png")
14+
notfound = loadimage(os.path.join(path, "notfound.png"))
1515
notfound.set_colorkey(pg.Color(255, 255, 255))
1616
notfoundtile = {
1717
"name": "unloaded tile",
@@ -26,7 +26,7 @@
2626
"cat": [1, 1],
2727
"tags": [""]
2828
}
29-
defaultlevel = open(path / "default.txt", "r").readlines()
29+
defaultlevel = open(os.path.join(path, "default.txt"), "r").readlines()
3030

3131

3232
def tojson(string: str, replacement: str = None):
@@ -245,10 +245,10 @@ def printmessage(message):
245245
window.blit(surf, [0, 0])
246246
pg.display.update()
247247
inv = settings["TE"]["LEtiles"]
248-
tilefiles = [path2graphics / i for i in globalsettings["tileinits"]]
248+
tilefiles = [os.path.join(path2graphics, i) for i in globalsettings["tileinits"]]
249249
solved = init_solve(tilefiles)
250250
solved_copy = copy.deepcopy(solved)
251-
f = pg.font.Font(path / settings["global"]["font"], 20)
251+
f = pg.font.Font(os.path.join(path, settings["global"]["font"]), 20)
252252
for catnum, catitem in enumerate(solved.data):
253253
cat = catitem["name"]
254254

@@ -258,7 +258,7 @@ def printmessage(message):
258258
for indx, item in enumerate(items):
259259
printmessage(f"Loading tile {item['nm']}...")
260260
try:
261-
img = loadimage(f"{path2graphics / item['nm']}.png")
261+
img = loadimage(f"{os.path.join(path2graphics, item['nm'])}.png")
262262
except FileNotFoundError:
263263
continue
264264
sz = toarr(item["sz"], "point")
@@ -331,7 +331,7 @@ def printmessage(message):
331331
ms = globalsettings["matsize"]
332332
pg.draw.rect(img, v, pg.Rect(ms[0], ms[0], ms[1], ms[1]))
333333
try:
334-
preview = loadimage(path2materialPreviews / (k + ".png"))
334+
preview = loadimage(os.path.join(path2materialPreviews, (k + ".png")))
335335
except FileNotFoundError:
336336
preview = pg.Surface([image1size, image1size])
337337
preview.set_alpha(0)
@@ -369,7 +369,7 @@ def renderlevel(data):
369369
# subprocess.Popen([f"{application_path}/drizzle/Drizzle.ConsoleApp{'' if islinux else '.exe'}", "render", fl], shell=True)
370370
p = multiprocessing.Process(target=renderlevelProccess, args=(f"{application_path}/drizzle/Drizzle.ConsoleApp{'' if islinux else '.exe'} render \"{fl}\"", ))
371371
pickedgif = random.choice(list(globalsettings["rendergifimages"].keys()))
372-
theimage = loadimage(path2gifs / pickedgif)
372+
theimage = loadimage(os.path.join(path2gifs, pickedgif))
373373
fontr: pg.font.Font = fs(30)[0]
374374
text = fontr.render(settings["global"].get("renderingscugtext", "wendewing level :3 Esc to cancel"), True, pg.Color(255, 255, 255), None)
375375
frame = 0
@@ -412,7 +412,7 @@ def renderlevelProccess(data):
412412

413413

414414
def getcolors():
415-
solved = open(application_path / "drizzle" / "Data" / "Props" / "propColors.txt", 'r').readlines()
415+
solved = open(os.path.join(application_path, "drizzle", "Data", "Props", "propColors.txt"), 'r').readlines()
416416
cols = []
417417
for line in solved:
418418
if line[0] != '[':
@@ -487,19 +487,19 @@ def printmessage(message):
487487
pg.draw.rect(window, pg.color.THECOLORS["black"], [0, 0, window.get_width(), surf.get_height()])
488488
window.blit(surf, [0, 0])
489489
pg.display.update()
490-
propfiles = [path2props / i for i in globalsettings["propinits"]]
491-
propfiles.append(path / "additionprops.txt")
490+
propfiles = [os.path.join(path2props, i) for i in globalsettings["propinits"]]
491+
propfiles.append(os.path.join(path, "additionprops.txt"))
492492
solved = init_solve(propfiles)
493493
solved_copy = copy.deepcopy(solved)
494-
f = pg.font.Font(path / settings["global"]["font"], 20)
494+
f = pg.font.Font(os.path.join(path, settings["global"]["font"]), 20)
495495
for catnum, catitem in enumerate(solved.data):
496496
items = catitem["items"]
497497
colr = catitem["color"]
498498
solved_copy[catnum]["items"] = []
499499
for indx, item in enumerate(items):
500500
printmessage(f"Loading prop {item['nm']}...")
501501
try:
502-
img = loadimage(path2props / f"{item['nm']}.png")
502+
img = loadimage(f"{os.path.join(path2props, item['nm'])}.png")
503503
images = addprop(item, img)
504504
newitem = solved[catnum]["items"][indx]
505505
newitem["images"] = images
@@ -548,7 +548,7 @@ def printmessage(message):
548548
returnimage = pg.Surface(size)
549549
returnimage.fill(pg.Color(255, 255, 255))
550550
try:
551-
img = loadimage(path2graphics / (tile["nm"] + ".png"))
551+
img = loadimage(os.path.join(path2graphics, (tile["nm"] + ".png")))
552552
except:
553553
img = pg.transform.scale(notfound, size)
554554
returnimage.blit(pg.transform.scale(notfound, size), [0, 0])
@@ -600,7 +600,7 @@ def solveeffects(effects):
600600
if "options" not in d:
601601
d["options"] = []
602602
if "preview" in d:
603-
d["preview"] = loadimage(path2effectPreviews / f"{d['preview']}.png")
603+
d["preview"] = loadimage(os.path.join(path2effectPreviews, f"{d['preview']}.png"))
604604
for i in effects["defaultparams"]:
605605
d["options"].append(i)
606606
for indx, option in enumerate(d["options"]):

main.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import multiprocessing
2+
import os
23

34
if __name__ == "__main__":
45
import argparse
56
from LevelProcess import *
67

78
widgets.keybol = True
8-
open(application_path / "loadLog.txt", "w")
9+
open(os.path.join(application_path, "loadLog.txt"), "w")
910
multiprocessing.freeze_support()
1011
manager = ProcessManager()
1112
parser = argparse.ArgumentParser(prog="RWE+ console", description="Maybe a better, than official LE.\n"

0 commit comments

Comments
 (0)