Compare commits

...

6 Commits

Author SHA1 Message Date
52ed1d37de Scrap some prepended newlines 2023-11-15 15:42:23 +00:00
8286be4a50 init is ignored when early is used 2023-11-15 15:42:23 +00:00
a1e4f05998 Update the timeit function to use the timeit module
add the autorange function as a bonus (I like it better)

Patch-1-pull-request
2023-11-15 15:41:24 +00:00
0d0c54058d Hasten is_integer
the commented further improvement should be done too imo, but up to you
2023-11-15 15:38:35 +00:00
19bfc010c8 Avoid creating an unnecessary list (use an iterator instead) 2023-11-15 15:38:34 +00:00
36d79b4bb2 Hasten istype 2023-11-15 15:38:34 +00:00
8 changed files with 20 additions and 23 deletions

View File

@ -1,4 +1,3 @@
init -999 python: init -999 python:
# Remove style overrides # Remove style overrides
adv.who_args.pop("style", None) adv.who_args.pop("style", None)

View File

@ -1,4 +1,3 @@
# Preferences # Preferences
# https://www.renpy.org/doc/html/preferences.html # https://www.renpy.org/doc/html/preferences.html

View File

@ -1,4 +1,3 @@
label start: label start:
python: python:
version = version_float() version = version_float()

View File

@ -1,4 +1,3 @@
# Legacy styles (still in use) # Legacy styles (still in use)
style yesno_button: style yesno_button:

View File

@ -11,6 +11,7 @@ init python early:
import re import re
import string import string
import functools import functools
import timeit as timeit_module
from bisect import bisect from bisect import bisect
from operator import itemgetter from operator import itemgetter
from operator import add as _add from operator import add as _add
@ -125,26 +126,28 @@ init python early:
if isinstance(obj, _list): if isinstance(obj, _list):
return [make_revertable(x) for x in obj] return [make_revertable(x) for x in obj]
elif isinstance(obj, _dict): elif isinstance(obj, _dict):
return dict([(make_revertable(k), make_revertable(v)) for (k,v) in obj.items()]) return dict((make_revertable(k), make_revertable(v)) for (k,v) in obj.items())
else: else:
return obj return obj
def is_integer(s): def is_integer(s):
def zero(s):
return (len(s) > 1 and s.startswith("0"))
s = str(s) s = str(s)
if not s:
if s and s[0] in ("-", "+"): return False
return (not zero(s[1:]) and s[1:].isdigit()) if s[0] in ("-", "+"):
return (not zero(s) and s.isdigit()) # calling lstrip("0+-") would be faster but not exactly identical
s = s[1:]
if s.lstrip("0").isdigit():
return True
return False
def timeit(func, loops=10000, args=(), kwargs={}): def timeit(func, loops=10000, args=(), kwargs={}):
start = time.time() rv = timeit_module.timeit("func(*args, **kwargs)", number=loops, globals=dict(func=func, args=args, kwargs=kwargs))
for i in range(loops): print(f"The task has taken {rv} seconds to finish")
func(*args, **kwargs)
end = time.time() def autorange(func, args=(), kwargs={}):
print(f"The task has taken {end-start} seconds to finish") loops, time = timeit_module.Timer("func(*args, **kwargs)", globals=dict(func=func, args=args, kwargs=kwargs)).autorange()
print(f"The task has taken {time/loops} seconds to finish ({loops} iterations in {time} seconds)")
def list_swap_values(l, val1, val2): def list_swap_values(l, val1, val2):
"""Mutates the original list.""" """Mutates the original list."""
@ -186,9 +189,9 @@ init python early:
return s1.replace(filter, "") == s2.replace(filter, "") return s1.replace(filter, "") == s2.replace(filter, "")
def istype(inst, clss): def istype(inst, clss):
if not isinstance(clss, (list, tuple, set)): if isinstance(clss, (list, tuple, set)):
clss = (clss,)
return type(inst) in clss return type(inst) in clss
return type(inst) is clss
class IntLike(python_object): class IntLike(python_object):
# Does not support rollback # Does not support rollback

View File

@ -1,4 +1,4 @@
init -999 python early: python early:
if renpy.version_tuple < (7,5,3,22090809): if renpy.version_tuple < (7,5,3,22090809):
raise RuntimeWarning("Your Ren'Py launcher is outdated, the current minimal requirement is 7.5.3.22090809+\nPlease perform an update and try launching the game again.") raise RuntimeWarning("Your Ren'Py launcher is outdated, the current minimal requirement is 7.5.3.22090809+\nPlease perform an update and try launching the game again.")

View File

@ -1,4 +1,3 @@
# Custom text tags # Custom text tags
# https://www.renpy.org/doc/html/custom_text_tags.html # https://www.renpy.org/doc/html/custom_text_tags.html

View File

@ -1,4 +1,3 @@
image fade = "#00000080" image fade = "#00000080"
image fade_gradient = "interface/bld.webp" image fade_gradient = "interface/bld.webp"