forked from OpenToontownTools/OpenLevelEditor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathttle.py
More file actions
157 lines (125 loc) · 6.51 KB
/
ttle.py
File metadata and controls
157 lines (125 loc) · 6.51 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
""" OpenLevelEditor Base Class - Drewcification 091420 """
from direct.directnotify.DirectNotifyGlobal import directNotify
from direct.showbase.ShowBase import ShowBase
from panda3d.core import loadPrcFile, loadPrcFileData
from tkinter import Tk, messagebox
import asyncio
import argparse
import builtins
import json
import os
import sys
TOONTOWN_ONLINE = 0
TOONTOWN_REWRITTEN = 1
TOONTOWN_CORPORATE_CLASH = 2
TOONTOWN_OFFLINE = 3
SERVER_TO_ID = {'online': TOONTOWN_ONLINE,
'rewritten': TOONTOWN_REWRITTEN,
'clash': TOONTOWN_CORPORATE_CLASH,
'offline': TOONTOWN_OFFLINE}
DEFAULT_SERVER = TOONTOWN_ONLINE
class ToontownLevelEditor(ShowBase):
notify = directNotify.newCategory("Open Level Editor")
APP_VERSION = open('ver', 'r').read()
def __init__(self):
# Load the prc file prior to launching showbase in order
# to have it affect window related stuff
loadPrcFile('editor.prc')
builtins.userfiles = self.config.GetString('userfiles-directory')
if not os.path.exists(userfiles):
pathlib.Path(userfiles).mkdir(parents = True, exist_ok = True)
# Check for -e or -d launch options
parser = argparse.ArgumentParser(description="Modes")
parser.add_argument("--experimental", action='store_true', help="Enables experimental features")
parser.add_argument("--debug", action='store_true', help="Enables debugging features")
parser.add_argument("--noupdate", action='store_true', help="Disables Auto Updating")
parser.add_argument("--compiler", nargs = "*", help="Specify which compiler to use (Only useful if your game uses a form of "
"libpandadna.) Valid options are 'libpandadna', for games which use the "
"modern c++ version of libpandadna (like Toontown Offline), and 'clash', "
"for games that use the legacy python version of libpandadna, mainly Corporate Clash")
parser.add_argument("--server", nargs="*", help="Enables features exclusive to various Toontown projects", default='online')
parser.add_argument("--holiday", nargs="*", help="Enables holiday modes. [halloween or winter]")
parser.add_argument("--hoods", nargs="*", help="Only loads the storage files of the specified hoods",
default=['TT', 'DD', 'BR', 'DG',
'DL', 'MM', 'GS', 'GZ',
'SBHQ', 'LBHQ', 'CBHQ', 'BBHQ',
'OZ', 'PA', 'ES', 'TUT'])
parser.add_argument("dnaPath", nargs="?", help="Load the DNA file through the specified path")
args = parser.parse_args()
if args.experimental:
loadPrcFileData("", "want-experimental true")
if args.debug:
loadPrcFileData("", "want-debug true")
if args.compiler:
loadPrcFileData("", f"compiler {args.compiler[0]}")
if args.holiday:
loadPrcFileData("", f"holiday {args.holiday[0]}")
server = SERVER_TO_ID.get(args.server[0].lower(), DEFAULT_SERVER)
self.server = server
self.hoods = args.hoods
# HACK: Check for dnaPath in args.hoods
for hood in self.hoods[:]:
if hood.endswith('.dna'):
args.dnaPath = hood
args.hoods.remove(hood)
break
# Check for any files we need and such
self.__checkForFiles()
# Import the main dlls so we don't have to repeatedly import them everywhere
self.__importMainLibs()
# Setup the root for Tkinter!
self.__createTk()
if not args.noupdate:
loop = asyncio.get_event_loop()
loop.run_until_complete(self.__checkUpdates())
self.__addCullBins()
# Now we actually start the editor
ShowBase.__init__(self)
aspect2d.setAntialias(AntialiasAttrib.MAuto)
from toontown.leveleditor import LevelEditor
self.le = LevelEditor.LevelEditor()
self.le.startUp(args.dnaPath)
def __checkForFiles(self):
# Make custom hood directory if it doesn't exist
if not os.path.exists(f'{userfiles}/hoods/'):
os.mkdir(f'{userfiles}/hoods/')
# Make a maps directory if we don't have one
if not os.path.isdir("maps"):
os.mkdir("maps")
# Make a Screenshots directory if we don't have one
if not os.path.isdir("screenshots"):
os.mkdir("screenshots")
def __importMainLibs(self):
builtin_dict = builtins.__dict__
builtin_dict.update(__import__('panda3d.core', fromlist=['*']).__dict__)
builtin_dict.update(__import__('libotp', fromlist=['*']).__dict__)
builtin_dict.update(__import__('libtoontown', fromlist=['*']).__dict__)
def __createTk(self):
tkroot = Tk()
tkroot.withdraw()
tkroot.title("Open Level Editor")
if sys.platform == 'win32':
# FIXME: This doesn't work in other platforms for some reason...
tkroot.iconbitmap("resources/openttle_ico_temp.ico")
self.tkRoot = tkroot
def __addCullBins(self):
cbm = CullBinManager.getGlobalPtr()
cbm.addBin('ground', CullBinManager.BTUnsorted, 18)
cbm.addBin('shadow', CullBinManager.BTBackToFront, 19)
async def __checkUpdates(self):
import aiohttp, webbrowser
async with aiohttp.ClientSession() as session:
try:
async with session.get("https://raw.githubusercontent.com/OpenToontownTools/OpenLevelEditor/master/ver") as resp:
ver = await resp.text()
ver = ver.splitlines()[0]
if ver != self.APP_VERSION:
self.notify.info(f"Client is out of date! Latest: {ver} | Client: {self.APP_VERSION}")
if messagebox.askokcancel("Error", f"Client is out of date!\nLatest: {ver} | Client: {self.APP_VERSION}. Press OK to be taken to the download page."):
webbrowser.open("https://github.com/OpenToontownTools/OpenLevelEditor/releases/latest")
else:
self.notify.info("Client is up to date!")
except:
messagebox.showerror(message = "There was an error checking for updates! This is likely an issue with your connection. Press OK to continue using the application.")
# Run it
ToontownLevelEditor().run()