WIP: Inventory grid redesign (unfinished - do not use)
This commit is contained in:
1 parent
f8e08608e2
commit
3453a1ebde
7 files changed
+807
-30
No files matched your search
+27
-2
@@ -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')
|
||||
|
||||
+18
-1
@@ -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),
|
||||
|
||||
+49
-3
@@ -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]
|
||||
|
||||
@@ -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',
|
||||
|
||||
Reference in new issue
Block a user