feat: random generators, frozenset and __hash__/__iter__/__getitem__/__contains__ in Ren'Py python
renpy.random/random get choices, sample, randrange and Random(seed); frozenset, iter and hash are builtins. User classes may define __hash__ (dict keys), __iter__, __getitem__ and __contains__; the converter accepts them instead of rejecting the whole class, which removes the Perk/Skill/Status wall in SaintlyCorruption. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
f9eb5c1212
commit
e1c596288e
8 files changed
+165
-18
No files matched your search
Vendored
+35
@@ -0,0 +1,35 @@
|
||||
class Perk:
|
||||
def __init__(self, key):
|
||||
self.key = key
|
||||
|
||||
def __hash__(self):
|
||||
return hash(self.key)
|
||||
|
||||
def __eq__(self, other):
|
||||
return self.key == other.key
|
||||
|
||||
|
||||
class Bag:
|
||||
def __init__(self, items):
|
||||
self.items = items
|
||||
|
||||
def __iter__(self):
|
||||
return iter(self.items)
|
||||
|
||||
def __getitem__(self, i):
|
||||
return self.items[i]
|
||||
|
||||
def __contains__(self, x):
|
||||
return x in self.items
|
||||
|
||||
|
||||
table = {}
|
||||
table[Perk("a")] = 1
|
||||
table[Perk("a")] = 2
|
||||
result_size = len(table)
|
||||
result_value = table[Perk("a")]
|
||||
bag = Bag([3, 4, 5])
|
||||
result_loop = [x * 2 for x in bag]
|
||||
result_item = bag[1]
|
||||
result_in = 4 in bag
|
||||
result_out = 9 in bag
|
||||
Reference in new issue
Block a user