Skip to content

Commit

Permalink
Support all remaining option types
Browse files Browse the repository at this point in the history
  • Loading branch information
LegendaryLinux committed Dec 10, 2023
1 parent 9d743f3 commit 38ed8b4
Show file tree
Hide file tree
Showing 7 changed files with 194 additions and 21 deletions.
9 changes: 3 additions & 6 deletions Options.py
Original file line number Diff line number Diff line change
Expand Up @@ -805,6 +805,7 @@ def verify(self, world: typing.Type[World], player_name: str, plando_options: "P
class OptionDict(Option[typing.Dict[str, typing.Any]], VerifyKeys, typing.Mapping[str, typing.Any]):
default: typing.Dict[str, typing.Any] = {}
supports_weighting = False
group_name = "Item & Location Options"

def __init__(self, value: typing.Dict[str, typing.Any]):
self.value = deepcopy(value)
Expand Down Expand Up @@ -846,6 +847,7 @@ class OptionList(Option[typing.List[typing.Any]], VerifyKeys):

default: typing.List[typing.Any] = []
supports_weighting = False
group_name = "Item & Location Options"

def __init__(self, value: typing.List[typing.Any]):
self.value = deepcopy(value)
Expand All @@ -872,6 +874,7 @@ def __contains__(self, item):
class OptionSet(Option[typing.Set[str]], VerifyKeys):
default: typing.Union[typing.Set[str], typing.FrozenSet[str]] = frozenset()
supports_weighting = False
group_name = "Item & Location Options"

def __init__(self, value: typing.Iterable[str]):
self.value = set(deepcopy(value))
Expand Down Expand Up @@ -997,15 +1000,13 @@ class StartInventory(ItemDict):
"""Start with these items."""
verify_item_name = True
display_name = "Start Inventory"
group_name = "Item & Location Options"


class StartInventoryPool(StartInventory):
"""Start with these items and don't place them in the world.
The game decides what the replacement items will be."""
verify_item_name = True
display_name = "Start Inventory from Pool"
group_name = "Item & Location Options"


class StartHints(ItemSet):
Expand All @@ -1017,25 +1018,21 @@ class StartHints(ItemSet):
class LocationSet(OptionSet):
verify_location_name = True
convert_name_groups = True
group_name = "Item & Location Options"


class StartLocationHints(LocationSet):
"""Start with these locations and their item prefilled into the !hint command"""
display_name = "Start Location Hints"
group_name = "Item & Location Options"


class ExcludeLocations(LocationSet):
"""Prevent these locations from having an important item"""
display_name = "Excluded Locations"
group_name = "Item & Location Options"


class PriorityLocations(LocationSet):
"""Prevent these locations from having an unimportant item"""
display_name = "Priority Locations"
group_name = "Item & Location Options"


class DeathLink(Toggle):
Expand Down
15 changes: 15 additions & 0 deletions WebHostLib/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,21 @@ def player_options(game: str):
all_options: Dict[str, Options.AssembleOptions] = world.options_dataclass.type_hints
grouped_options = collections.defaultdict(dict)
for option_name, option in all_options.items():
if issubclass(option, Options.ItemDict) and not option.verify_item_name:
continue

if issubclass(option, Options.OptionList) and not hasattr(option, "valid_keys"):
continue

if issubclass(option, Options.LocationSet) and not option.verify_location_name:
continue

if issubclass(option, Options.ItemSet) and not option.verify_item_name:
continue

if issubclass(option, Options.OptionSet) and not hasattr(option, "valid_keys"):
continue

grouped_options[getattr(option, "group_name", "Game Options")][option_name] = option

return render_template(
Expand Down
39 changes: 39 additions & 0 deletions WebHostLib/static/styles/playerOptions/playerOptions.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 46 additions & 0 deletions WebHostLib/static/styles/playerOptions/playerOptions.scss
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,52 @@ html{
}
}

.option-container{
display: flex;
flex-direction: column;
background-color: rgba(0, 0, 0, 0.125);
border: 1px solid rgba(20, 20, 20, 0.125);
border-radius: 3px;
color: #ffffff;
max-height: 10rem;
overflow-y: auto;
padding-right: 0.25rem;
padding-left: 0.25rem;

.option-entry{
display: flex;
flex-direction: row;
margin-bottom: 0.125rem;
margin-top: 0.125rem;

&:hover{
background-color: rgba(20, 20, 20, 0.125);
}

input[type=checkbox]{
margin-right: 0.25rem;
}

input[type=number]{
max-width: 1.5rem;
max-height: 1rem;
margin-left: 0.125rem;
text-align: center;

/* Hide arrows on input[type=number] fields */
-moz-appearance: textfield;
&::-webkit-outer-spin-button, &::-webkit-inner-spin-button{
-webkit-appearance: none;
margin: 0;
}
}

span{
flex-grow: 1;
}
}
}

.randomize-button{
display: flex;
flex-direction: column;
Expand Down
88 changes: 82 additions & 6 deletions WebHostLib/templates/playerOptions/macros.html
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
<div class="text-choice-container">
<div class="text-choice-wrapper">
<select id="{{ option_name }}" name="{{ option_name }}">
{% for id, name in option.name_lookup.items() %}
{% for id, name in option.name_lookup.items()|sort %}
{% if name != "random" %}
{% if option.default == id %}
<option value="{{ name }}" selected>{{ option.get_option_name(id) }}</option>
Expand All @@ -125,23 +125,99 @@
{% endmacro %}

{% macro ItemDict(option_name, option, world) %}
<span>Item Dict Input Coming Soon™</span>
<tr>
<td>{{ OptionTitle(option_name, option) }}</td>
<td>
<div class="option-container">
{% for item_name in world.item_names|sort %}
<div class="option-entry">
<span>{{ item_name }}</span>
<input type="number" id="{{ option_name }}-{{ item_name }}-qty" name="{{ option_name }}-qty" value="{{ option.default[item_name]|default("0") }}" />
</div>
{% endfor %}
</div>
</td>
</tr>
{% endmacro %}

{% macro OptionList(option_name, option) %}
<span>Option List Input Coming Soon™</span>
<tr>
<td>{{ OptionTitle(option_name, option) }}</td>
<td>
<div class="option-container">
{% for key in option.valid_keys|sort %}
<div class="option-entry">
<span>{{ key }}</span>
<input type="number" id="{{ option_name }}-{{ key }}-qty" name="{{ option_name }}-{{ key }}-qty" value="{{ option.default.count(key) }}" />
</div>
{% endfor %}
</div>
</td>
</tr>
{% endmacro %}

{% macro LocationSet(option_name, option, world) %}
<span>Location Set Input Coming Soon™</span>
<tr>
<td>{{ OptionTitle(option_name, option) }}</td>
<td>
<div class="option-container">
{% for group_name in world.location_name_groups.keys()|sort %}
{% if group_name != "Everywhere" %}
<div class="option-entry">
<input type="checkbox" id="{{ option_name }}-{{ group_name }}" name="{{ option_name }}-{{ group_name }}" {{ "checked" if grop_name in option.default }} />
<span>{{ group_name }}</span>
</div>
{% endif %}
{% endfor %}
{% for location_name in world.location_names|sort %}
<div class="option-entry">
<input type="checkbox" id="{{ option_name }}-{{ location_name }}" name="{{ option_name }}-{{ location_name }}" {{ "checked" if location_name in option.default }} />
<span>{{ location_name }}</span>
</div>
{% endfor %}
</div>
</td>
</tr>
{% endmacro %}

{% macro ItemSet(option_name, option, world) %}
<span>Item Set Input Coming Soon™</span>
<tr>
<td>{{ OptionTitle(option_name, option) }}</td>
<td>
<div class="option-container">
{% for group_name in world.item_name_groups.keys()|sort %}
{% if group_name != "Everything" %}
<div class="option-entry">
<input type="checkbox" id="{{ option_name }}-{{ group_name }}" name="{{ option_name }}-{{ group_name }}" {{ "checked" if group_name in option.default }} />
<span>{{ group_name }}</span>
</div>
{% endif %}
{% endfor %}
{% for item_name in world.item_names|sort %}
<div class="option-entry">
<input type="checkbox" id="{{ option_name }}-{{ item_name }}" name="{{ option_name }}-{{ item_name }}" {{ "checked" if item_name in option.default }} />
<span>{{ item_name }}</span>
</div>
{% endfor %}
</div>
</td>
</tr>
{% endmacro %}

{% macro OptionSet(option_name, option) %}
<span>Option Set Input Coming Soon™</span>
<tr>
<td>{{ OptionTitle(option_name, option) }}</td>
<td>
<div class="option-container">
{% for key in option.valid_keys %}
<div class="option-entry">
<input type="checkbox" id="{{ option_name }}-{{ key }}" name="{{ option_name }}-{{ key }}" {{ "checked" if key in option.default }} />
<span>{{ key }}</span>
</div>
{% endfor %}
</div>
</td>
</tr>
{% endmacro %}

{% macro OptionTitle(option_name, option) %}
Expand Down
16 changes: 8 additions & 8 deletions WebHostLib/templates/playerOptions/playerOptions.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ <h2>{{ group_name }}</h2>
<table class="left">
<tbody>
{% for option_name, option in group_options.items() %}
{% if loop.index >= loop.length / 2 %}
{% if loop.index < loop.length / 2 %}
{% if issubclass(option, Options.Toggle) %}
{{ inputs.Toggle(option_name, option) }}

Expand All @@ -77,16 +77,16 @@ <h2>{{ group_name }}</h2>
{% elif issubclass(option, Options.FreeText) %}
{{ inputs.FreeText(option_name, option) }}

{% elif issubclass(option, Options.ItemDict) %}
{% elif issubclass(option, Options.ItemDict) and option.verify_item_name %}
{{ inputs.ItemDict(option_name, option, world) }}

{% elif issubclass(option, Options.OptionList) and option.valid_keys %}
{{ inputs.OptionList(option_name, option) }}

{% elif issubclass(option, Options.LocationSet) %}
{% elif issubclass(option, Options.LocationSet) and option.verify_location_name %}
{{ inputs.LocationSet(option_name, option, world) }}

{% elif issubclass(option, Options.ItemSet) %}
{% elif issubclass(option, Options.ItemSet) and option.verify_item_name %}
{{ inputs.ItemSet(option_name, option, world) }}

{% elif issubclass(option, Options.OptionSet) and option.valid_keys %}
Expand All @@ -100,7 +100,7 @@ <h2>{{ group_name }}</h2>
<table class="right">
<tbody>
{% for option_name, option in group_options.items() %}
{% if loop.index >= loop.length / 2 %}
{% if loop.index > loop.length / 2 %}
{% if issubclass(option, Options.Toggle) %}
{{ inputs.Toggle(option_name, option) }}

Expand All @@ -125,16 +125,16 @@ <h2>{{ group_name }}</h2>
{% elif issubclass(option, Options.FreeText) %}
{{ inputs.FreeText(option_name, option) }}

{% elif issubclass(option, Options.ItemDict) %}
{% elif issubclass(option, Options.ItemDict) and option.verify_item_name %}
{{ inputs.ItemDict(option_name, option, world) }}

{% elif issubclass(option, Options.OptionList) and option.valid_keys %}
{{ inputs.OptionList(option_name, option) }}

{% elif issubclass(option, Options.LocationSet) %}
{% elif issubclass(option, Options.LocationSet) and option.verify_location_name %}
{{ inputs.LocationSet(option_name, option, world) }}

{% elif issubclass(option, Options.ItemSet) %}
{% elif issubclass(option, Options.ItemSet) and option.verify_item_name %}
{{ inputs.ItemSet(option_name, option, world) }}

{% elif issubclass(option, Options.OptionSet) and option.valid_keys %}
Expand Down

0 comments on commit 38ed8b4

Please sign in to comment.