Refactoring

This commit is contained in:
LoafyLemon 2022-09-21 21:57:04 +01:00
parent c352f8cea3
commit e5a7060af9
15 changed files with 307 additions and 313 deletions

View File

@ -13,8 +13,8 @@ init python:
sprites = []
# Add body parts and skin layers from clothes, face, cum
sprites.extend(("{}{}/{}.webp".format(self.imagepath, k, v[0]), v[1]) for k, v in self.body.iteritems() if v[0]) # Body parts
sprites.extend((o[0].skin, self.zorder_skin) for o in self.char.clothes.itervalues() if o[0] and o[0].skin and o[2]) # Clothes skin
sprites.extend(("{}{}/{}.webp".format(self.imagepath, k, v[0]), v[1]) for k, v in self.body.items() if v[0]) # Body parts
sprites.extend((o[0].skin, self.zorder_skin) for o in self.char.clothes.values() if o[0] and o[0].skin and o[2]) # Clothes skin
sprites.extend((x, self.zorder_skin) for x in self.char.face.get_skin()) # Face skin
sprites.extend((x, self.zorder_skin) for x in self.char.cum.get_skin()) # Cum skin
@ -31,7 +31,7 @@ init python:
sprites = []
# Add body parts and skin layers from clothes
sprites.extend(("{}{}/{}.webp".format(self.imagepath, k, v[0]), v[1]) for k, v in self.body.iteritems() if v[0])
sprites.extend(("{}{}/{}.webp".format(self.imagepath, k, v[0]), v[1]) for k, v in self.body.items() if v[0])
if group:
sprites.extend((o.skin, self.zorder_skin) for o in group if o and o.skin)
@ -50,7 +50,7 @@ init python:
"""Takes keyword argument(s) with the string name of body part file(s). Returns True if image is changed."""
changed = False
for arg, value in kwargs.iteritems():
for arg, value in kwargs.items():
if value != self.body[str(arg)][0]:
self.body[str(arg)][0] = value
changed = True
@ -72,7 +72,7 @@ init python:
"""Takes keyword argument(s) with the string name of body type(s) and int value(s). Returns True if image is changed."""
changed = False
for arg, value in kwargs.iteritems():
for arg, value in kwargs.items():
if value != self.body[str(arg)][1]:
self.body[str(arg)][1] = value
changed = True

View File

@ -54,7 +54,7 @@ init python:
for x in self.layers_additional:
self.__dict__[x] = []
for i in xrange(self.layers):
for i in range(self.layers):
path = "{}{}_{}.webp".format(self.imagepath, i, x)
if renpy.loadable(path):
self.__dict__[x].append(path)
@ -65,7 +65,7 @@ init python:
self.__dict__[x+"_outline"] = path if renpy.loadable(path) else None
def build_image(self):
sprites = [(self.apply_color("{}{}.webp".format(self.imagepath, x), x), x) for x in xrange(self.layers)]
sprites = [(self.apply_color("{}{}.webp".format(self.imagepath, x), x), x) for x in range(self.layers)]
# Add extra layers if exist
for n, x in enumerate(self.layers_extra):

View File

@ -10,23 +10,23 @@ init python:
self.cum = dict((k, None) for k in {"hair", "face", "breasts", "body", "crotch", "pussy", "legs"})
def build_image(self):
sprites = tuple("{}{}/{}.webp".format(self.imagepath, k, v) for k, v in self.cum.iteritems() if v != None)
sprites = tuple("{}{}/{}.webp".format(self.imagepath, k, v) for k, v in self.cum.items() if v != None)
return sprites
def get_skin(self):
return ["{}{}/{}_skin.webp".format(self.imagepath, k, v) for k, v in self.cum.iteritems() if renpy.loadable("{}{}/{}_skin.webp".format(self.imagepath, k, v))]
return ["{}{}/{}_skin.webp".format(self.imagepath, k, v) for k, v in self.cum.items() if renpy.loadable("{}{}/{}_skin.webp".format(self.imagepath, k, v))]
def set_cum(self, *args, **kwargs):
"""Takes keyword argument(s) containing string name(s) of cum layers to apply or None. Returns True if image is changed."""
changed = False
if args:
for k, v in self.cum.iteritems():
for k, v in self.cum.items():
if v != args[0]:
self.cum[k] = args[0]
changed = True
for arg, value in kwargs.iteritems():
for arg, value in kwargs.items():
if str(arg) != value:
self.cum[str(arg)] = value
changed = True

View File

@ -14,7 +14,7 @@ init python:
### TODO: This piece of code needs to be simplified.
# Add facial expressions
for k, v in self.face.iteritems():
for k, v in self.face.items():
if v[0] and k not in ("eyes", "pupils"):
sprites.append(("{}{}/{}.webp".format(self.imagepath, k, v[0]), v[1]))
@ -51,18 +51,18 @@ init python:
return sprites
def get_skin(self):
for k, v in self.face.iteritems():
for k, v in self.face.items():
skin_path = "{}{}/{}_skin.webp".format(self.imagepath, k, v[0])
if renpy.loadable(skin_path):
yield skin_path
def get_face(self):
return dict((k, v[0]) for k, v in self.face.iteritems())
return dict((k, v[0]) for k, v in self.face.items())
def set_face(self, **kwargs):
"""Takes keyword argument(s) with the string name of expression file(s). Returns True if image is changed."""
changed = False
for arg, value in kwargs.iteritems():
for arg, value in kwargs.items():
if value not in (self.face[str(arg)][0], False):
self.face[str(arg)][0] = value
changed = True
@ -84,7 +84,7 @@ init python:
def set_zorder(self, **kwargs):
"""Takes keyword argument(s) with the string name of face type(s) and int value(s). Returns True if image is changed."""
changed = False
for arg, value in kwargs.iteritems():
for arg, value in kwargs.items():
if value != self.face[str(arg)][1]:
self.face[str(arg)][1] = value
changed = True

View File

@ -10,4 +10,3 @@ init python:
outfit_last = outfit = get_character_outfit(c, type="last")
outfit_last.save()

View File

@ -10,7 +10,7 @@ init python:
for x in self.layers_additional:
self.__dict__[x] = []
for i in xrange(self.layers):
for i in range(self.layers):
path = "{}{}_{}.webp".format(self.imagepath, i, x)
if renpy.loadable(path):
self.__dict__[x].append(path)

File diff suppressed because it is too large Load Diff

View File

@ -9,7 +9,7 @@ init python:
self.price = price
self.char = self.group[0].char
self.unlocked = unlocked
self.schedule = dict(self.default_schedule.items() + schedule.items())
self.schedule = dict(list(self.default_schedule.items()) + list(schedule.items()))
self.hash = self.generate_hash()
self.temp = temp
self.hidden = hidden
@ -33,7 +33,7 @@ init python:
return self.hash == obj.hash
def generate_hash(self):
salt = str( sorted([ sorted([x.name, x.type, x.id, x.color]) for x in self.group ]) )
salt = str( sorted( [sorted([x.name, x.type, x.id, str(x.color)] ) for x in self.group]) )
return hash(salt)
def delete(self):
@ -127,7 +127,7 @@ init python:
def save(self):
"""Overwrites this outfit with clothes currently equipped by the character."""
self.group = []
for v in self.char.clothes.itervalues():
for v in self.char.clothes.values():
if v[0]:
self.group.append(v[0].clone())
self.rebuild_image()
@ -149,7 +149,7 @@ init python:
return self.schedule
def set_schedule(self, **kwargs):
for k, v in kwargs.iteritems():
for k, v in kwargs.items():
self.schedule[k] = v
def has_type(self, *args):
@ -168,7 +168,7 @@ init python:
def has_any_type(self, *args):
"""Takes arguments containing string cloth types. Returns True if ANY of them is worn, False otherwise."""
if "clothes" in args:
for k in self.char.clothes.iterkeys():
for k in self.char.clothes.keys():
if not k.startswith(self.blacklist_toggles):
if self.has_type(k):
return True

View File

@ -2,19 +2,14 @@ init python:
import threading
class DollThread(threading.Thread, NoRollback):
def __init__(self, group=None, target=None, name=None, args=(), kwargs={}, Verbose=None):
super(DollThread, self).__init__(group, target, name, args, kwargs, Verbose)
def __init__(self, group=None, target=None, name=None, args=(), kwargs=None, *, daemon=None):
threading.Thread.__init__(self, group, target, name, args, kwargs, daemon=daemon)
self._return = None
def run(self):
try:
self._return = self._Thread__target(*self._Thread__args, **self._Thread__kwargs)
except:
import traceback
traceback.print_exc()
if config.developer:
raise Exception("Thread just pooped itself.")
if self._target is not None:
self._return = self._target(*self._args, **self._kwargs)
renpy.restart_interaction()

View File

@ -28,7 +28,7 @@ init -1 python:
def start(self):
queue = self.queue
queue = filter(lambda x: (x.wait <= 0) and (x.daytime == game.daytime), queue)
queue = [x for x in queue if (x.wait <= 0) and (x.daytime == game.daytime)]
queue.sort(key=lambda x: x.priority)
for ev in queue:

File diff suppressed because it is too large Load Diff

View File

@ -30,12 +30,12 @@ init -1 python:
output.append("zero")
else:
s = str(n)
groups = (len(s)+2)/3
groups = (len(s)+2)//3
s = s.zfill(groups*3)
for i in xrange(0, groups*3, 3):
for i in range(0, groups*3, 3):
h,t,u = int(s[i]), int(s[i+1]), int(s[i+2])
g = groups-(i/3+1)
g = groups-(i//3+1)
if h > 0:
output.append(units[h]+" hundred")
@ -120,7 +120,7 @@ init -1 python:
if isinstance(obj, _list):
return [make_revertable(x) for x in obj]
elif isinstance(obj, _dict):
return dict([(make_revertable(k), make_revertable(v)) for (k,v) in obj.iteritems()])
return dict([(make_revertable(k), make_revertable(v)) for (k,v) in obj.items()])
else:
return obj
@ -136,10 +136,10 @@ init -1 python:
def timeit(func, loops=10000, args=(), kwargs={}):
start = time.time()
for i in xrange(loops):
for i in range(loops):
func(*args, **kwargs)
end = time.time()
print("The task has taken {} seconds to finish".format(end-start))
print(f"The task has taken {end-start} seconds to finish")
def list_swap_values(l, val1, val2):
"""Mutates the original list."""
@ -191,7 +191,7 @@ init -1 python:
renpy.display.tts.tts(str(s))
def is_in_lead(house):
if isinstance(house, basestring):
if isinstance(house, str):
house = getattr(renpy.store, house)
return (house == max(gryffindor, slytherin, ravenclaw, hufflepuff))

View File

@ -101,7 +101,7 @@ init python:
# We need to make sure not to add quotes
# to expressions or variables.
if isinstance(val, basestring):
if isinstance(val, str):
val = "\"{}\"".format(val)
# Insert new expression
@ -109,11 +109,11 @@ init python:
d[expr] = val
# Convert to list of tuples
# l = [(k, "\"{}\"".format(v)) for k, v in d.iteritems() if not v is None] # This is faster, but not robust enough.
# l = [(k, "\"{}\"".format(v)) for k, v in d.items() if not v is None] # This is faster, but not robust enough.
l = _list()
for key, val in d.iteritems():
for key, val in d.items():
if key in kw_args and val is None:
continue
@ -268,7 +268,7 @@ init python:
for expr in ("mouth", "eyes", "eyebrows", "pupils", "cheeks", "tears"):
path = "characters/{}/face/{}/".format(name, expr)
files = filter(lambda x: path in x, all_files)
files = [x for x in all_files if path in x]
d[key][expr] = [x.split(path)[1].split(".webp")[0] for x in files if x.endswith(".webp") and not any(f in x for f in filters)]
@ -290,7 +290,7 @@ init python:
# Define expressions for Snape.
filters = ("b01", "b01_01", "b02", "picture_Frame", "wand")
path = "characters/snape/main/"
files = filter(lambda x: path in x, all_files)
files = [x for x in all_files if path in x]
d["sna"] = _dict()
d["sna"]["expression"] = [x.split(path)[1].split(".webp")[0] for x in files if x.endswith(".webp") and not any(f in x for f in filters)]
@ -338,7 +338,7 @@ init python:
# if we don't, we'll end up messing up
# the order of keywordless arguments.
imap = {v: i for i, v in enumerate(keywords)}
d[who] = OrderedDict(sorted(d[who].items(), key=lambda x: imap[x[0]]))
d[who] = OrderedDict(sorted(list(d[who].items()), key=lambda x: imap[x[0]]))
return d
def get_expression_types(self, who):
@ -349,7 +349,7 @@ init python:
def get_expressions_active_type(self, who, type):
expr = self.get_expressions_active(who).get(type)
if isinstance(expr, basestring):
if isinstance(expr, str):
expr = strip(expr)
return expr
@ -371,7 +371,7 @@ init python:
def get_expressions_last_type(self, who, type):
expr = self.get_expressions_last(who).get(type, None)
if isinstance(expr, basestring):
if isinstance(expr, str):
expr = strip(expr)
return expr
@ -391,7 +391,7 @@ init python:
if last == active:
return
for type, val in persistent.iteritems():
for type, val in persistent.items():
if val is False:
continue
@ -459,7 +459,7 @@ screen editor():
if e.node:
vbox:
hbox:
for expr_type in e.get_expression_types(e.node.who).iterkeys():
for expr_type in e.get_expression_types(e.node.who).keys():
textbutton "[expr_type]":
action [CaptureFocus(expr_type), SetScreenVariable("focused", expr_type)]
selected GetFocusRect(expr_type)
@ -510,7 +510,7 @@ screen editor():
textbutton "[e.live_code]" action SetScreenVariable("focused", 0)
if e.node:
for expr_type, expr_list in e.get_expression_types(e.node.who).iteritems():
for expr_type, expr_list in e.get_expression_types(e.node.who).items():
if GetFocusRect(expr_type):
dismiss action [ClearFocus(expr_type), SetScreenVariable("focused", None)]

View File

@ -4,7 +4,7 @@ init python:
line = fp.readline()
while line:
path, area = line.strip("\r\n").split(':')
whitespace_dict[path] = map(int, area.split(','))
whitespace_dict[path] = list(map(int, area.split(',')))
line = fp.readline()
def crop_whitespace(path):
@ -25,7 +25,7 @@ init python:
return Transform(sprite, crop=(x, y, w, h), xsize=xsize, ysize=ysize, fit="contain", matrixcolor=matrix, subpixel=True)
def get_zoom(image, size):
if isinstance(image, basestring):
if isinstance(image, str):
image = Image(image)
r = renpy.render(image, 800, 800, 0, 0)

File diff suppressed because it is too large Load Diff