624 lines
27 KiB
HTML
624 lines
27 KiB
HTML
{% extends "base.html" %}
|
|
{% block title %}{{ player.player_name if player else 'Player' }} - Dune Awakening Dashboard{% endblock %}
|
|
{% block content %}
|
|
|
|
{% if tunnel_down %}
|
|
<div class="error-banner danger">
|
|
<strong>SSH Tunnel Not Detected</strong><br>
|
|
Start the SSH tunnel first, then refresh.
|
|
</div>
|
|
{% elif db_error %}
|
|
<div class="error-banner danger"><strong>Database Error:</strong> {{ db_error }}</div>
|
|
{% elif not_found %}
|
|
<div class="error-banner danger"><strong>Player Not Found</strong><br>The requested player character does not exist.</div>
|
|
{% else %}
|
|
|
|
<div class="page-header">
|
|
<h1>{{ player.player_name }}</h1>
|
|
<p>Actor ID: {{ player.id }} · Controller ID: {{ player.player_controller_id or 'N/A' }}
|
|
{% if player.online_status %}
|
|
· <span class="badge badge-{{ player.online_status.lower() }}">{{ player.online_status }}</span>
|
|
{% endif %}
|
|
{% if player.life_state %}
|
|
· <span class="badge badge-{{ player.life_state.lower() }}">{{ player.life_state }}</span>
|
|
{% endif %}
|
|
</p>
|
|
</div>
|
|
|
|
{% if vitals and vitals.max_health %}
|
|
<div class="vitals-bar">
|
|
{% if not is_online %}
|
|
<button onclick="openModal('vitals-modal')" class="btn-edit" style="margin-right:8px;">Edit Vitals</button>
|
|
{% endif %}
|
|
<div class="vitals-item">
|
|
<span class="vitals-label">Health</span>
|
|
<span class="vitals-value" style="color:#e74c3c;">{{ "%.0f"|format(vitals.current_health or 0) }}/{{ "%.0f"|format(vitals.max_health or 0) }}</span>
|
|
{% if is_online %}<span style="font-size:10px;color:#e67e22;margin-left:4px;">(WIP)</span>{% else %}<span style="font-size:10px;color:var(--text-muted);margin-left:4px;">(WIP)</span>{% endif %}
|
|
</div>
|
|
<div class="vitals-divider"></div>
|
|
<div class="vitals-item">
|
|
<span class="vitals-label">Hydration</span>
|
|
<span class="vitals-value" style="color:#3498db;">{{ "%.1f"|format(vitals.current_hydration | float if vitals.current_hydration else 0) }}</span>
|
|
{% if is_online %}<span style="font-size:10px;color:#2ecc71;margin-left:4px;">(live)</span>{% endif %}
|
|
</div>
|
|
<div class="vitals-divider"></div>
|
|
<div class="vitals-item">
|
|
<span class="vitals-label">Spice</span>
|
|
<span class="vitals-value" style="color:#f39c12;">{{ "%.0f"|format(vitals.current_spice | float if vitals.current_spice else 0) }}</span>
|
|
{% if is_online %}<span style="font-size:10px;color:#2ecc71;margin-left:4px;">(live)</span>{% endif %}
|
|
</div>
|
|
{% if vitals.spice_addiction_level is not none or vitals.spice_tolerance is not none %}
|
|
<div class="vitals-divider"></div>
|
|
<div class="vitals-item">
|
|
<span class="vitals-label">Spice Addiction</span>
|
|
<span class="vitals-value" style="color:#9b59b6;">{{ "%.1f"|format(vitals.spice_addiction_level | float if vitals.spice_addiction_level else 0) }}</span>
|
|
</div>
|
|
<div class="vitals-divider"></div>
|
|
<div class="vitals-item">
|
|
<span class="vitals-label">Spice Tolerance</span>
|
|
<span class="vitals-value" style="color:#9b59b6;">{{ "%.1f"|format(vitals.spice_tolerance | float if vitals.spice_tolerance else 0) }}</span>
|
|
</div>
|
|
{% endif %}
|
|
{% if is_online %}
|
|
<div style="width:100%;font-size:11px;color:#e67e22;margin-top:4px;">Player is online — edit vitals only when offline. Health data is currently WIP.</div>
|
|
{% endif %}
|
|
</div>
|
|
{% endif %}
|
|
|
|
<div class="detail-section">
|
|
<h2>Account Info</h2>
|
|
<div class="detail-grid">
|
|
<div class="detail-item">
|
|
<div class="dlabel">Character Name</div>
|
|
<div class="dvalue">{{ player.player_name or 'Unknown' }}</div>
|
|
</div>
|
|
<div class="detail-item">
|
|
<div class="dlabel">Funcom ID</div>
|
|
<div class="dvalue">{{ player.funcom_id or 'N/A' }}</div>
|
|
</div>
|
|
<div class="detail-item">
|
|
<div class="dlabel">Email / User</div>
|
|
<div class="dvalue">{{ player.account_email }}</div>
|
|
</div>
|
|
<div class="detail-item">
|
|
<div class="dlabel">Platform ID</div>
|
|
<div class="dvalue" style="font-size:12px;">{{ player.platform_id or 'N/A' }}</div>
|
|
</div>
|
|
<div class="detail-item">
|
|
<div class="dlabel">Map</div>
|
|
<div class="dvalue">{{ player.map or 'N/A' }}</div>
|
|
</div>
|
|
<div class="detail-item">
|
|
<div class="dlabel">Position</div>
|
|
<div class="dvalue" style="font-size:11px;font-family:monospace;">{{ player.transform_text or 'N/A' }}</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
{% if player.last_login_time or player.last_avatar_activity %}
|
|
<div class="detail-section">
|
|
<h2>Activity</h2>
|
|
<div class="detail-grid">
|
|
{% if player.last_login_time %}
|
|
<div class="detail-item">
|
|
<div class="dlabel">Last Login</div>
|
|
<div class="dvalue">{{ player.last_login_time.strftime('%Y-%m-%d %H:%M UTC') }}</div>
|
|
</div>
|
|
{% endif %}
|
|
{% if player.last_avatar_activity %}
|
|
<div class="detail-item">
|
|
<div class="dlabel">Last Activity</div>
|
|
<div class="dvalue">{{ player.last_avatar_activity.strftime('%Y-%m-%d %H:%M UTC') }}</div>
|
|
</div>
|
|
{% endif %}
|
|
</div>
|
|
</div>
|
|
{% endif %}
|
|
|
|
<div style="display:grid;grid-template-columns:1fr 1fr;gap:20px;margin-bottom:20px;">
|
|
<div class="card">
|
|
<div class="card-header">Faction
|
|
{% if not is_online %}
|
|
<button onclick="openModal('faction-modal')" class="btn-edit">Edit</button>
|
|
{% endif %}
|
|
</div>
|
|
<div class="card-body">
|
|
{% if player.faction_name %}
|
|
<span class="badge badge-{{ player.faction_name.lower() }}">{{ player.faction_name }}</span>
|
|
{% if player.utc_time_faction_change %}<br><small style="color:var(--text-light);">Since {{ player.utc_time_faction_change.strftime('%Y-%m-%d') }}</small>{% endif %}
|
|
{% else %}<div class="empty">No faction</div>{% endif %}
|
|
</div>
|
|
</div>
|
|
<div class="card">
|
|
<div class="card-header">Guild</div>
|
|
<div class="card-body">
|
|
{% if guild %}
|
|
<div><a href="/guilds/{{ guild.guild_id }}" style="font-weight:600;">{{ guild.guild_name }}</a></div>
|
|
<div><span class="badge badge-{{ guild.faction_name.lower() if guild.faction_name else 'none' }}">{{ guild.faction_name or 'No faction' }}</span></div>
|
|
<div><span class="badge badge-{{ fmt_role(guild.role_id).lower() }}">{{ fmt_role(guild.role_id) }}</span></div>
|
|
{% if guild.guild_description %}<p style="margin-top:8px;font-size:13px;color:var(--text-light);">{{ guild.guild_description }}</p>{% endif %}
|
|
{% else %}<div class="empty">Not in a guild</div>{% endif %}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="detail-section">
|
|
<h2>Currencies</h2>
|
|
<div class="card">
|
|
<div class="table-wrap">
|
|
<table>
|
|
<thead><tr><th>Currency</th><th>Balance</th></tr></thead>
|
|
<tbody>
|
|
{% for c in currency %}
|
|
<tr>
|
|
<td>{{ c.currency_id | currency_label }}</td>
|
|
<td style="font-weight:600;">{{ c.balance | format_number }}</td>
|
|
</tr>
|
|
{% else %}
|
|
<tr><td colspan="2" class="empty">No currency data</td></tr>
|
|
{% endfor %}
|
|
</tbody>
|
|
</table>
|
|
<div style="font-size:10px;color:var(--text-muted);padding:4px 8px;">Note: Currency values may be stale due to game server behavior</div>
|
|
</div>
|
|
{% if is_online %}
|
|
<div style="font-size:12px;color:#e67e22;padding:8px 16px;">Player is online — editing disabled. Log out first.</div>
|
|
{% else %}
|
|
<button onclick="openCurrenciesModal()" class="btn-edit" style="margin:8px 16px;">Edit</button>
|
|
{% endif %}
|
|
<div style="font-size:11px;color:var(--text-muted);padding:4px 16px 8px;">Read-only. Balances reflect last game save — game server writes deltas on top of DB value.</div>
|
|
</div>
|
|
</div>
|
|
|
|
{% if specialization or tech_knowledge is not none %}
|
|
<div class="detail-section">
|
|
<h2>Specialization & XP
|
|
{% if not is_online %}
|
|
<button onclick="openModal('spec-modal')" class="btn-edit">Edit</button>
|
|
{% endif %}
|
|
</h2>
|
|
<div class="card">
|
|
<div class="table-wrap">
|
|
<table>
|
|
<thead><tr><th>Track</th><th>XP</th><th>Level</th></tr></thead>
|
|
<tbody>
|
|
{% for s in specialization %}
|
|
<tr><td>{{ s.track_type }}</td><td>{{ s.xp_amount | format_number }}</td><td>{{ s.level }}</td></tr>
|
|
{% endfor %}
|
|
{% if tech_knowledge is not none %}
|
|
<tr><td>Tech Knowledge Points</td><td>{{ tech_knowledge | format_number }}</td><td>—</td></tr>
|
|
{% endif %}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
{% endif %}
|
|
|
|
{% if faction_reputation %}
|
|
<div class="detail-section">
|
|
<h2>Faction Reputation</h2>
|
|
<div class="card">
|
|
<div class="table-wrap">
|
|
<table>
|
|
<thead><tr><th>Faction</th><th>Reputation</th></tr></thead>
|
|
<tbody>
|
|
{% for fr in faction_reputation %}
|
|
<tr>
|
|
<td>{{ fr.faction_name }}</td>
|
|
<td style="font-weight:600;">{{ fr.reputation_amount | format_number }}</td>
|
|
</tr>
|
|
{% endfor %}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
{% endif %}
|
|
|
|
{% if landsraad_info and landsraad_info.daily_reward_charges is not none %}
|
|
<div class="detail-section">
|
|
<h2>Landsraad</h2>
|
|
<div class="card">
|
|
<div class="table-wrap">
|
|
<table>
|
|
<thead><tr><th>Info</th><th>Value</th></tr></thead>
|
|
<tbody>
|
|
{% if landsraad_info.daily_reward_charges is not none %}
|
|
<tr><td>Daily Reward Charges</td><td>{{ landsraad_info.daily_reward_charges }}</td></tr>
|
|
{% endif %}
|
|
{% if landsraad_info.last_viewed_term_id is not none %}
|
|
<tr><td>Last Viewed Term</td><td>{{ landsraad_info.last_viewed_term_id }}</td></tr>
|
|
{% endif %}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
{% endif %}
|
|
|
|
{% if vehicles %}
|
|
<div class="detail-section">
|
|
<h2>Vehicles ({{ vehicles|length }})</h2>
|
|
<div class="card">
|
|
<div class="table-wrap">
|
|
<table>
|
|
<thead><tr><th>Type</th><th>Name</th><th>Map</th><th>Access</th><th>Position</th></tr></thead>
|
|
<tbody>
|
|
{% for v in vehicles %}
|
|
<tr>
|
|
<td style="font-size:12px;">{{ v.class | class_name }}</td>
|
|
<td>{{ v.actor_name or 'N/A' }}</td>
|
|
<td>{{ v.map or 'N/A' }}</td>
|
|
<td>{% if v.ownership_rank == 1 %}<span class="badge badge-leader">Owner</span>{% elif v.ownership_rank %}<span class="badge badge-officer">Rank {{ v.ownership_rank }}</span>{% endif %}</td>
|
|
<td style="font-size:11px;font-family:monospace;">{{ v.transform_text or '' }}</td>
|
|
</tr>
|
|
{% endfor %}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
{% endif %}
|
|
|
|
{% if buildings %}
|
|
<div class="detail-section">
|
|
<h2>Buildings ({{ buildings|length }})</h2>
|
|
<div class="card">
|
|
<div class="table-wrap">
|
|
<table>
|
|
<thead><tr><th>ID</th><th>Class</th><th>Map</th><th>Instances</th><th>Position</th></tr></thead>
|
|
<tbody>
|
|
{% for b in buildings %}
|
|
<tr>
|
|
<td>{{ b.id }}</td>
|
|
<td style="font-size:12px;">{{ b.class | class_name }}</td>
|
|
<td>{{ b.map or 'N/A' }}</td>
|
|
<td>{{ b.instance_count }}</td>
|
|
<td style="font-size:11px;font-family:monospace;">{{ b.transform_text or '' }}</td>
|
|
</tr>
|
|
{% endfor %}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
{% endif %}
|
|
|
|
{% if inventories %}
|
|
<div class="detail-section">
|
|
<h2>Inventory</h2>
|
|
{% if is_online %}
|
|
<div style="font-size:12px;color:#e67e22;padding:0 16px 8px;">Player is online — editing disabled. Log out first.</div>
|
|
{% endif %}
|
|
<div class="card">
|
|
<div class="card-body">
|
|
{% for inv in inventories %}
|
|
<div class="inv-type">{{ inv.inventory_type | inv_label }} (ID: {{ inv.id }}, Slots: {{ inv.max_item_count or '?' }}, Volume: {{ inv.max_item_volume or '?' }})
|
|
{% if not is_online %}
|
|
<button onclick="openAddItemModal({{ inv.id }})" class="btn-edit" style="font-size:11px;padding:2px 8px;">+ Add Item</button>
|
|
{% endif %}
|
|
</div>
|
|
{% if inv.item_list %}
|
|
<div class="table-wrap" style="margin-bottom:12px;">
|
|
<table>
|
|
<thead><tr><th>Template</th><th>Stack</th><th>Quality</th><th>New</th>{% if not is_online %}<th>Actions</th>{% endif %}</tr></thead>
|
|
<tbody>
|
|
{% for item in inv.item_list %}
|
|
<tr id="item-row-{{ item.id }}">
|
|
<td style="font-size:11px;max-width:300px;word-break:break-all;" id="item-template-{{ item.id }}">{{ item.template_id }}</td>
|
|
<td><span id="item-stack-{{ item.id }}">{{ item.stack_size }}</span> {% if not is_online %}<button onclick="editItem({{ item.id }}, 'stack_size', {{ item.stack_size }})" class="btn-edit" style="font-size:10px;padding:1px 5px;">✎</button>{% endif %}</td>
|
|
<td><span id="item-quality-{{ item.id }}">{{ item.quality_level or 0 }}</span> {% if not is_online %}<button onclick="editItem({{ item.id }}, 'quality_level', {{ item.quality_level or 0 }})" class="btn-edit" style="font-size:10px;padding:1px 5px;">✎</button>{% endif %}</td>
|
|
<td>{{ item.is_new or False }}</td>
|
|
{% if not is_online %}<td><button onclick="deleteItem({{ item.id }}, '{{ item.template_id }}')" class="btn-danger" style="font-size:10px;padding:1px 5px;">Del</button></td>{% endif %}
|
|
</tr>
|
|
{% endfor %}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
{% else %}
|
|
<p style="color:var(--text-muted);font-size:13px;margin-bottom:12px;">(empty)</p>
|
|
{% endif %}
|
|
{% endfor %}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
{% endif %}
|
|
|
|
{% if landclaims %}
|
|
<div class="detail-section">
|
|
<h2>Land Claims ({{ landclaims|length }})</h2>
|
|
<div class="card">
|
|
<div class="table-wrap">
|
|
<table>
|
|
<thead><tr><th>ID</th><th>Class</th><th>Map</th><th>Position</th></tr></thead>
|
|
<tbody>
|
|
{% for lc in landclaims %}
|
|
<tr>
|
|
<td>{{ lc.id }}</td>
|
|
<td style="font-size:12px;">{{ lc.class | class_name }}</td>
|
|
<td>{{ lc.map or 'N/A' }}</td>
|
|
<td style="font-size:11px;font-family:monospace;">{{ lc.transform_text or '' }}</td>
|
|
</tr>
|
|
{% endfor %}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
{% endif %}
|
|
|
|
<!-- Faction Edit Modal -->
|
|
<div id="faction-modal" class="modal-overlay" style="display:none;" onclick="if(event.target===this)closeModal('faction-modal')">
|
|
<div class="modal">
|
|
<h3>Edit Faction</h3>
|
|
<form id="faction-form" onsubmit="return submitEdit(this, '/api/edit_faction')">
|
|
<input type="hidden" name="player_controller_id" value="{{ player.player_controller_id or '' }}">
|
|
<label>Faction:
|
|
<select name="faction_id">
|
|
<option value="1" {% if player.faction_id == 1 %}selected{% endif %}>Atreides</option>
|
|
<option value="2" {% if player.faction_id == 2 %}selected{% endif %}>Harkonnen</option>
|
|
<option value="3" {% if player.faction_id == 3 %}selected{% endif %}>None</option>
|
|
<option value="4" {% if player.faction_id == 4 %}selected{% endif %}>Smuggler</option>
|
|
</select>
|
|
</label>
|
|
<div class="modal-actions">
|
|
<button type="submit" class="btn-save">Save</button>
|
|
<button type="button" onclick="closeModal('faction-modal')" class="btn-cancel">Cancel</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Vitals Edit Modal -->
|
|
<div id="vitals-modal" class="modal-overlay" style="display:none;" onclick="if(event.target===this)closeModal('vitals-modal')">
|
|
<div class="modal" style="max-width:500px;">
|
|
<h3>Edit Vitals</h3>
|
|
<p style="font-size:12px;color:var(--text-muted);margin-bottom:12px;">Health editing is currently <strong>WIP</strong>. Hydration/Spice are clamped at 0.</p>
|
|
<form id="vitals-form" onsubmit="return submitVitalsEdit()">
|
|
<input type="hidden" name="pawn_id" value="{{ player.state_pawn_id or player.id }}">
|
|
<label>Current Health:
|
|
<input type="number" name="current_health" step="1" min="0" max="{{ vitals.max_health | int if vitals.max_health else 150 }}" value="{{ "%.0f"|format(vitals.current_health or 0) }}" style="width:100px;">
|
|
</label>
|
|
<label>Max Health (WIP):
|
|
<input type="number" name="max_health" step="1" min="0" max="9999" value="{{ "%.0f"|format(vitals.max_health or 150) }}" style="width:100px;">
|
|
</label>
|
|
<label>Hydration:
|
|
<input type="number" name="current_hydration" step="0.1" min="0" value="{{ "%.1f"|format(vitals.current_hydration | float if vitals.current_hydration else 0) }}" style="width:100px;">
|
|
</label>
|
|
<label>Spice:
|
|
<input type="number" name="current_spice" step="1" min="0" value="{{ "%.0f"|format(vitals.current_spice | float if vitals.current_spice else 0) }}" style="width:100px;">
|
|
</label>
|
|
<div class="modal-actions">
|
|
<button type="submit" class="btn-save">Save</button>
|
|
<button type="button" onclick="closeModal('vitals-modal')" class="btn-cancel">Cancel</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Currencies Edit Modal -->
|
|
<div id="currencies-modal" class="modal-overlay" style="display:none;" onclick="if(event.target===this)closeModal('currencies-modal')">
|
|
<div class="modal" style="max-width:500px;">
|
|
<h3>Edit Currencies</h3>
|
|
<p style="font-size:12px;color:var(--text-muted);margin-bottom:12px;">Current balances. Enter a positive number to add, negative to subtract.</p>
|
|
<div id="currency-forms"></div>
|
|
<div class="modal-actions" style="margin-top:12px;">
|
|
<button type="button" onclick="closeModal('currencies-modal')" class="btn-cancel">Close</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Specialization/XP Edit Modal -->
|
|
<div id="spec-modal" class="modal-overlay" style="display:none;" onclick="if(event.target===this)closeModal('spec-modal')">
|
|
<div class="modal" style="max-width:500px;">
|
|
<h3>Edit Specialization & XP</h3>
|
|
<form id="spec-form" onsubmit="return submitSpecEdit()">
|
|
<input type="hidden" name="player_id" value="{{ player.player_controller_id or '' }}">
|
|
<label>Tech Knowledge Points (XP):
|
|
<input type="number" name="xp_points" value="{{ tech_knowledge if tech_knowledge is not none else 0 }}" style="width:150px;">
|
|
</label>
|
|
<button type="submit" class="btn-save" style="margin-top:8px;">Save XP</button>
|
|
</form>
|
|
{% for s in specialization %}
|
|
<hr style="margin:12px 0;border-color:var(--border);">
|
|
<form onsubmit="return submitEdit(this, '/api/edit_xp')">
|
|
<input type="hidden" name="player_id" value="{{ player.player_controller_id or '' }}">
|
|
<input type="hidden" name="track_type" value="{{ s.track_type }}">
|
|
<label>{{ s.track_type }} — XP: <input type="number" name="xp_amount" value="{{ s.xp_amount }}" style="width:100px;">
|
|
Level: <input type="number" step="0.1" name="level" value="{{ s.level }}" style="width:80px;">
|
|
</label>
|
|
<button type="submit" class="btn-save" style="font-size:11px;padding:2px 8px;">Save</button>
|
|
</form>
|
|
{% endfor %}
|
|
<div class="modal-actions" style="margin-top:12px;">
|
|
<button type="button" onclick="closeModal('spec-modal')" class="btn-cancel">Close</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Add Item Modal -->
|
|
<div id="add-item-modal" class="modal-overlay" style="display:none;" onclick="if(event.target===this)closeModal('add-item-modal')">
|
|
<div class="modal">
|
|
<h3>Add Item to Inventory</h3>
|
|
<form id="add-item-form" onsubmit="return submitAddItem()">
|
|
<input type="hidden" id="add-item-inv-id" name="inventory_id" value="">
|
|
<label>Template ID: <input type="text" name="template_id" placeholder="e.g. HealthPackRecipe" style="width:250px;"></label>
|
|
<label>Stack Size: <input type="number" name="stack_size" value="1" style="width:80px;"></label>
|
|
<label>Quality Level: <input type="number" name="quality_level" value="0" style="width:80px;"></label>
|
|
<div class="modal-actions">
|
|
<button type="submit" class="btn-save">Add</button>
|
|
<button type="button" onclick="closeModal('add-item-modal')" class="btn-cancel">Cancel</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
|
|
{% endif %}
|
|
{% endblock %}
|
|
|
|
{% block scripts %}
|
|
<script>
|
|
function openModal(id) {
|
|
document.getElementById(id).style.display = 'flex';
|
|
}
|
|
function closeModal(id) {
|
|
document.getElementById(id).style.display = 'none';
|
|
}
|
|
|
|
async function submitEdit(form, url) {
|
|
const data = new FormData(form);
|
|
try {
|
|
const resp = await fetch(url, { method: 'POST', body: data });
|
|
const result = await resp.json();
|
|
if (result.success) {
|
|
alert('Saved successfully!');
|
|
location.reload();
|
|
} else {
|
|
alert('Error: ' + (result.error || 'Unknown error'));
|
|
}
|
|
} catch (e) {
|
|
alert('Error: ' + e.message);
|
|
}
|
|
return false;
|
|
}
|
|
|
|
async function submitSpecEdit() {
|
|
const form = document.getElementById('spec-form');
|
|
const data = new FormData(form);
|
|
try {
|
|
const resp = await fetch('/api/edit_tech_knowledge', { method: 'POST', body: data });
|
|
const result = await resp.json();
|
|
if (result.success) {
|
|
alert('XP saved!');
|
|
location.reload();
|
|
} else {
|
|
alert('Error: ' + (result.error || 'Unknown error'));
|
|
}
|
|
} catch (e) {
|
|
alert('Error: ' + e.message);
|
|
}
|
|
return false;
|
|
}
|
|
|
|
function openCurrenciesModal() {
|
|
const container = document.getElementById('currency-forms');
|
|
container.innerHTML = '';
|
|
{% for c in currency %}
|
|
{
|
|
const div = document.createElement('div');
|
|
div.style.marginBottom = '12px';
|
|
div.innerHTML = '<label style="display:flex;align-items:center;gap:8px;">{{ c.currency_id | currency_label | safe }}: <span style="font-weight:600;min-width:80px;">{{ c.balance | format_number | safe }}</span> <input type="number" name="delta_{{ c.currency_id }}" placeholder="+/-" style="width:120px;"> <button type="button" class="btn-save" style="font-size:11px;padding:2px 8px;" onclick="submitCurrencyEdit({{ c.currency_id }})">Apply</button></label>';
|
|
container.appendChild(div);
|
|
}
|
|
{% endfor %}
|
|
openModal('currencies-modal');
|
|
}
|
|
|
|
async function submitCurrencyEdit(currencyId) {
|
|
const input = document.querySelector(`input[name="delta_${currencyId}"]`);
|
|
const delta = parseInt(input ? input.value : 0);
|
|
if (isNaN(delta) || delta === 0) {
|
|
alert('Enter a non-zero amount to add or subtract.');
|
|
return;
|
|
}
|
|
const data = new FormData();
|
|
data.append('player_controller_id', '{{ player.player_controller_id }}');
|
|
data.append('currency_id', currencyId);
|
|
data.append('delta', delta);
|
|
try {
|
|
const resp = await fetch('/api/edit_currency', { method: 'POST', body: data });
|
|
const result = await resp.json();
|
|
if (result.success) {
|
|
alert('Currency updated: ' + result.old_balance + ' → ' + result.new_balance + ' (delta: ' + (delta > 0 ? '+' : '') + delta + ')');
|
|
location.reload();
|
|
} else {
|
|
alert('Error: ' + (result.error || 'Unknown error'));
|
|
}
|
|
} catch (e) {
|
|
alert('Error: ' + e.message);
|
|
}
|
|
}
|
|
|
|
async function submitVitalsEdit() {
|
|
const form = document.getElementById('vitals-form');
|
|
const data = new FormData(form);
|
|
try {
|
|
const resp = await fetch('/api/edit_vitals', { method: 'POST', body: data });
|
|
const result = await resp.json();
|
|
if (result.success) {
|
|
alert('Vitals updated successfully!');
|
|
location.reload();
|
|
} else {
|
|
alert('Error: ' + (result.error || 'Unknown error'));
|
|
}
|
|
} catch (e) {
|
|
alert('Error: ' + e.message);
|
|
}
|
|
return false;
|
|
}
|
|
|
|
async function editItem(itemId, field, currentValue) {
|
|
const newValue = prompt(`Edit ${field} for item ${itemId}:`, currentValue);
|
|
if (newValue === null || newValue === currentValue) return;
|
|
const data = new FormData();
|
|
data.append('item_id', itemId);
|
|
data.append('field', field);
|
|
data.append('value', newValue);
|
|
try {
|
|
const resp = await fetch('/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();
|
|
} else {
|
|
alert('Error: ' + (result.error || 'Unknown error'));
|
|
}
|
|
} catch (e) {
|
|
alert('Error: ' + e.message);
|
|
}
|
|
}
|
|
|
|
async function deleteItem(itemId, templateName) {
|
|
if (!confirm(`Delete item "${templateName}" (ID: ${itemId})? This cannot be undone.`)) return;
|
|
const data = new FormData();
|
|
data.append('item_id', itemId);
|
|
try {
|
|
const resp = await fetch('/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();
|
|
} else {
|
|
alert('Error: ' + (result.error || 'Unknown error'));
|
|
}
|
|
} catch (e) {
|
|
alert('Error: ' + e.message);
|
|
}
|
|
}
|
|
|
|
function openAddItemModal(invId) {
|
|
document.getElementById('add-item-inv-id').value = invId;
|
|
openModal('add-item-modal');
|
|
}
|
|
|
|
async function submitAddItem() {
|
|
const form = document.getElementById('add-item-form');
|
|
const data = new FormData(form);
|
|
try {
|
|
const resp = await fetch('/api/add_item', { method: 'POST', body: data });
|
|
const result = await resp.json();
|
|
if (result.success) {
|
|
alert('Item added! ID: ' + result.item_id);
|
|
location.reload();
|
|
} else {
|
|
alert('Error: ' + (result.error || 'Unknown error'));
|
|
}
|
|
} catch (e) {
|
|
alert('Error: ' + e.message);
|
|
}
|
|
return false;
|
|
}
|
|
</script>
|
|
{% endblock %} |