Compare commits
No commits in common. "ec6a94f18e6d37ff30be5e667dc315c211aa7198" and "28f3d7e6cb7ed5b669882b75d16ac99bd1057ed6" have entirely different histories.
ec6a94f18e
...
28f3d7e6cb
@ -1,5 +1,4 @@
|
|||||||
|
|
||||||
import json
|
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
@ -11,32 +10,16 @@ app = Flask(__name__)
|
|||||||
app.config["MONGO_URI"] = os.environ["MONGO_URI"]
|
app.config["MONGO_URI"] = os.environ["MONGO_URI"]
|
||||||
mongo = PyMongo(app)
|
mongo = PyMongo(app)
|
||||||
|
|
||||||
LOCALIZATION_JSON = {}
|
|
||||||
with open("./db_explorer/en.json") as f:
|
|
||||||
LOCALIZATION_JSON = json.load(f)
|
|
||||||
|
|
||||||
@app.template_filter('filter_vtt')
|
@app.template_filter('filter_vtt')
|
||||||
def filter_vtt(text):
|
def filter_vtt(text):
|
||||||
compendium_re = re.compile(r"@Compendium\[([^\]]+)\]\{([^\}]+)\}")
|
compendium_re = re.compile(r"@Compendium\[([^\]]+)\]\{([^\}]+)\}")
|
||||||
def compendium_return(m):
|
def compendium_return(m):
|
||||||
# TODO: Actually add links
|
|
||||||
return f"<a>{m.group(2)}</a>"
|
return f"<a>{m.group(2)}</a>"
|
||||||
macro_re = re.compile(r"\[\[\/\S+?r(?:oll)?\s(?:(?P<sdice>[^\{\] ]+)[^\{\]]*|(?:\{(?P<ldice>[^\}]+)\}\[[^\]]+\])?)\]\](?:\{(?P<alt>[^\}]+)\})?")
|
macro_re = re.compile(r"\[\[\/\S?r\s(?:(?P<sdice>[^\{\] ]+)[^\{\]]*|(?:\{(?P<ldice>[^\}]+)\}\[[^\]]+\])?)\]\](?:\{(?P<alt>[^\}]+)\})?")
|
||||||
def macro_return(m):
|
def macro_return(m):
|
||||||
if m.group('alt') is not None:
|
if m.group('alt') is not None:
|
||||||
return m.group('alt')
|
return m.group('alt')
|
||||||
return m.group('sdice')
|
return m.group('sdice')
|
||||||
localize_re = re.compile(r"@Localize\[([^\]]+)\]")
|
|
||||||
def localize_return(m):
|
|
||||||
path = m.group(1)
|
|
||||||
output = LOCALIZATION_JSON
|
|
||||||
for chunk in path.split('.'):
|
|
||||||
output = output.get(chunk, {})
|
|
||||||
if type(output) != str:
|
|
||||||
output = f"[LOCALIZATION LOOKUP ERROR - {m.group(0)}]"
|
|
||||||
return output
|
|
||||||
# Template
|
|
||||||
text = localize_re.sub(localize_return, text) # Has to be run before Compendium and Macro replacement
|
|
||||||
text = compendium_re.sub(compendium_return, text)
|
text = compendium_re.sub(compendium_return, text)
|
||||||
text = macro_re.sub(macro_return, text)
|
text = macro_re.sub(macro_return, text)
|
||||||
return text
|
return text
|
||||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user