mirror of
https://github.com/MarioSpore/Grinch-AP.git
synced 2025-10-21 04:01:32 -06:00
Core: Add "OptionCounter", use it for generic "StartInventory" and Witness "TrapWeights" (#3756)
* CounterOption * bring back the negative exception for ItemDict * Backwards compatibility * ruff on witness * fix in calls * move the contains * comment * comment * Add option min and max values for CounterOption * Use min 0 for TrapWeights * This is safe now * ruff * This fits on one line again now * OptionCounter * Update Options.py * Couple more typing things * Update Options.py * Make StartInventory work again, also make LocationCounter theoretically work * Docs * more forceful wording * forced line break * Fix unit test (that wasn't breaking?) * Add trapweights to witness option presets to 'prove' that the unit test passes * Make it so you can order stuff * Update macros.html
This commit is contained in:
@@ -108,7 +108,7 @@ def option_presets(game: str) -> Response:
|
||||
f"Expected {option.special_range_names.keys()} or {option.range_start}-{option.range_end}."
|
||||
|
||||
presets[preset_name][preset_option_name] = option.value
|
||||
elif isinstance(option, (Options.Range, Options.OptionSet, Options.OptionList, Options.ItemDict)):
|
||||
elif isinstance(option, (Options.Range, Options.OptionSet, Options.OptionList, Options.OptionCounter)):
|
||||
presets[preset_name][preset_option_name] = option.value
|
||||
elif isinstance(preset_option, str):
|
||||
# Ensure the option value is valid for Choice and Toggle options
|
||||
@@ -222,7 +222,7 @@ def generate_yaml(game: str):
|
||||
|
||||
for key, val in options.copy().items():
|
||||
key_parts = key.rsplit("||", 2)
|
||||
# Detect and build ItemDict options from their name pattern
|
||||
# Detect and build OptionCounter options from their name pattern
|
||||
if key_parts[-1] == "qty":
|
||||
if key_parts[0] not in options:
|
||||
options[key_parts[0]] = {}
|
||||
|
@@ -111,10 +111,19 @@
|
||||
</div>
|
||||
{% endmacro %}
|
||||
|
||||
{% macro ItemDict(option_name, option) %}
|
||||
{% macro OptionCounter(option_name, option) %}
|
||||
{% set relevant_keys = option.valid_keys %}
|
||||
{% if not relevant_keys %}
|
||||
{% if option.verify_item_name %}
|
||||
{% set relevant_keys = world.item_names %}
|
||||
{% elif option.verify_location_name %}
|
||||
{% set relevant_keys = world.location_names %}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
||||
{{ OptionTitle(option_name, option) }}
|
||||
<div class="option-container">
|
||||
{% for item_name in (option.valid_keys|sort if (option.valid_keys|length > 0) else world.item_names|sort) %}
|
||||
{% for item_name in (relevant_keys if relevant_keys is ordered else relevant_keys|sort) %}
|
||||
<div class="option-entry">
|
||||
<label for="{{ option_name }}-{{ item_name }}-qty">{{ item_name }}</label>
|
||||
<input type="number" id="{{ option_name }}-{{ item_name }}-qty" name="{{ option_name }}||{{ item_name }}||qty" value="{{ option.default[item_name]|default("0") }}" data-option-name="{{ option_name }}" data-item-name="{{ item_name }}" />
|
||||
|
@@ -93,8 +93,10 @@
|
||||
{% elif issubclass(option, Options.FreeText) %}
|
||||
{{ inputs.FreeText(option_name, option) }}
|
||||
|
||||
{% elif issubclass(option, Options.ItemDict) and option.verify_item_name %}
|
||||
{{ inputs.ItemDict(option_name, option) }}
|
||||
{% elif issubclass(option, Options.OptionCounter) and (
|
||||
option.valid_keys or option.verify_item_name or option.verify_location_name
|
||||
) %}
|
||||
{{ inputs.OptionCounter(option_name, option) }}
|
||||
|
||||
{% elif issubclass(option, Options.OptionList) and option.valid_keys %}
|
||||
{{ inputs.OptionList(option_name, option) }}
|
||||
@@ -133,8 +135,10 @@
|
||||
{% elif issubclass(option, Options.FreeText) %}
|
||||
{{ inputs.FreeText(option_name, option) }}
|
||||
|
||||
{% elif issubclass(option, Options.ItemDict) and option.verify_item_name %}
|
||||
{{ inputs.ItemDict(option_name, option) }}
|
||||
{% elif issubclass(option, Options.OptionCounter) and (
|
||||
option.valid_keys or option.verify_item_name or option.verify_location_name
|
||||
) %}
|
||||
{{ inputs.OptionCounter(option_name, option) }}
|
||||
|
||||
{% elif issubclass(option, Options.OptionList) and option.valid_keys %}
|
||||
{{ inputs.OptionList(option_name, option) }}
|
||||
|
@@ -113,9 +113,18 @@
|
||||
{{ TextChoice(option_name, option) }}
|
||||
{% endmacro %}
|
||||
|
||||
{% macro ItemDict(option_name, option, world) %}
|
||||
{% macro OptionCounter(option_name, option, world) %}
|
||||
{% set relevant_keys = option.valid_keys %}
|
||||
{% if not relevant_keys %}
|
||||
{% if option.verify_item_name %}
|
||||
{% set relevant_keys = world.item_names %}
|
||||
{% elif option.verify_location_name %}
|
||||
{% set relevant_keys = world.location_names %}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
||||
<div class="dict-container">
|
||||
{% for item_name in (option.valid_keys|sort if (option.valid_keys|length > 0) else world.item_names|sort) %}
|
||||
{% for item_name in (relevant_keys if relevant_keys is ordered else relevant_keys|sort) %}
|
||||
<div class="dict-entry">
|
||||
<label for="{{ option_name }}-{{ item_name }}-qty">{{ item_name }}</label>
|
||||
<input
|
||||
|
@@ -83,8 +83,10 @@
|
||||
{% elif issubclass(option, Options.FreeText) %}
|
||||
{{ inputs.FreeText(option_name, option) }}
|
||||
|
||||
{% elif issubclass(option, Options.ItemDict) and option.verify_item_name %}
|
||||
{{ inputs.ItemDict(option_name, option, world) }}
|
||||
{% elif issubclass(option, Options.OptionCounter) and (
|
||||
option.valid_keys or option.verify_item_name or option.verify_location_name
|
||||
) %}
|
||||
{{ inputs.OptionCounter(option_name, option, world) }}
|
||||
|
||||
{% elif issubclass(option, Options.OptionList) and option.valid_keys %}
|
||||
{{ inputs.OptionList(option_name, option) }}
|
||||
|
Reference in New Issue
Block a user