fix single item in inventory displaying

fix parsing of initial char xml to have some sane output
initial inventory does not show, but it should not crash
This commit is contained in:
aronwk-aaron 2022-10-23 17:25:41 -05:00
parent eb7a820b54
commit b87481e803
3 changed files with 76 additions and 29 deletions

View File

@ -9,6 +9,7 @@ from app import gm_level, log_audit
from app.luclient import translate_from_locale from app.luclient import translate_from_locale
import xmltodict import xmltodict
import xml.etree.ElementTree as ET import xml.etree.ElementTree as ET
import json
character_blueprint = Blueprint('characters', __name__) character_blueprint = Blueprint('characters', __name__)
@ -78,7 +79,7 @@ def view(id):
character_json = xmltodict.parse( character_json = xmltodict.parse(
CharacterXML.query.filter( CharacterXML.query.filter(
CharacterXML.id == id CharacterXML.id == id
).first().xml_data, ).first().xml_data.replace("\"stt=", "\" stt="),
attr_prefix="attr_" attr_prefix="attr_"
) )
@ -91,9 +92,10 @@ def view(id):
# stupid fix for jinja parsing # stupid fix for jinja parsing
character_json["obj"]["inv"]["holdings"] = character_json["obj"]["inv"].pop("items") character_json["obj"]["inv"]["holdings"] = character_json["obj"]["inv"].pop("items")
# sort by items slot index # sort by items slot index
for inv in character_json["obj"]["inv"]["holdings"]["in"]: if type(character_json["obj"]["inv"]["holdings"]["in"]) == list:
if "i" in inv.keys() and type(inv["i"]) == list: for inv in character_json["obj"]["inv"]["holdings"]["in"]:
inv["i"] = sorted(inv["i"], key=lambda i: int(i['attr_s'])) if "i" in inv.keys() and type(inv["i"]) == list:
inv["i"] = sorted(inv["i"], key=lambda i: int(i['attr_s']))
return render_template( return render_template(
'character/view.html.j2', 'character/view.html.j2',
@ -119,7 +121,7 @@ def view_xml(id):
character_xml = CharacterXML.query.filter( character_xml = CharacterXML.query.filter(
CharacterXML.id == id CharacterXML.id == id
).first().xml_data ).first().xml_data.replace("\"stt=", "\" stt=")
response = make_response(character_xml) response = make_response(character_xml)
response.headers.set('Content-Type', 'text/xml') response.headers.set('Content-Type', 'text/xml')
@ -190,7 +192,7 @@ def rescue(id):
CharacterXML.id == id CharacterXML.id == id
).first() ).first()
character_xml = ET.XML(character_data.xml_data) character_xml = ET.XML(character_data.xml_data.replace("\"stt=", "\" stt="))
for zone in character_xml.findall('.//r'): for zone in character_xml.findall('.//r'):
if int(zone.attrib["w"]) % 100 == 0: if int(zone.attrib["w"]) % 100 == 0:
form.save_world.choices.append( form.save_world.choices.append(

View File

@ -281,6 +281,7 @@ def register_luclient_jinja_helpers(app):
@app.template_filter('parse_lzid') @app.template_filter('parse_lzid')
def parse_lzid(lzid): def parse_lzid(lzid):
if not lzid: return [1000, 1000, 1000]
return[ return[
(int(lzid) & ((1 << 16) - 1)), (int(lzid) & ((1 << 16) - 1)),
((int(lzid) >> 16) & ((1 << 16) - 1)), ((int(lzid) >> 16) & ((1 << 16) - 1)),

View File

@ -63,9 +63,13 @@
Play time: Play time:
</div> </div>
<div class="col"> <div class="col">
{% if character_json.obj.char.attr_time %}
{{ (character_json.obj.char.attr_time|int/60/60/24)|int }} Days {{ (character_json.obj.char.attr_time|int/60/60/24)|int }} Days
{{ (character_json.obj.char.attr_time|int/60/60)|int - ((character_json.obj.char.attr_time|int/60/60/24)|int) * 24}} Hours {{ (character_json.obj.char.attr_time|int/60/60)|int - ((character_json.obj.char.attr_time|int/60/60/24)|int) * 24}} Hours
{{ (character_json.obj.char.attr_time|int/60 - (character_json.obj.char.attr_time|int/60/60)|int*60)|int }} Minutes {{ (character_json.obj.char.attr_time|int/60 - (character_json.obj.char.attr_time|int/60/60)|int*60)|int }} Minutes
{% else %}
None
{% endif %}
</div> </div>
</div> </div>
<hr class="bg-primary"/> <hr class="bg-primary"/>
@ -110,9 +114,15 @@
{# Inv ID 0 - Index: 0 #} {# Inv ID 0 - Index: 0 #}
{% for item in character_json.obj.inv.holdings.in %} {% for item in character_json.obj.inv.holdings.in %}
{% if item.attr_t == "0" %} {% if item.attr_t == "0" %}
{% for inv_item in item.i %} {% if item.i is iterable and (item.i is not string and item.i is not mapping) %}
{% include 'partials/charxml/_inv_grid.html.j2' %} {% for inv_item in item.i %}
{% endfor %} {% include 'partials/charxml/_inv_grid.html.j2' %}
{% endfor %}
{% else %}
{% with inv_item=item.i %}
{% include 'partials/charxml/_inv_grid.html.j2' %}
{% endwith %}
{% endif %}
{% endif %} {% endif %}
{% endfor %} {% endfor %}
</div> </div>
@ -120,9 +130,15 @@
{# Inv ID 1 - Index: 1 #} {# Inv ID 1 - Index: 1 #}
{% for item in character_json.obj.inv.holdings.in %} {% for item in character_json.obj.inv.holdings.in %}
{% if item.attr_t == "1" %} {% if item.attr_t == "1" %}
{% for inv_item in item.i %} {% if item.i is iterable and (item.i is not string and item.i is not mapping) %}
{% include 'partials/charxml/_inv_grid.html.j2' %} {% for inv_item in item.i %}
{% endfor %} {% include 'partials/charxml/_inv_grid.html.j2' %}
{% endfor %}
{% else %}
{% with inv_item=item.i %}
{% include 'partials/charxml/_inv_grid.html.j2' %}
{% endwith %}
{% endif %}
{% endif %} {% endif %}
{% endfor %} {% endfor %}
</div> </div>
@ -130,9 +146,15 @@
{# Inv ID 14 - Index: 10 #} {# Inv ID 14 - Index: 10 #}
{% for item in character_json.obj.inv.holdings.in %} {% for item in character_json.obj.inv.holdings.in %}
{% if item.attr_t == "14" %} {% if item.attr_t == "14" %}
{% for inv_item in item.i %} {% if item.i is iterable and (item.i is not string and item.i is not mapping) %}
{% include 'partials/charxml/_inv_grid.html.j2' %} {% for inv_item in item.i %}
{% endfor %} {% include 'partials/charxml/_inv_grid.html.j2' %}
{% endfor %}
{% else %}
{% with inv_item=item.i %}
{% include 'partials/charxml/_inv_grid.html.j2' %}
{% endwith %}
{% endif %}
{% endif %} {% endif %}
{% endfor %} {% endfor %}
</div> </div>
@ -140,9 +162,15 @@
{# Inv ID 2 - Index: 2 #} {# Inv ID 2 - Index: 2 #}
{% for item in character_json.obj.inv.holdings.in %} {% for item in character_json.obj.inv.holdings.in %}
{% if item.attr_t == "2" %} {% if item.attr_t == "2" %}
{% for inv_item in item.i %} {% if item.i is iterable and (item.i is not string and item.i is not mapping) %}
{% include 'partials/charxml/_inv_grid.html.j2' %} {% for inv_item in item.i %}
{% endfor %} {% include 'partials/charxml/_inv_grid.html.j2' %}
{% endfor %}
{% else %}
{% with inv_item=item.i %}
{% include 'partials/charxml/_inv_grid.html.j2' %}
{% endwith %}
{% endif %}
{% endif %} {% endif %}
{% endfor %} {% endfor %}
</div> </div>
@ -150,19 +178,31 @@
{# Inv ID 5 - Index: 6 #} {# Inv ID 5 - Index: 6 #}
{% for item in character_json.obj.inv.holdings.in %} {% for item in character_json.obj.inv.holdings.in %}
{% if item.attr_t == "5" %} {% if item.attr_t == "5" %}
{% for inv_item in item.i %} {% if item.i is iterable and (item.i is not string and item.i is not mapping) %}
{% include 'partials/charxml/_inv_grid.html.j2' %} {% for inv_item in item.i %}
{% endfor %} {% include 'partials/charxml/_inv_grid.html.j2' %}
{% endfor %}
{% else %}
{% with inv_item=item.i %}
{% include 'partials/charxml/_inv_grid.html.j2' %}
{% endwith %}
{% endif %}
{% endif %} {% endif %}
{% endfor %} {% endfor %}
</div> </div>
<div class="tab-pane fade" id="nav-behaviors" role="tabpanel" aria-labelledby="nav-behaviors-tab"> <div class="tab-pane fade" id="nav-behaviors" role="tabpanel" aria-labelledby="nav-behaviors-tab">
{# Inv ID 7 - Index: 8 #} {# Inv ID 7 - Index: 8 #}
{% for item in character_json.obj.inv.holdings.in %} {% for item in character_json.obj.inv.holdings.in %}
{% if item.attr_t == "7" %} {% if item.attr_t == "1" %}
{% for inv_item in item.i %} {% if item.i is iterable and (item.i is not string and item.i is not mapping) %}
{% include 'partials/charxml/_inv_grid.html.j2' %} {% for inv_item in item.i %}
{% endfor %} {% include 'partials/charxml/_inv_grid.html.j2' %}
{% endfor %}
{% else %}
{% with inv_item=item.i %}
{% include 'partials/charxml/_inv_grid.html.j2' %}
{% endwith %}
{% endif %}
{% endif %} {% endif %}
{% endfor %} {% endfor %}
</div> </div>
@ -187,10 +227,14 @@
</button> </button>
</div> </div>
<div class="modal-body"> <div class="modal-body">
{% for zone in character_json.obj.char.zs.s %} {% if character_json.obj.char.zs %}
{% include 'partials/charxml/_zone_stats.html.j2' %} {% for zone in character_json.obj.char.zs.s %}
{{ '<hr class="bg-primary"/>' if not loop.last else "" }} {% include 'partials/charxml/_zone_stats.html.j2' %}
{% endfor %} {{ '<hr class="bg-primary"/>' if not loop.last else "" }}
{% endfor %}
{% else %}
No Stats Yet
{% endif %}
</div> </div>
<div class="modal-footer"> <div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button> <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>