diff --git a/db_explorer/db_explorer/app.py b/db_explorer/db_explorer/app.py new file mode 100644 index 0000000..e86e8e0 --- /dev/null +++ b/db_explorer/db_explorer/app.py @@ -0,0 +1,58 @@ + +import urllib.parse +import os +import re + +from flask import Flask, render_template +from flask_pymongo import PyMongo + +app = Flask(__name__) +app.config["MONGO_URI"] = os.environ["MONGO_URI"] +mongo = PyMongo(app) + +@app.template_filter('filter_vtt') +def filter_vtt(text): + compendium_re = re.compile(r"@Compendium\[([^\]]+)\]\{([^\}]+)\}") + def compendium_return(m): + return f"{m.group(2)}" + macro_re = re.compile(r"\[\[\/\S?r\s(?:(?P[^\{\] ]+)[^\{\]]*|(?:\{(?P[^\}]+)\}\[[^\]]+\])?)\]\](?:\{(?P[^\}]+)\})?") + def macro_return(m): + if m.group('alt') is not None: + return m.group('alt') + return m.group('sdice') + text = compendium_re.sub(compendium_return, text) + text = macro_re.sub(macro_return, text) + return text + +@app.route("/") +def list_types(): + types = [ {"name": "Actions", "href": "action"} ] + return render_template("list.html", header="All types", items=types) + +@app.route("/action") +def list_actions(): + items = list(map(lambda x: {"name": x["name"], "href": "./action/" + urllib.parse.quote(x["name"], safe='')}, mongo.db.action.find({}, {"name": 1}).sort("name", 1))) + return render_template("list.html", header="All actions", items=items) + +@app.route("/action/") +def show_action(name): + item = mongo.db.action.find_one_or_404({"name": name}) + print(item) + if item["data"]["actions"]["value"] == None: + if item["data"]["actionType"]["value"] == 'passive': + item['_action_icon'] = None + elif item["data"]["actionType"]["value"] == 'reaction': + item['_action_icon'] = 'r' + elif item["data"]["actionType"]["value"] == 'free': + item['_action_icon'] = 0 + else: + raise ValueError(f'Unknown action type: {item["data"]["actionType"]["value"]}') + elif item["data"]["actions"]["value"] in (1,2,3): + item['_action_icon'] = item["data"]["actions"]["value"] + else: + raise ValueError(f'Unknown action: {item["data"]["actionType"]["value"]} - {item["data"]["actions"]["value"]}') + + return render_template("action.html", action=item) + +if __name__ == "__main__": + app.run() \ No newline at end of file diff --git a/db_explorer/db_explorer/blueprints/core/__init__.py b/db_explorer/db_explorer/blueprints/core/__init__.py new file mode 100644 index 0000000..02ded5b --- /dev/null +++ b/db_explorer/db_explorer/blueprints/core/__init__.py @@ -0,0 +1,2 @@ + +from flask import Blueprint \ No newline at end of file diff --git a/db_explorer/db_explorer/static/activity/free.webp b/db_explorer/db_explorer/static/activity/free.webp new file mode 100644 index 0000000..3c548b1 Binary files /dev/null and b/db_explorer/db_explorer/static/activity/free.webp differ diff --git a/db_explorer/db_explorer/static/activity/one.webp b/db_explorer/db_explorer/static/activity/one.webp new file mode 100644 index 0000000..2344d49 Binary files /dev/null and b/db_explorer/db_explorer/static/activity/one.webp differ diff --git a/db_explorer/db_explorer/static/activity/reaction.webp b/db_explorer/db_explorer/static/activity/reaction.webp new file mode 100644 index 0000000..ee09f5a Binary files /dev/null and b/db_explorer/db_explorer/static/activity/reaction.webp differ diff --git a/db_explorer/db_explorer/static/activity/three.webp b/db_explorer/db_explorer/static/activity/three.webp new file mode 100644 index 0000000..96ae2fd Binary files /dev/null and b/db_explorer/db_explorer/static/activity/three.webp differ diff --git a/db_explorer/db_explorer/static/activity/two.webp b/db_explorer/db_explorer/static/activity/two.webp new file mode 100644 index 0000000..bbe077e Binary files /dev/null and b/db_explorer/db_explorer/static/activity/two.webp differ diff --git a/db_explorer/db_explorer/static/css/base.css b/db_explorer/db_explorer/static/css/base.css new file mode 100644 index 0000000..9d5d19f --- /dev/null +++ b/db_explorer/db_explorer/static/css/base.css @@ -0,0 +1,10 @@ + +.action-icon { + height: 26px; + margin-left: 5px; +} + +.sourcebook { + text-align: right; + font-size: 0.8em; +} \ No newline at end of file diff --git a/db_explorer/db_explorer/templates/_base.html b/db_explorer/db_explorer/templates/_base.html new file mode 100644 index 0000000..c8d1aa6 --- /dev/null +++ b/db_explorer/db_explorer/templates/_base.html @@ -0,0 +1,15 @@ +{% import "_const.html" as c -%} + + + + {% block head %} + {% block title %}PF2 DB{% endblock %} + {% endblock %} + + + {% block body %} + This page is unintentionally left empty + {% endblock %} + + diff --git a/db_explorer/db_explorer/templates/_const.html b/db_explorer/db_explorer/templates/_const.html new file mode 100644 index 0000000..2104271 --- /dev/null +++ b/db_explorer/db_explorer/templates/_const.html @@ -0,0 +1,16 @@ +{% macro _abase(url) -%} + +{%- endmacro %} +{% set afree = _abase(url_for("static", filename="activity/free.webp")) -%} +{% set aone = _abase(url_for("static", filename="activity/one.webp")) -%} +{% set atwo = _abase(url_for("static", filename="activity/two.webp")) -%} +{% set athree = _abase(url_for("static", filename="activity/three.webp")) -%} +{% set areaction = _abase(url_for("static", filename="activity/reaction.webp")) -%} +{% set actions = { + None: "", + 0: afree, + 1: aone, + 2: atwo, + 3: athree, + 'r': areaction +} -%} \ No newline at end of file diff --git a/db_explorer/db_explorer/templates/action.html b/db_explorer/db_explorer/templates/action.html new file mode 100644 index 0000000..ed4dd89 --- /dev/null +++ b/db_explorer/db_explorer/templates/action.html @@ -0,0 +1,7 @@ +{% extends "_base.html" %} +{% block title %}{{action.name}} - PF2 DB{% endblock %} +{% block body %} +

{{action["name"]}}{{c.actions[action["_action_icon"]]|safe}}

+

{{action["data"]["description"]["value"]|filter_vtt|safe}}

+

{{action["data"]["source"]["value"]}}

+{% endblock %} \ No newline at end of file diff --git a/db_explorer/db_explorer/templates/list.html b/db_explorer/db_explorer/templates/list.html new file mode 100644 index 0000000..ed7c977 --- /dev/null +++ b/db_explorer/db_explorer/templates/list.html @@ -0,0 +1,10 @@ +{% extends "_base.html" %} +{% block title %}{{header}} - PF2 DB {% endblock %} +{% block body %} +

{{ header }}

+ +{% endblock %} \ No newline at end of file diff --git a/db_explorer/pyproject.toml b/db_explorer/pyproject.toml new file mode 100644 index 0000000..a02acba --- /dev/null +++ b/db_explorer/pyproject.toml @@ -0,0 +1,17 @@ +[tool.poetry] +name = "db-explorer" +version = "0.1.0" +description = "" +authors = ["Michal Kunc "] +readme = "README.md" +packages = [{include = "db_explorer"}] + +[tool.poetry.dependencies] +python = "^3.8" +Flask = "^2.0.2" +Flask-PyMongo = "^2.3.0" + + +[build-system] +requires = ["poetry-core"] +build-backend = "poetry.core.masonry.api"