Skip to content

Commit 8d9db1a

Browse files
committed
Revert "Move OTTUtils to a submodule"
This reverts commit 989d3d5.
1 parent 989d3d5 commit 8d9db1a

File tree

9 files changed

+179
-8
lines changed

9 files changed

+179
-8
lines changed

.gitmodules

Lines changed: 0 additions & 3 deletions
This file was deleted.

ott/OTTUtil.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
"""
2+
Helpers and such for Open Toontown Tools
3+
"""
4+
from direct.task.TaskManagerGlobal import taskMgr
5+
6+
7+
def sleep(duration: float):
8+
"""
9+
Breaks for a number of seconds. Returns an awaitable.
10+
@LittleToonCat
11+
12+
:param duration: Duration of sleep
13+
"""
14+
15+
def __task(task):
16+
if task.time > duration:
17+
return task.done
18+
return task.cont
19+
20+
return taskMgr.add(__task)

ott/Settings.py

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
"""
2+
OpenTTTools Settings
3+
Slight override of a typical dict to make the file auto save when a change is made
4+
"""
5+
6+
import collections
7+
import json
8+
import os
9+
10+
11+
class Settings(collections.MutableMapping):
12+
13+
def __init__(self, filename: str):
14+
"""
15+
:param filename: File path to json file
16+
"""
17+
self.filename = filename
18+
19+
self.data = {}
20+
21+
# Make sure the file exists
22+
if os.path.exists(self.filename):
23+
try:
24+
with open(self.filename, 'r') as f:
25+
self.data = json.load(f)
26+
except:
27+
# Something went wrong with the file, probable corruption, make a new one
28+
self.save()
29+
# If not, create it
30+
else:
31+
self.save()
32+
33+
def save(self):
34+
"""
35+
Write settings changes to the json file
36+
"""
37+
with open(self.filename, 'w') as jsonFile:
38+
json.dump(self.data, jsonFile, indent = 4)
39+
print('Saved settings')
40+
41+
''' Overrides '''
42+
43+
def __getitem__(self, key: str):
44+
"""
45+
x = settings['setting'] override
46+
47+
:param key: Setting Key
48+
:return: Setting value
49+
"""
50+
return self.data[key]
51+
52+
def __setitem__(self, key: str, value: str):
53+
"""
54+
settings['setting'] = 'value' override
55+
56+
:param key: Setting Key
57+
:param value: The value to set the setting to
58+
"""
59+
self.data[key] = value
60+
# Save the file
61+
self.save()
62+
63+
def __delitem__(self, key: str):
64+
"""
65+
del settings['setting'] override
66+
67+
:param key: Setting Key to remove
68+
"""
69+
del self.data[key]
70+
# Save the file
71+
self.save()
72+
73+
def __iter__(self):
74+
"""
75+
iteration override (e.g. for x in settings)
76+
77+
:return: Iterable of settings
78+
"""
79+
return iter(self.data)
80+
81+
def __len__(self) -> int:
82+
"""
83+
len(settings) Override
84+
85+
:return: Number of settings as integer
86+
"""
87+
return len(self.data)

ott/ShaderRegistry.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
"""
2+
Shader Registry - drewcification 111420
3+
Static class to register and get shaders
4+
5+
Shaders are registered at the games initialization
6+
from ott.ShaderRegistry import ShaderRegistry
7+
ShaderRegistry.register('render:black_and_white',
8+
frag = 'phase_3/shaders/tt_sha_render_bandw.frag',
9+
vert = 'phase_3/shaders/tt_sha_render_bandw.vert')
10+
11+
They can be retrieved at any point during runtime
12+
from ott.ShaderRegistry import ShaderRegistry
13+
render.setShader(ShaderRegistry.get('render:black_and_white'))
14+
"""
15+
16+
from panda3d.core import Shader
17+
18+
19+
class ShaderRegistry:
20+
# Static shader dictionary
21+
shaders = {}
22+
23+
@staticmethod
24+
def register(identifier: str, frag: str, vert: str):
25+
"""
26+
Register shader
27+
28+
All shaders must be in GLSL with separate .frag and .vert files!
29+
30+
Shader identifiers should be formatted by where they are used
31+
32+
e.g.:
33+
Full scene render effects are prefixed with 'render:'
34+
CheesyEffects are prefixed with 'ce:'
35+
Make-A-Toon shaders are prefixed with 'mat:'
36+
etc.
37+
38+
:param identifier: Identifier string
39+
:param frag: Fragment shader file path
40+
:param vert: Vertex shader file path
41+
"""
42+
shader = Shader.load(Shader.SL_GLSL, fragment = frag, vertex = vert)
43+
ShaderRegistry.shaders[identifier] = shader
44+
print(f'Registered shader {identifier}')
45+
46+
@staticmethod
47+
def get(identifier: str) -> Shader:
48+
"""
49+
Returns loaded shader
50+
51+
:param identifier:
52+
:return: Shader
53+
"""
54+
55+
# Raise an exception if we load a shader we haven't registered yet
56+
if identifier not in ShaderRegistry.shaders:
57+
raise NotInRegistryError(identifier)
58+
59+
return ShaderRegistry.shaders.get(identifier)
60+
61+
62+
class NotInRegistryError(Exception):
63+
def __init__(self, identifier: str):
64+
self.identifier = identifier
65+
66+
def __str__(self):
67+
return f'identifier {self.identifier} not in registry'

ott/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
""" Universal classes for all OTT Projects """

ottutil

Lines changed: 0 additions & 1 deletion
This file was deleted.

toontown/hood/GenericAnimatedProp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from direct.interval.IntervalGlobal import *
44
from direct.directnotify import DirectNotifyGlobal
55

6-
from ottutil.ShaderRegistry import ShaderRegistry
6+
from ott.ShaderRegistry import ShaderRegistry
77

88
from toontown.toonbase import ToontownGlobals
99
from toontown.hood import ZoneUtil

toontown/leveleditor/LevelEditorPanel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from .LevelEditorGlobals import *
1414
from .LESceneGraphExplorer import *
1515

16-
from ottutil.ShaderRegistry import ShaderRegistry
16+
from ott.ShaderRegistry import ShaderRegistry
1717

1818
from toontown.fixes import VectorWidgets
1919

ttle.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
from panda3d.core import loadPrcFile, loadPrcFileData
1313
from tkinter import Tk, messagebox
1414

15-
from ottutil.Settings import Settings
16-
from ottutil.ShaderRegistry import ShaderRegistry
15+
from ott.Settings import Settings
16+
from ott.ShaderRegistry import ShaderRegistry
1717

1818
from toontown.toonbase import ToontownGlobals
1919

0 commit comments

Comments
 (0)