Browse Source

Add monster HTML

master
Josh Gordon 4 years ago
parent
commit
53a4755492
  1. 49
      app/monsters.py
  2. 9
      app/static/style.css
  3. 26
      app/templates/monsters.html

49
app/monsters.py

@ -10,10 +10,10 @@ def getProperty(strs,prop):
class MonsterAction(object):
def __init__(self):
self.name = ""
self.hit = ""
self.reach = -1
self.damage = ""
self.name = "INVALID"
self.hit = "0"
self.reach = "0"
self.damage = "0"
self.special = ""
def parse(self,text):
@ -21,16 +21,29 @@ class MonsterAction(object):
#and last line is last closing brace of action
lines = [line.strip() for line in text.split("\n") if line]
self.name = lines[0][:-1].strip()
self.hit = lines[1].split(" ")[1:]
self.reach = lines[2].split(" ")[1]
self.damage = lines[3].split(" ")[1]
self.hit = ''.join(lines[1].split(" ")[1:]).strip()
self.reach = lines[2].split(" ")[1].strip()
self.damage = lines[3].split(" ")[1].strip()
if len(lines) > 4:
if "Special" in lines[4]:
i = 1
i = 5
while not "}" in lines[i]:
self.special += lines[i] + "\n"
self.special += lines[i].strip() + "\n"
i += 1
def export(self):
export_list = []
if not self.hit == "0":
export_list.append(("Hit",self.hit))
if not self.reach == "0":
export_list.append(("Reach",self.reach))
if not self.damage == "0":
export_list.append(("Damage",self.damage))
if not self.special == "":
export_list.append(("Special",self.special))
return export_list
def __str__(self):
return str(self.__dict__)
@ -96,6 +109,24 @@ class Monster(object):
print("Unparsed: ")
print(text)
def exportProps(self):
prop_list = []
for prop in MONSTER_PROPS:
if hasattr(self,prop):
prop_list.append((prop,getattr(self,prop)))
return prop_list
def getDescription(self):
return self.descript.strip()
def getNotes(self):
return self.notes.strip()
def exportActions(self):
return self.actions
def __str__(self):
return str(self.__dict__).replace("\',","\'\n")

9
app/static/style.css

@ -84,6 +84,11 @@ th {
color: #fff;
}
td table.props {
text-align: center;
width:100%;
}
table.props {
border-top: 1px solid #fff;
border-left: none;
@ -142,3 +147,7 @@ table.rolls td, table.rolls th {
left: 30px;
z-index: 99;
}
.centered {
text-align: center;
}

26
app/templates/monsters.html

@ -4,13 +4,35 @@
<ul class="headlist special">
<li><a href="monsters/random">Random</a></li>
</ul>
<ul class="headlist">
{% for monster in monsters %}
<li><a href="#{{monster.name}}">{{monster.name}}</a> {% if not loop.last %} &middot; {% endif %} </li>
{% endfor %}
</ul>
<table>
{% for monster in monsters %}
<tr>
<th class="topalign" id={{monster.name}}>
{{monster.name}}
<table class="props">
{% for (key,val) in monster.exportProps() %}
<tr><th>{{key}}</th><td>{{val}}</td></tr>
{% endfor %}
</table>
</th>
<td class="freeform monospace">{{monster.getDescription()}}
<hr>{{monster.getNotes()}}
</td>
<td class="freeform monospace centered">{% for action in monster.exportActions() %}{{action.name}} <table class="props">
{% for (key,val) in action.export() %}
<tr><th>{{key}}</th><td>{{val}}</td></tr>
{% endfor %}
</table>{% if not loop.last %} <br> {% endif %}{% endfor %}</td>
</tr>
{% endfor %}
</table>
<a class="topLink" href="#">Scroll to Top</a>
{% endblock %}
Loading…
Cancel
Save