Browse Source

Add dungeon generation to frontend

master
Josh Gordon 3 years ago
parent
commit
a383ba7d81
  1. 2
      app/dungeon.py
  2. 16
      app/routes.py
  3. 1
      app/static/style.css
  4. 16
      app/templates/dungeon.html
  5. 4
      app/templates/image.html
  6. 1
      app/templates/index.html

2
app/dungeon.py

@ -289,7 +289,7 @@ def genGridDungeonB64(gSizeX,gSizeY,mScale,imScale,numCells=None):
#cv2.imshow("here",im)
#cv2.waitKey(0)
#base64 encode as jpg
ret,buf = cv2.imencode('.jpg',im)
ret,buf = cv2.imencode('.png',im)
enc = base64.b64encode(buf)
return enc

16
app/routes.py

@ -4,6 +4,8 @@ from flask import Flask, render_template, request, redirect
from items import get_items, get_worlds, get_monsters
from dungeon import genGridDungeonB64
from random import choice, sample
import re
@ -163,5 +165,19 @@ def random_monster():
m = choice(get_monsters())
return redirect("/monsters#"+m.name)
@app.route("/dungeon")
def dungeon():
return render_template('dungeon.html')
@app.route("/dungeonGen", methods=["POST"])
def genDungeon():
x = int(request.form['x'])
y = int(request.form['y'])
m = int(request.form['m'])
s = int(request.form['s'])
c = int(request.form['c'])
enc = str(genGridDungeonB64(x,y,m,s,c))[2:-1]
return render_template('image.html',data=enc)
if __name__ == "__main__":
app.run()

1
app/static/style.css

@ -169,3 +169,4 @@ table.rolls td, table.rolls th {
.action .kind, .action .onhit, .action .name {
font-style: italic;
}

16
app/templates/dungeon.html

@ -0,0 +1,16 @@
{% extends "base.html" %}
{% block content %}
<form action="/dungeonGen" method="post">
Dungeon width:
<input type=number name="x" placeholder=10>
Dungeon height:
<input type=number name="y" placeholder=10>
Tile size:
<input type=number name="m" placeholder=8>
Image scale:
<input type=number name="s" placeholder=24>
Number of Rooms:
<input type=number name="c" placeholder=6>
<input type=submit value="generate">
</form>
{% endblock %}

4
app/templates/image.html

@ -0,0 +1,4 @@
{% extends "base.html" %}
{% block content %}
<img src="data:image/jpg;base64,{{data}}" alt="Dungeon Image" />
{% endblock %}

1
app/templates/index.html

@ -24,6 +24,7 @@
</nav>
<a href="/marches">.</a>
<a href="/dungeon">.</a>
{% if searchResults is defined %}

Loading…
Cancel
Save