mirror of
https://github.com/ArchipelagoMW/Archipelago.git
synced 2026-04-17 02:43:30 -07:00
Auto-validate Option.schema, Factorio: allow setting pollution values
This commit is contained in:
committed by
Fabian Dill
parent
b809d76b79
commit
10c6a70696
@@ -19,6 +19,15 @@ class AssembleOptions(type):
|
||||
# apply aliases, without name_lookup
|
||||
options.update({name[6:].lower(): option_id for name, option_id in attrs.items() if
|
||||
name.startswith("alias_")})
|
||||
|
||||
# auto-validate schema on __init__
|
||||
if "schema" in attrs.keys():
|
||||
def validate_decorator(func):
|
||||
def validate(self, *args, **kwargs):
|
||||
func(self, *args, **kwargs)
|
||||
self.value = self.schema.validate(self.value)
|
||||
return validate
|
||||
attrs["__init__"] = validate_decorator(attrs["__init__"])
|
||||
return super(AssembleOptions, mcs).__new__(mcs, name, bases, attrs)
|
||||
|
||||
class Option(metaclass=AssembleOptions):
|
||||
|
||||
Reference in New Issue
Block a user