Skip to content

Commit

Permalink
testing wip
Browse files Browse the repository at this point in the history
  • Loading branch information
ThePhar committed Jun 23, 2024
1 parent 60d1501 commit 733c833
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 19 deletions.
3 changes: 3 additions & 0 deletions WebHost.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ def get_app() -> "Flask":
logging.info("Getting public IP, as HOST_ADDRESS is empty.")
app.config["HOST_ADDRESS"] = Utils.get_public_ipv4()
logging.info(f"HOST_ADDRESS was set to {app.config['HOST_ADDRESS']}")
if app.config["DEBUG"]:
app.config["CACHE_TYPE"] = "NullCache"
logging.info(f"CACHE_TYPE was set to 'NullCache' in DEBUG mode.")

register()
cache.init_app(app)
Expand Down
41 changes: 30 additions & 11 deletions WebHostLib/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
import json
import os
from textwrap import dedent
from typing import Dict, Union
from typing import Dict, Type, Union

import yaml
from docutils.core import publish_parts
from flask import Response, redirect, render_template, request
from flask_wtf import FlaskForm
from wtforms import SelectField, StringField
from wtforms.fields.simple import HiddenField
from wtforms.validators import DataRequired

import Options
Expand All @@ -19,11 +20,8 @@


class PlayerOptionsForm(FlaskForm):
def __init__(self, world: World):
name = StringField("Player Name", validators=[DataRequired()])
preset = SelectField("Options Preset", choices=[(preset, preset) for preset in world.web.options_presets])

super().__init__()
game = HiddenField()
name = StringField("Player Name", validators=[DataRequired()])


def create() -> None:
Expand All @@ -49,18 +47,39 @@ def render_options_page(template: str, world_name: str, is_complex: bool = False
for group in world.web.option_groups:
start_collapsed[group.name] = group.start_collapsed

# TODO: Testing
form = PlayerOptionsForm(prefix="meta")

return render_template(
template,
world_name=world_name,
world=world,
option_groups=Options.get_option_groups(world, visibility_level=visibility_flag),
start_collapsed=start_collapsed,
issubclass=issubclass,
Options=Options,
# world=world,
# option_groups=Options.get_option_groups(world, visibility_level=visibility_flag),
# start_collapsed=start_collapsed,
# issubclass=issubclass,
# Options=Options,
form=form,
header_theme=f"header/{get_world_theme(world_name)}Header.html",
)


# Test
@app.route("/games/<string:world_name>/test", methods=["POST"])
def test_action(world_name: str) -> Union[Response, str]:
return str(",".join([f"{k}: {v}" for k, v in request.form.items()]))


@app.route("/games/<string:world_name>/<string:option_name>/<int:start_index>")
def test_action_2(world_name: str, option_name: str, start_index: int) -> Union[Response, str]:
world = AutoWorldRegister.world_types[world_name]
option = world.options_dataclass.type_hints[option_name]
keys = list(option.valid_keys)
keys.sort()

return json.dumps(keys[start_index:start_index+100])
# return ""


def generate_game(options: Dict[str, Union[dict, str]]) -> Union[Response, str]:
from .generate import start_generation

Expand Down
40 changes: 36 additions & 4 deletions WebHostLib/templates/options/player.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,44 @@
{%- block head -%}
<title>{{ world_name }} Options</title>
<link rel="stylesheet" type="text/css" href="{{ url_for("static", filename="styles/options/player.css") }}">
<script defer type="application/ecmascript" src="{{ url_for("static", filename="assets/options/player.js") }}"></script>
{# <script defer type="application/ecmascript" src="{{ url_for("static", filename="assets/options/player.js") }}"></script>#}
<style>
#test-block {
box-sizing: border-box;
width: 400px;
height: 400px;
border: 1px solid black;
padding: 2px;
overflow-x: clip;
overflow-y: scroll;
}
</style>
{%- endblock -%}

{%- block body -%}
{% include header_theme %}
<div class="markdown">
Hello, world!asd
{%- include header_theme -%}
<div id="test-block">

</div>

<script>
const options = {
root: document.querySelector("#test-block"),
rootMargin: "0px",
threshold: 1.0,
};

const observer = new IntersectionObserver(callback, options);

function callback(entries, observer) {
console.log("Observer", observer);
entries.forEach((entry) => {
console.log("Entry", entry);
})
}

fetch("local_items/0")
.then((response) => response.text())
.then((text) => console.log(text));
</script>
{%- endblock -%}
2 changes: 1 addition & 1 deletion WebHostLib/templates/pageWrapper.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=768">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename="styles/tooltip.css") }}">
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename="styles/cookieNotice.css") }}">
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename="styles/globalStyles.css") }}">
Expand Down
6 changes: 3 additions & 3 deletions worlds/AutoWorld.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ def __new__(mcs, name: str, bases: Tuple[type, ...], dct: Dict[str, Any]) -> Aut
# TODO - remove this once all worlds use options dataclasses
if "options_dataclass" not in dct and "option_definitions" in dct:
# TODO - switch to deprecate after a version
if __debug__:
logging.warning(f"{name} Assigned options through option_definitions which is now deprecated. "
"Please use options_dataclass instead.")
# if __debug__:
# logging.warning(f"{name} Assigned options through option_definitions which is now deprecated. "
# "Please use options_dataclass instead.")
dct["options_dataclass"] = make_dataclass(f"{name}Options", dct["option_definitions"].items(),
bases=(PerGameCommonOptions,))

Expand Down

0 comments on commit 733c833

Please sign in to comment.