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 %}
| Template | Stack | Quality | New | {% if not is_online %}Actions | {% endif %}
|---|---|---|---|---|
| {{ 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 }} | - {% if not is_online %}{% endif %} - |
(empty)
+(empty)
+ {% endif %} + + {% else %} +(empty)
+ {% endif %} + {% endif %} + + {% endfor %} + + {% if unknown_inventories %} +(empty)
+ {% endif %} +(empty)
{% endif %} {% endfor %}