Init repo
This commit is contained in:
commit
90b0363284
41
wa-syn-map.py
Normal file
41
wa-syn-map.py
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
from flask import Flask, jsonify, abort
|
||||||
|
from pathlib import Path
|
||||||
|
import json
|
||||||
|
|
||||||
|
app = Flask(__name__)
|
||||||
|
|
||||||
|
base_dir = Path('../Prediger-workadventure').resolve()
|
||||||
|
print(base_dir)
|
||||||
|
|
||||||
|
@app.route('/dyn/<string:code>/<path:map>')
|
||||||
|
def dyn_map(code, map):
|
||||||
|
|
||||||
|
p = (base_dir / map).resolve()
|
||||||
|
|
||||||
|
print(p)
|
||||||
|
|
||||||
|
if not base_dir < p:
|
||||||
|
abort(404)
|
||||||
|
|
||||||
|
if p.is_file() and p.suffix == ".json":
|
||||||
|
with p.open() as f:
|
||||||
|
map = json.load(f)
|
||||||
|
|
||||||
|
if "layers" in map:
|
||||||
|
for i in range(len(map["layers"])):
|
||||||
|
if "properties" in map["layers"][i]:
|
||||||
|
for j in range(len(map["layers"][i]["properties"])):
|
||||||
|
if "name" in map["layers"][i]["properties"][j] and map["layers"][i]["properties"][j]["name"] == "jitsiRoom" and "value" in map["layers"][i]["properties"][j]:
|
||||||
|
map["layers"][i]["properties"][j]["value"] = map["layers"][i]["properties"][j]["value"] + "_" + code
|
||||||
|
|
||||||
|
if "tilesets" in map:
|
||||||
|
for i in range(len(map["tilesets"])):
|
||||||
|
if "image" in map["tilesets"][i]:
|
||||||
|
map["tilesets"][i]["image"] = "../../map/" + map["tilesets"][i]["image"]
|
||||||
|
|
||||||
|
|
||||||
|
return jsonify(map)
|
||||||
|
abort(404)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
app.run()
|
Loading…
Reference in New Issue
Block a user