From 3453a1ebde9d32ca8a8b45a321b628a0faac6b99 Mon Sep 17 00:00:00 2001 From: Reditus <33814724+ReditusDraco@users.noreply.github.com> Date: Wed, 20 May 2026 11:36:48 +0100 Subject: [PATCH] WIP: Inventory grid redesign (unfinished - do not use) --- README.md | 5 + app/routes/main.py | 29 ++- app/services/admin.py | 19 +- app/services/player.py | 52 +++++- app/utils/constants.py | 43 +++++ static/style.css | 353 +++++++++++++++++++++++++++++++++++ templates/player_detail.html | 336 ++++++++++++++++++++++++++++++--- 7 files changed, 807 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index a5cb0ba..5ac95c8 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,11 @@ If you're testing this project, grab builds from nightly for the latest features ## Features +### ⚠️ Experimental Features (Use at Your Own Risk) +- **Inventory Grid View** — New visual inventory display with grid slots, equipped items, durability bars, ammo counts, and click-to-edit. **This feature is very unfinished and has known issues.** Do not use for critical inventory management. Do not report issues with this feature until it is marked stable. + +### Stable Features + - **Map Features**: Interactive maps with real-world coordinate calibration for Hagga Basin and The Deep Desert. Default view centers on Hagga Basin at 15% zoom. Zoom range: 15%–100%. - **Player Management**: View, search, and filter players. Track online status, factions, guilds, and locations. - **Chat Logs**: Parsed from text-router pod logs with channel filtering and auto-refresh. diff --git a/app/routes/main.py b/app/routes/main.py index e834a5a..6cac187 100644 --- a/app/routes/main.py +++ b/app/routes/main.py @@ -42,12 +42,21 @@ def register_routes(app, services, settings): @app.context_processor def inject_globals(): conn_ok = db.check_health() + from app.utils.constants import ( + INVENTORY_HIDDEN_TYPES, INVENTORY_UNKNOWN_TYPES, INVENTORY_PRIMARY_TYPES, + EQUIPPED_SLOT_LABELS, QUALITY_TIERS, + ) return dict( nav_pages=NAV_PAGES, current_path=request.path if request else '/', fmt_role=fmt_role, conn_ok=conn_ok, current_user=current_user, + inv_hidden_types=INVENTORY_HIDDEN_TYPES, + inv_unknown_types=INVENTORY_UNKNOWN_TYPES, + inv_primary_types=INVENTORY_PRIMARY_TYPES, + equipped_slot_labels=EQUIPPED_SLOT_LABELS, + quality_tiers=QUALITY_TIERS, ) @app.template_filter('inv_label') @@ -97,6 +106,12 @@ def register_routes(app, services, settings): except (ValueError, TypeError): return str(val) + @app.template_filter('escapejs') + def escapejs_filter(s): + if not s: + return '' + return s.replace('\\', '\\\\').replace("'", "\\'").replace('"', '\\"').replace('\n', '\\n').replace('\r', '\\r') + # Health check @app.route('/health') def health_check(): @@ -192,19 +207,29 @@ def register_routes(app, services, settings): is_online = player_svc.is_online(player_controller_id) if player_controller_id else False + from app.utils.constants import INVENTORY_HIDDEN_TYPES, INVENTORY_UNKNOWN_TYPES, INVENTORY_PRIMARY_TYPES + primary_inventories = [inv for inv in inventories if inv['inventory_type'] in INVENTORY_PRIMARY_TYPES and inv['inventory_type'] not in INVENTORY_HIDDEN_TYPES] + unknown_inventories = [inv for inv in inventories if inv['inventory_type'] in INVENTORY_UNKNOWN_TYPES] + other_inventories = [inv for inv in inventories if inv['inventory_type'] not in INVENTORY_PRIMARY_TYPES and inv['inventory_type'] not in INVENTORY_UNKNOWN_TYPES and inv['inventory_type'] not in INVENTORY_HIDDEN_TYPES] + static_data = get_static_data() return render_template('player_detail.html', player=player, guild=guild, vehicles=player_vehicles, buildings=buildings_result, currency=currency, - inventories=inventories, landclaims=landclaims, + inventories=inventories, primary_inventories=primary_inventories, + unknown_inventories=unknown_inventories, other_inventories=other_inventories, + landclaims=landclaims, specialization=specialization, tech_knowledge=tech_knowledge, purchased_keystones=purchased_keystones, all_keystones=static_data['keystones'], faction_reputation=faction_reputation, landsraad_info=landsraad_info, vitals=vitals, is_online=is_online) except Exception as e: logger.exception("Error in player_detail route") - return render_template('player_detail.html', db_error=f"{type(e).__name__}: {e}") + return render_template('player_detail.html', + player=None, inventories=[], primary_inventories=[], + unknown_inventories=[], other_inventories=[], + db_error=f"{type(e).__name__}: {e}") # Vehicles @app.route('/vehicles') diff --git a/app/services/admin.py b/app/services/admin.py index 5a2fd29..9566944 100644 --- a/app/services/admin.py +++ b/app/services/admin.py @@ -578,7 +578,7 @@ class AdminService: def edit_item(self, item_id, field, value): if item_id is None or field is None or value is None: return False, "Missing parameters" - allowed_fields = ('stack_size', 'quality_level', 'is_new') + allowed_fields = ('stack_size', 'quality_level', 'is_new', 'durability', 'max_durability', 'ammo') if field not in allowed_fields: return False, f"Invalid field. Allowed: {', '.join(allowed_fields)}" @@ -593,6 +593,23 @@ class AdminService: "UPDATE dune.items SET is_new = %s WHERE id = %s RETURNING id, stack_size, quality_level, is_new", [bool(value), item_id] ) + elif field in ('durability', 'max_durability', 'ammo'): + stats_path = { + 'durability': '{FItemStackAndDurabilityStats,CurrentDurability}', + 'max_durability': '{FItemStackAndDurabilityStats,DecayedMaxDurability}', + 'ammo': '{FWeaponItemStats,CurrentAmmo}', + }[field] + cur.execute( + "UPDATE dune.items SET stats = jsonb_set(stats, %s, %s::jsonb, true) WHERE id = %s RETURNING id", + [stats_path.split(','), str(value), item_id] + ) + row = cur.fetchone() + if not row: + conn.rollback() + return False, "Item not found" + conn.commit() + audit_logger.info(f"EDIT_ITEM: item_id={item_id} field={field} value={value}") + return True, {"item_id": item_id, "field": field, "value": value} else: cur.execute( "UPDATE dune.items SET {} = %s WHERE id = %s RETURNING id, stack_size, quality_level, is_new".format(field), diff --git a/app/services/player.py b/app/services/player.py index 374f086..bce3adf 100644 --- a/app/services/player.py +++ b/app/services/player.py @@ -274,7 +274,7 @@ class PlayerService: def get_player_inventories(self, player_id): try: inventories = self.db.query(""" - SELECT i.id, i.actor_id, i.inventory_type, + SELECT i.id, i.actor_id, i.inventory_type, i.max_item_count, i.max_item_volume, COALESCE(json_agg( json_build_object( 'id', items.id, @@ -282,20 +282,66 @@ class PlayerService: 'stack_size', items.stack_size, 'quality_level', items.quality_level, 'is_new', items.is_new, + 'position_index', items.position_index, 'stats_text', items.stats::text ) ORDER BY items.position_index ) FILTER (WHERE items.id IS NOT NULL), '[]') as item_list FROM dune.inventories i LEFT JOIN dune.items ON i.id = items.inventory_id WHERE i.actor_id = %s - GROUP BY i.id, i.actor_id, i.inventory_type + GROUP BY i.id, i.actor_id, i.inventory_type, i.max_item_count, i.max_item_volume ORDER BY i.inventory_type """, [player_id]) or [] for inv in inventories: - inv['item_list'] = inv.get('item_list', []) or [] + if not isinstance(inv, dict): + logger.warning(f"Inventory row is not a dict: {type(inv)}") + continue + raw_items = inv.get('item_list', []) or [] + if isinstance(raw_items, str): + try: + import json + raw_items = json.loads(raw_items) + except (json.JSONDecodeError, TypeError): + raw_items = [] + parsed_items = [] + for item in raw_items: + if not isinstance(item, dict): + logger.warning(f"Item is not a dict: {type(item)}, value: {repr(item)[:100]}") + continue + new_item = dict(item) + stats_text = new_item.pop('stats_text', None) + stats = {} + if stats_text: + try: + import json + stats = json.loads(stats_text) + except (json.JSONDecodeError, TypeError): + stats = {} + new_item['stats'] = stats + dur_stats = stats.get('FItemStackAndDurabilityStats') + if isinstance(dur_stats, dict): + new_item['durability'] = dur_stats.get('CurrentDurability') + new_item['max_durability'] = dur_stats.get('DecayedMaxDurability') + elif isinstance(dur_stats, list) and dur_stats: + new_item['durability'] = dur_stats[0].get('CurrentDurability') if isinstance(dur_stats[0], dict) else None + new_item['max_durability'] = dur_stats[0].get('DecayedMaxDurability') if isinstance(dur_stats[0], dict) else None + else: + new_item['durability'] = None + new_item['max_durability'] = None + weapon_stats = stats.get('FWeaponItemStats') + if isinstance(weapon_stats, dict): + new_item['ammo'] = weapon_stats.get('CurrentAmmo') + elif isinstance(weapon_stats, list) and weapon_stats: + new_item['ammo'] = weapon_stats[0].get('CurrentAmmo') if isinstance(weapon_stats[0], dict) else None + else: + new_item['ammo'] = None + parsed_items.append(new_item) + inv['item_list'] = parsed_items return inventories except Exception as e: logger.warning(f"Failed to get inventories: {e}") + import traceback + logger.warning(traceback.format_exc()) inventories = self.db.query( "SELECT i.* FROM dune.inventories i WHERE i.actor_id = %s ORDER BY i.inventory_type", [player_id] diff --git a/app/utils/constants.py b/app/utils/constants.py index 9d3e3ae..3c53c1f 100644 --- a/app/utils/constants.py +++ b/app/utils/constants.py @@ -1,4 +1,5 @@ """Shared data constants and helpers""" +import json INVENTORY_TYPE_LABELS = { 0: 'Main Inventory', @@ -17,6 +18,48 @@ INVENTORY_TYPE_LABELS = { 33: 'Augment Slots', } +# Inventory types to hide from display +INVENTORY_HIDDEN_TYPES = {14, 27} + +# Inventory types to show in the collapsible "Unknown" section +INVENTORY_UNKNOWN_TYPES = {12, 20, 25, 29, 30, 31, 32, 33} + +# Primary inventory types shown as main sections +INVENTORY_PRIMARY_TYPES = {0, 1, 5, 15} + +# Equipped item slot labels (by position_index 0-9) +EQUIPPED_SLOT_LABELS = { + 0: 'Head', + 1: 'Chest', + 2: 'Legs', + 3: 'Gloves', + 4: 'Feet', + 5: 'Unknown Spare Slot', + 6: 'Portable Light', + 7: 'Suspensor Belt', + 8: 'Power Pack', + 9: 'Shield', +} + +# Quality tier colors +QUALITY_TIERS = { + 0: {'label': 'Common', 'color': '#9a8a7a'}, + 1: {'label': 'Uncommon', 'color': '#27ae60'}, + 2: {'label': 'Rare', 'color': '#3498db'}, + 3: {'label': 'Epic', 'color': '#9b59b6'}, + 4: {'label': 'Legendary', 'color': '#f39c12'}, +} + + +def parse_stats(stats_text): + """Parse item stats JSONB text into a dict.""" + if not stats_text: + return {} + try: + return json.loads(stats_text) + except (json.JSONDecodeError, TypeError): + return {} + CURRENCY_ID_LABELS = { 0: 'Solari Credits', 1: 'House Script', diff --git a/static/style.css b/static/style.css index 15aa30d..1a6f21b 100644 --- a/static/style.css +++ b/static/style.css @@ -407,6 +407,359 @@ td a:hover { text-decoration: underline; } .inv-type:first-child { margin-top: 0; } +.inv-section-header { + display: flex; + align-items: center; + justify-content: space-between; + margin: 16px 0 8px; + font-size: 14px; + font-weight: 600; +} + +.inv-section-header .inv-meta { + font-size: 11px; + font-weight: 400; + color: var(--text-muted); + margin-left: 8px; +} + +/* Main Inventory Grid */ +.inv-grid { + display: grid; + grid-template-columns: repeat(5, 1fr); + gap: 6px; + margin-bottom: 12px; +} + +.inv-grid-slot { + aspect-ratio: 1; + border: 2px dashed var(--border); + border-radius: 8px; + display: flex; + flex-direction: column; + align-items: center; + justify-content: center; + cursor: pointer; + position: relative; + transition: all 0.15s; + background: var(--card-bg); + min-height: 80px; + overflow: hidden; +} + +.inv-grid-slot:hover { + border-color: var(--primary); + background: var(--hover); +} + +.inv-grid-slot.has-item { + border-style: solid; + border-color: var(--border); +} + +.inv-grid-slot.has-item:hover { + border-color: var(--primary); + box-shadow: 0 0 0 2px rgba(201,162,78,0.2); +} + +.inv-slot-icon { + font-size: 22px; + line-height: 1; + margin-bottom: 2px; + color: var(--text-light); +} + +.inv-slot-name { + font-size: 8px; + color: var(--text-muted); + text-align: center; + line-height: 1.1; + max-width: 90%; + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; +} + +.inv-slot-stack { + position: absolute; + bottom: 2px; + right: 4px; + font-size: 9px; + font-weight: 700; + color: var(--text); + background: rgba(255,255,255,0.8); + padding: 0 3px; + border-radius: 2px; +} + +.inv-slot-ammo { + position: absolute; + top: 2px; + right: 4px; + font-size: 9px; + font-weight: 600; + color: #e67e22; +} + +.inv-slot-durability-bar { + position: absolute; + bottom: 0; + left: 0; + right: 0; + height: 3px; + background: var(--border); + border-radius: 0 0 4px 4px; + overflow: hidden; +} + +.inv-slot-durability-fill { + height: 100%; + background: var(--success); + transition: width 0.2s; +} + +.inv-slot-durability-fill.medium { background: #f39c12; } +.inv-slot-durability-fill.low { background: var(--danger); } + +.inv-slot-quality { + position: absolute; + top: 2px; + left: 4px; + width: 6px; + height: 6px; + border-radius: 50%; +} + +.inv-slot-empty-icon { + color: var(--text-muted); + opacity: 0.3; + font-size: 18px; +} + +/* Equipped Items Grid */ +.inv-equipped-grid { + display: grid; + grid-template-columns: repeat(5, 1fr); + gap: 8px; + margin-bottom: 12px; +} + +.inv-equipped-slot { + border: 2px solid var(--border); + border-radius: 8px; + padding: 8px; + text-align: center; + cursor: pointer; + position: relative; + transition: all 0.15s; + background: var(--card-bg); + min-height: 80px; + display: flex; + flex-direction: column; + align-items: center; + justify-content: center; +} + +.inv-equipped-slot:hover { + border-color: var(--primary); + background: var(--hover); +} + +.inv-equipped-slot.has-item { + border-style: solid; +} + +.inv-equipped-label { + font-size: 10px; + text-transform: uppercase; + letter-spacing: 0.5px; + color: var(--text-muted); + margin-bottom: 4px; + font-weight: 600; +} + +.inv-equipped-slot .inv-slot-icon { + font-size: 22px; +} + +.inv-equipped-slot .inv-slot-name { + font-size: 9px; +} + +/* Key Items List */ +.inv-key-items { + display: flex; + flex-direction: column; + gap: 4px; + margin-bottom: 12px; +} + +.inv-key-item { + display: flex; + align-items: center; + gap: 8px; + padding: 6px 10px; + border: 1px solid var(--border); + border-radius: 6px; + cursor: pointer; + transition: all 0.15s; + background: var(--card-bg); +} + +.inv-key-item:hover { + border-color: var(--primary); + background: var(--hover); +} + +.inv-key-item .inv-slot-icon { + font-size: 16px; +} + +.inv-key-item .inv-slot-name { + font-size: 12px; + flex: 1; +} + +/* Unknown Section */ +.inv-unknown-section { + margin-top: 12px; +} + +.inv-unknown-toggle { + display: flex; + align-items: center; + justify-content: space-between; + padding: 8px 12px; + background: var(--card-bg); + border: 1px solid var(--border); + border-radius: 6px; + cursor: pointer; + font-size: 13px; + font-weight: 600; + color: var(--text); + transition: all 0.15s; + width: 100%; +} + +.inv-unknown-toggle:hover { + border-color: var(--primary); + background: var(--hover); +} + +.inv-unknown-toggle .arrow { + transition: transform 0.2s; + font-size: 10px; + color: var(--text-muted); +} + +.inv-unknown-toggle .arrow.open { + transform: rotate(90deg); +} + +.inv-unknown-content { + display: none; + margin-top: 8px; +} + +.inv-unknown-content.open { + display: block; +} + +.inv-unknown-sub { + margin-bottom: 12px; +} + +.inv-unknown-sub-header { + font-size: 12px; + font-weight: 600; + color: var(--text-light); + margin-bottom: 6px; + padding-bottom: 4px; + border-bottom: 1px solid var(--border); +} + +.inv-unknown-grid { + display: grid; + grid-template-columns: repeat(auto-fill, minmax(60px, 1fr)); + gap: 4px; +} + +.inv-unknown-grid .inv-grid-slot { + min-height: 56px; + border-width: 1px; +} + +/* Item Edit Modal */ +.item-edit-modal .item-preview { + display: flex; + align-items: center; + gap: 12px; + padding: 12px; + background: var(--hover); + border-radius: 8px; + margin-bottom: 16px; +} + +.item-edit-modal .item-preview .item-icon { + font-size: 32px; + color: var(--text-light); +} + +.item-edit-modal .item-preview .item-info { + flex: 1; +} + +.item-edit-modal .item-preview .item-name { + font-weight: 600; + font-size: 14px; +} + +.item-edit-modal .item-preview .item-id { + font-size: 11px; + color: var(--text-muted); + font-family: monospace; +} + +.item-edit-form .form-row { + display: flex; + align-items: center; + gap: 8px; + margin-bottom: 10px; +} + +.item-edit-form .form-row label { + min-width: 80px; + font-size: 13px; + color: var(--text-light); + margin: 0; +} + +.item-edit-form .form-row input { + flex: 1; + padding: 6px 10px; + border: 1px solid var(--border); + border-radius: 4px; + font-size: 13px; + background: var(--card-bg); + color: var(--text); +} + +.item-edit-form .form-row input:focus { + outline: none; + border-color: var(--primary); + box-shadow: 0 0 0 2px rgba(201,162,78,0.15); +} + +.item-edit-actions { + display: flex; + gap: 8px; + margin-top: 16px; +} + +.item-edit-actions .btn-save { flex: 1; } +.item-edit-actions .btn-cancel { flex: 1; } +.item-edit-actions .btn-danger { flex: 0 0 auto; } + /* Info box */ .info-box { background: #eaf2f8; diff --git a/templates/player_detail.html b/templates/player_detail.html index ebfff9c..20b816e 100644 --- a/templates/player_detail.html +++ b/templates/player_detail.html @@ -293,31 +293,215 @@ {% endif %}
- {% for inv in inventories %} -
{{ inv.inventory_type | inv_label }} (ID: {{ inv.id }}, Slots: {{ inv.max_item_count or '?' }}, Volume: {{ inv.max_item_volume or '?' }}) + {% for inv in primary_inventories %} + {% if inv.inventory_type == 0 %} +
+ {{ inv.inventory_type | inv_label }}(ID: {{ inv.id }}, Slots: {{ inv.max_item_count or '?' }}, Volume: {{ inv.max_item_volume or '?' }}) + {% if not is_online %} + + {% endif %} +
+
+ {% for item in inv.item_list %} +
+
📦
+
{{ item.template_id | truncate(20) }}
+ {% if item.stack_size and item.stack_size > 1 %} +
{{ item.stack_size }}
+ {% endif %} + {% if item.ammo %} +
🔥{{ item.ammo }}
+ {% endif %} + {% if item.durability and item.max_durability and item.max_durability > 0 %} + {% set dur_pct = (item.durability / item.max_durability * 100) | int %} + {% set dur_class = 'low' if dur_pct < 30 else ('medium' if dur_pct < 70 else '') %} +
+ {% endif %} + {% if item.quality_level and item.quality_level > 0 %} + {% set tier_color = quality_tiers[item.quality_level].color if item.quality_level in quality_tiers else '#9a8a7a' %} +
+ {% endif %} +
+ {% endfor %} + {% set item_count = inv.item_list | length %} + {% set max_slots = inv.max_item_count or 35 %} + {% for i in range(item_count, max_slots) %} +
+
+
+
+ {% endfor %} +
+ + {% elif inv.inventory_type == 1 %} +
+ {{ inv.inventory_type | inv_label }}(ID: {{ inv.id }}) + {% if not is_online %} + + {% endif %} +
+
+ {% for slot_idx in range(10) %} + {% set slot_label = equipped_slot_labels[slot_idx] if slot_idx in equipped_slot_labels else 'Slot ' ~ slot_idx %} + {% set slot_item = inv.item_list | selectattr('position_index', 'equalto', slot_idx) | first %} + {% if slot_item %} +
+
{{ slot_label }}
+
📦
+
{{ slot_item.template_id | truncate(15) }}
+ {% if slot_item.stack_size and slot_item.stack_size > 1 %} +
{{ slot_item.stack_size }}
+ {% endif %} + {% if slot_item.ammo %} +
🔥{{ slot_item.ammo }}
+ {% endif %} + {% if slot_item.durability and slot_item.max_durability and slot_item.max_durability > 0 %} + {% set dur_pct = (slot_item.durability / slot_item.max_durability * 100) | int %} + {% set dur_class = 'low' if dur_pct < 30 else ('medium' if dur_pct < 70 else '') %} +
+ {% endif %} + {% if slot_item.quality_level and slot_item.quality_level > 0 %} + {% set tier_color = quality_tiers[slot_item.quality_level].color if slot_item.quality_level in quality_tiers else '#9a8a7a' %} +
+ {% endif %} +
+ {% else %} +
+
{{ slot_label }}
+
+
+
+ {% endif %} + {% endfor %} +
+ + {% elif inv.inventory_type == 15 %} +
+ {{ inv.inventory_type | inv_label }}(ID: {{ inv.id }}) {% if not is_online %} {% endif %}
{% if inv.item_list %} -
- - {% if not is_online %}{% endif %} - - {% for item in inv.item_list %} - - - - - - {% if not is_online %}{% endif %} - - {% endfor %} - -
TemplateStackQualityNewActions
{{ item.template_id }}{{ item.stack_size }} {% if not is_online %}{% endif %}{{ item.quality_level or 0 }} {% if not is_online %}{% endif %}{{ item.is_new or False }}
+
+ {% for item in inv.item_list %} +
+
📦
+
{{ item.template_id }}
+ {% if item.stack_size and item.stack_size > 1 %} + x{{ item.stack_size }} + {% endif %} +
+ {% endfor %}
{% else %} -

(empty)

+

(empty)

+ {% endif %} + + {% else %} +
+ {{ inv.inventory_type | inv_label }} (ID: {{ inv.id }}) + {% if not is_online %} + + {% endif %} +
+ {% if inv.item_list %} +
+ {% for item in inv.item_list %} +
+
📦
+
{{ item.template_id | truncate(15) }}
+ {% if item.stack_size and item.stack_size > 1 %} +
{{ item.stack_size }}
+ {% endif %} + {% if item.ammo %} +
🔥{{ item.ammo }}
+ {% endif %} + {% if item.durability and item.max_durability and item.max_durability > 0 %} + {% set dur_pct = (item.durability / item.max_durability * 100) | int %} + {% set dur_class = 'low' if dur_pct < 30 else ('medium' if dur_pct < 70 else '') %} +
+ {% endif %} +
+ {% endfor %} +
+ {% else %} +

(empty)

+ {% endif %} + {% endif %} + + {% endfor %} + + {% if unknown_inventories %} +
+ +
+ {% for inv in unknown_inventories %} +
+
{{ inv.inventory_type | inv_label }} (ID: {{ inv.id }})
+ {% if inv.item_list %} +
+ {% for item in inv.item_list %} +
+
📦
+
{{ item.template_id | truncate(20) }}
+ {% if item.stack_size and item.stack_size > 1 %} +
{{ item.stack_size }}
+ {% endif %} + {% if item.ammo %} +
🔥{{ item.ammo }}
+ {% endif %} + {% if item.durability and item.max_durability and item.max_durability > 0 %} + {% set dur_pct = (item.durability / item.max_durability * 100) | int %} + {% set dur_class = 'low' if dur_pct < 30 else ('medium' if dur_pct < 70 else '') %} +
+ {% endif %} + {% if item.quality_level and item.quality_level > 0 %} + {% set tier_color = quality_tiers[item.quality_level].color if item.quality_level in quality_tiers else '#9a8a7a' %} +
+ {% endif %} +
+ {% endfor %} +
+ {% else %} +

(empty)

+ {% endif %} +
+ {% endfor %} +
+
+ {% endif %} + + {% for inv in other_inventories %} +
+ {{ inv.inventory_type | inv_label }} (ID: {{ inv.id }}) + {% if not is_online %} + + {% endif %} +
+ {% if inv.item_list %} +
+ {% for item in inv.item_list %} +
+
📦
+
{{ item.template_id | truncate(15) }}
+ {% if item.stack_size and item.stack_size > 1 %} +
{{ item.stack_size }}
+ {% endif %} + {% if item.ammo %} +
🔥{{ item.ammo }}
+ {% endif %} + {% if item.durability and item.max_durability and item.max_durability > 0 %} + {% set dur_pct = (item.durability / item.max_durability * 100) | int %} + {% set dur_class = 'low' if dur_pct < 30 else ('medium' if dur_pct < 70 else '') %} +
+ {% endif %} +
+ {% endfor %} +
+ {% else %} +

(empty)

{% endif %} {% endfor %}
@@ -453,6 +637,49 @@
+ + + {% endif %} {% endblock %} @@ -557,6 +784,13 @@ async function submitVitalsEdit() { return false; } +function toggleUnknownSection(btn) { + const content = btn.nextElementSibling; + const arrow = btn.querySelector('.arrow'); + content.classList.toggle('open'); + arrow.classList.toggle('open'); +} + async function editItem(itemId, field, currentValue) { const newValue = prompt(`Edit ${field} for item ${itemId}:`, currentValue); if (newValue === null || newValue === currentValue) return; @@ -568,9 +802,7 @@ async function editItem(itemId, field, currentValue) { const resp = await csrfFetch('/api/edit_item', { method: 'POST', body: data }); const result = await resp.json(); if (result.success) { - const span = document.getElementById('item-' + field.replace('_', '-') + '-' + itemId); - if (span) span.textContent = result.value; - else location.reload(); + location.reload(); } else { alert('Error: ' + (result.error || 'Unknown error')); } @@ -579,7 +811,63 @@ async function editItem(itemId, field, currentValue) { } } -async function deleteItem(itemId, templateName) { +function openItemEditModal(itemId, templateName, stackSize, quality, durability, maxDurability, ammo, invId) { + document.getElementById('item-edit-item-id').value = itemId; + document.getElementById('item-edit-inv-id').value = invId; + document.getElementById('item-edit-name').textContent = templateName; + document.getElementById('item-edit-id').textContent = 'ID: ' + itemId; + document.getElementById('item-edit-stack').value = stackSize || 1; + document.getElementById('item-edit-quality').value = quality || 0; + document.getElementById('item-edit-durability').value = durability !== null ? durability : ''; + document.getElementById('item-edit-max-durability').value = maxDurability !== null ? maxDurability : ''; + document.getElementById('item-edit-ammo').value = ammo !== null ? ammo : ''; + openModal('item-edit-modal'); +} + +async function submitItemEdit() { + const itemId = document.getElementById('item-edit-item-id').value; + const invId = document.getElementById('item-edit-inv-id').value; + const stackSize = document.getElementById('item-edit-stack').value; + const quality = document.getElementById('item-edit-quality').value; + const durability = document.getElementById('item-edit-durability').value; + const maxDurability = document.getElementById('item-edit-max-durability').value; + const ammo = document.getElementById('item-edit-ammo').value; + + const fields = { stack_size: stackSize, quality_level: quality }; + if (durability) fields.durability = parseFloat(durability); + if (maxDurability) fields.max_durability = parseFloat(maxDurability); + if (ammo) fields.ammo = parseInt(ammo); + + let allSuccess = true; + for (const [field, value] of Object.entries(fields)) { + const data = new FormData(); + data.append('item_id', itemId); + data.append('field', field); + data.append('value', value); + try { + const resp = await csrfFetch('/api/edit_item', { method: 'POST', body: data }); + const result = await resp.json(); + if (!result.success) { + alert('Error updating ' + field + ': ' + (result.error || 'Unknown error')); + allSuccess = false; + break; + } + } catch (e) { + alert('Error: ' + e.message); + allSuccess = false; + break; + } + } + + if (allSuccess) { + closeModal('item-edit-modal'); + location.reload(); + } +} + +async function submitItemDelete() { + const itemId = document.getElementById('item-edit-item-id').value; + const templateName = document.getElementById('item-edit-name').textContent; if (!confirm(`Delete item "${templateName}" (ID: ${itemId})? This cannot be undone.`)) return; const data = new FormData(); data.append('item_id', itemId); @@ -587,8 +875,8 @@ async function deleteItem(itemId, templateName) { const resp = await csrfFetch('/api/delete_item', { method: 'POST', body: data }); const result = await resp.json(); if (result.success) { - const row = document.getElementById('item-row-' + itemId); - if (row) row.remove(); + closeModal('item-edit-modal'); + location.reload(); } else { alert('Error: ' + (result.error || 'Unknown error')); }