Autosave: 20260307-082818
This commit is contained in:
parent
4e7d2f9aa7
commit
b345880797
199
admin.php
199
admin.php
@ -646,6 +646,13 @@ if ($_SERVER["REQUEST_METHOD"] === "POST" && isset($_POST["action"]) && $_POST["
|
||||
$bonus_destruction = (int)$_POST["bonus_destruction"];
|
||||
$bonus_capture = (int)$_POST["bonus_capture"];
|
||||
$grid_data = $_POST["grid_data"];
|
||||
|
||||
$cost_resource_id = !empty($_POST["cost_resource_id"]) ? (int)$_POST["cost_resource_id"] : null;
|
||||
$cost_amount = (int)$_POST["cost_amount"];
|
||||
$destruction_resource_id = !empty($_POST["destruction_resource_id"]) ? (int)$_POST["destruction_resource_id"] : null;
|
||||
$destruction_amount = (int)$_POST["destruction_amount"];
|
||||
$capture_resource_id = !empty($_POST["capture_resource_id"]) ? (int)$_POST["capture_resource_id"] : null;
|
||||
$capture_amount = (int)$_POST["capture_amount"];
|
||||
|
||||
$image_url = null;
|
||||
if ($id > 0) {
|
||||
@ -665,11 +672,11 @@ if ($_SERVER["REQUEST_METHOD"] === "POST" && isset($_POST["action"]) && $_POST["
|
||||
}
|
||||
|
||||
if ($id > 0) {
|
||||
$stmt = $db->prepare("UPDATE units SET name = ?, slug = ?, faction_id = ?, can_be_destroyed = ?, can_be_captured = ?, points_per_hit = ?, bonus_destruction = ?, bonus_capture = ?, grid_data = ?, image_url = ? WHERE id = ?");
|
||||
$stmt->execute([$name, $slug, $faction_id, $can_be_destroyed, $can_be_captured, $points_per_hit, $bonus_destruction, $bonus_capture, $grid_data, $image_url, $id]);
|
||||
$stmt = $db->prepare("UPDATE units SET name = ?, slug = ?, faction_id = ?, can_be_destroyed = ?, can_be_captured = ?, points_per_hit = ?, bonus_destruction = ?, bonus_capture = ?, grid_data = ?, image_url = ?, cost_resource_id = ?, cost_amount = ?, destruction_resource_id = ?, destruction_amount = ?, capture_resource_id = ?, capture_amount = ? WHERE id = ?");
|
||||
$stmt->execute([$name, $slug, $faction_id, $can_be_destroyed, $can_be_captured, $points_per_hit, $bonus_destruction, $bonus_capture, $grid_data, $image_url, $cost_resource_id, $cost_amount, $destruction_resource_id, $destruction_amount, $capture_resource_id, $capture_amount, $id]);
|
||||
} else {
|
||||
$stmt = $db->prepare("INSERT INTO units (name, slug, faction_id, can_be_destroyed, can_be_captured, points_per_hit, bonus_destruction, bonus_capture, grid_data, image_url) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
|
||||
$stmt->execute([$name, $slug, $faction_id, $can_be_destroyed, $can_be_captured, $points_per_hit, $bonus_destruction, $bonus_capture, $grid_data, $image_url]);
|
||||
$stmt = $db->prepare("INSERT INTO units (name, slug, faction_id, can_be_destroyed, can_be_captured, points_per_hit, bonus_destruction, bonus_capture, grid_data, image_url, cost_resource_id, cost_amount, destruction_resource_id, destruction_amount, capture_resource_id, capture_amount) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
|
||||
$stmt->execute([$name, $slug, $faction_id, $can_be_destroyed, $can_be_captured, $points_per_hit, $bonus_destruction, $bonus_capture, $grid_data, $image_url, $cost_resource_id, $cost_amount, $destruction_resource_id, $destruction_amount, $capture_resource_id, $capture_amount]);
|
||||
$id = $db->lastInsertId();
|
||||
}
|
||||
|
||||
@ -797,6 +804,54 @@ elseif ($tab === "units") {
|
||||
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
|
||||
<link href="assets/css/custom.css?v=<?php echo time(); ?>" rel="stylesheet">
|
||||
<style>
|
||||
/* The switch - the box around the slider */
|
||||
.switch {
|
||||
position: relative;
|
||||
display: inline-block;
|
||||
width: 50px;
|
||||
height: 24px;
|
||||
}
|
||||
.switch input {
|
||||
opacity: 0;
|
||||
width: 0;
|
||||
height: 0;
|
||||
}
|
||||
.slider {
|
||||
position: absolute;
|
||||
cursor: pointer;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background-color: #4c566a;
|
||||
-webkit-transition: .4s;
|
||||
transition: .4s;
|
||||
border-radius: 24px;
|
||||
}
|
||||
.slider:before {
|
||||
position: absolute;
|
||||
content: "";
|
||||
height: 16px;
|
||||
width: 16px;
|
||||
left: 4px;
|
||||
bottom: 4px;
|
||||
background-color: white;
|
||||
-webkit-transition: .4s;
|
||||
transition: .4s;
|
||||
border-radius: 50%;
|
||||
}
|
||||
input:checked + .slider {
|
||||
background-color: #88c0d0;
|
||||
}
|
||||
input:focus + .slider {
|
||||
box-shadow: 0 0 1px #88c0d0;
|
||||
}
|
||||
input:checked + .slider:before {
|
||||
-webkit-transform: translateX(26px);
|
||||
-ms-transform: translateX(26px);
|
||||
transform: translateX(26px);
|
||||
}
|
||||
|
||||
body { background: #000; color: #fff; font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; margin: 0; }
|
||||
header { background: #1a202c; padding: 10px 20px; border-bottom: 2px solid #2d3545; display: flex; justify-content: space-between; align-items: center; }
|
||||
.nav-links a { color: #88c0d0; text-decoration: none; margin-right: 20px; font-weight: bold; font-size: 14px; }
|
||||
@ -956,52 +1011,91 @@ elseif ($tab === "units") {
|
||||
<input type="hidden" name="action" value="upsert_unit">
|
||||
<input type="hidden" name="id" id="unit_id" value="0">
|
||||
<div style="display: flex; gap: 20px; flex-wrap: wrap;">
|
||||
<div class="form-group" style="flex: 1; min-width: 250px;">
|
||||
<div class="form-group" style="flex: 1; min-width: 200px;">
|
||||
<label>Nom de l'unité</label>
|
||||
<input type="text" name="name" id="unit_name" required placeholder="Chasseur Stellaire" onkeyup="syncSlug(this.value, 'unit_slug')">
|
||||
</div>
|
||||
<div class="form-group" style="flex: 1; min-width: 200px;">
|
||||
<div class="form-group" style="flex: 1; min-width: 150px;">
|
||||
<label>Slug (unique)</label>
|
||||
<input type="text" name="slug" id="unit_slug" required placeholder="chasseur_stellaire">
|
||||
</div>
|
||||
<div class="form-group" style="flex: 1; min-width: 200px;">
|
||||
<div class="form-group" style="flex: 1; min-width: 150px;">
|
||||
<label>Faction</label>
|
||||
<select name="faction_id" id="unit_faction_id">
|
||||
|
||||
<?php foreach ($factions_list as $f): ?>
|
||||
<option value="<?php echo $f['id']; ?>"><?php echo htmlspecialchars($f['name']); ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div style="display: flex; gap: 20px; flex-wrap: wrap; align-items: flex-end;">
|
||||
<div class="form-group" style="flex: 1; min-width: 250px;">
|
||||
<div class="form-group" style="flex: 1; min-width: 200px;">
|
||||
<label>Image de l'unité</label>
|
||||
<input type="file" name="image" accept="image/*">
|
||||
</div>
|
||||
<div class="form-group" style="flex: 1; min-width: 200px;">
|
||||
<label>Points par coup (dégâts)</label>
|
||||
<input type="number" name="points_per_hit" id="unit_points_per_hit" value="1" min="0">
|
||||
</div>
|
||||
|
||||
<div style="display: flex; gap: 20px; flex-wrap: wrap; align-items: flex-end;">
|
||||
<div class="form-group" style="flex: 2; min-width: 250px;">
|
||||
<label>Ressources par coût direct</label>
|
||||
<select name="cost_resource_id" id="unit_cost_resource_id">
|
||||
<option value="">-- Sélectionner une ressource --</option>
|
||||
<?php foreach ($resources_list as $res): ?>
|
||||
<option value="<?php echo $res['id']; ?>"><?php echo htmlspecialchars($res['name']); ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group" style="display: flex; gap: 20px; flex: 1; min-width: 200px; padding-bottom: 10px;">
|
||||
<label style="display: flex; align-items: center; gap: 5px; cursor: pointer;">
|
||||
<input type="checkbox" name="can_be_destroyed" id="unit_can_be_destroyed" value="1"> Destructible
|
||||
</label>
|
||||
<label style="display: flex; align-items: center; gap: 5px; cursor: pointer;">
|
||||
<input type="checkbox" name="can_be_captured" id="unit_can_be_captured" value="1"> Capturable
|
||||
</label>
|
||||
<div class="form-group" style="flex: 1; min-width: 200px;">
|
||||
<label>Nombre de ressources à distribuer</label>
|
||||
<input type="number" name="cost_amount" id="unit_cost_amount" value="1" min="1">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div style="display: flex; gap: 20px; flex-wrap: wrap;">
|
||||
<div class="form-group" style="flex: 1;">
|
||||
<label>Bonus Destruction (Points)</label>
|
||||
<input type="number" name="bonus_destruction" id="unit_bonus_destruction" value="0" min="0">
|
||||
<div style="display: flex; gap: 20px; flex-wrap: wrap; align-items: flex-end;">
|
||||
<div class="form-group" style="flex: 0 0 150px;">
|
||||
<label>Destructible</label>
|
||||
<div style="padding: 10px 0;">
|
||||
<label class="switch">
|
||||
<input type="checkbox" name="can_be_destroyed" id="unit_can_be_destroyed" value="1" checked onchange="toggleUnitField('destroyed')">
|
||||
<span class="slider round"></span>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group" style="flex: 1;">
|
||||
<label>Bonus Capture (Points)</label>
|
||||
<input type="number" name="bonus_capture" id="unit_bonus_capture" value="0" min="0">
|
||||
<div class="form-group" style="flex: 2; min-width: 250px;" id="group_destruction_res">
|
||||
<label>Ressource attribuée (Destruction)</label>
|
||||
<select name="destruction_resource_id" id="unit_destruction_resource_id">
|
||||
<option value="">-- Sélectionner une ressource --</option>
|
||||
<?php foreach ($resources_list as $res): ?>
|
||||
<option value="<?php echo $res['id']; ?>"><?php echo htmlspecialchars($res['name']); ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group" style="flex: 1; min-width: 200px;" id="group_destruction_amt">
|
||||
<label>Quantité (Destruction)</label>
|
||||
<input type="number" name="destruction_amount" id="unit_destruction_amount" value="0" min="0">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div style="display: flex; gap: 20px; flex-wrap: wrap; align-items: flex-end;">
|
||||
<div class="form-group" style="flex: 0 0 150px;">
|
||||
<label>Capturable</label>
|
||||
<div style="padding: 10px 0;">
|
||||
<label class="switch">
|
||||
<input type="checkbox" name="can_be_captured" id="unit_can_be_captured" value="1" onchange="toggleUnitField('captured')">
|
||||
<span class="slider round"></span>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group" style="flex: 2; min-width: 250px; display: none;" id="group_capture_res">
|
||||
<label>Ressource attribuée (Capture)</label>
|
||||
<select name="capture_resource_id" id="unit_capture_resource_id">
|
||||
<option value="">-- Sélectionner une ressource --</option>
|
||||
<?php foreach ($resources_list as $res): ?>
|
||||
<option value="<?php echo $res['id']; ?>"><?php echo htmlspecialchars($res['name']); ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group" style="flex: 1; min-width: 200px; display: none;" id="group_capture_amt">
|
||||
<label>Quantité (Capture)</label>
|
||||
<input type="number" name="capture_amount" id="unit_capture_amount" value="0" min="0">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -1070,13 +1164,30 @@ elseif ($tab === "units") {
|
||||
</span>
|
||||
</td>
|
||||
<td style="font-size: 11px;">
|
||||
Pts/Coup: <?php echo $unit['points_per_hit']; ?><br>
|
||||
<?php
|
||||
$costResName = 'Points';
|
||||
foreach($resources_list as $res) { if($res['id'] == $unit['cost_resource_id']) { $costResName = $res['name']; break; } }
|
||||
?>
|
||||
Coût: <?php echo $unit['cost_amount']; ?> <?php echo htmlspecialchars($costResName); ?><br>
|
||||
<?php if ($unit['can_be_destroyed']): ?><span style="color: #bf616a;">● Destructible</span><br><?php endif; ?>
|
||||
<?php if ($unit['can_be_captured']): ?><span style="color: #a3be8c;">● Capturable</span><?php endif; ?>
|
||||
</td>
|
||||
<td style="font-size: 10px;">
|
||||
<?php if ($unit['bonus_destruction'] > 0): ?>Destr: +<?php echo $unit['bonus_destruction']; ?> pts<br><?php endif; ?>
|
||||
<?php if ($unit['bonus_capture'] > 0): ?>Capt: +<?php echo $unit['bonus_capture']; ?> pts<br><?php endif; ?>
|
||||
<?php if ($unit['destruction_resource_id']): ?>
|
||||
<?php
|
||||
$dResName = '?';
|
||||
foreach($resources_list as $res) { if($res['id'] == $unit['destruction_resource_id']) { $dResName = $res['name']; break; } }
|
||||
?>
|
||||
Destr: +<?php echo $unit['destruction_amount']; ?> <?php echo htmlspecialchars($dResName); ?><br>
|
||||
<?php endif; ?>
|
||||
<?php if ($unit['capture_resource_id']): ?>
|
||||
<?php
|
||||
$cResName = '?';
|
||||
foreach($resources_list as $res) { if($res['id'] == $unit['capture_resource_id']) { $cResName = $res['name']; break; } }
|
||||
?>
|
||||
Capt: +<?php echo $unit['capture_amount']; ?> <?php echo htmlspecialchars($cResName); ?><br>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php foreach ($unit['rewards'] as $rw): ?>
|
||||
<?php
|
||||
$rName = '?';
|
||||
@ -2226,20 +2337,36 @@ elseif ($tab === "units") {
|
||||
|
||||
function checkUnitFormValidity(){const n=document.getElementById('unit_name')?.value,s=document.getElementById('unit_slug')?.value,g=document.getElementById('unit_grid_data')?.value,b=document.getElementById('unit_submit_btn');if(b){const v=n&&s&&g&&g!=='[]'&&g!=='';b.disabled=!v;b.style.opacity=v?'1':'0.5';}}
|
||||
|
||||
function toggleUnitField(type) {
|
||||
const isChecked = document.getElementById('unit_can_be_' + type).checked;
|
||||
const resGroup = document.getElementById('group_' + type + '_res");
|
||||
const amtGroup = document.getElementById('group_' + type + '_amt");
|
||||
if (resGroup && amtGroup) {
|
||||
resGroup.style.display = isChecked ? 'block' : 'none';
|
||||
amtGroup.style.display = isChecked ? 'block' : 'none';
|
||||
}
|
||||
}
|
||||
|
||||
function editUnit(data) {
|
||||
resetUnitForm();
|
||||
document.getElementById('unit_id').value = data.id;
|
||||
document.getElementById('unit_name').value = data.name;
|
||||
document.getElementById('unit_slug').value = data.slug;
|
||||
document.getElementById('unit_faction_id').value = data.faction_id;
|
||||
document.getElementById('unit_points_per_hit').value = data.points_per_hit;
|
||||
document.getElementById('unit_cost_resource_id').value = data.cost_resource_id || "";
|
||||
document.getElementById('unit_cost_amount').value = data.cost_amount || 1;
|
||||
document.getElementById('unit_can_be_destroyed').checked = data.can_be_destroyed == 1;
|
||||
document.getElementById('unit_can_be_captured').checked = data.can_be_captured == 1;
|
||||
document.getElementById('unit_bonus_destruction').value = data.bonus_destruction;
|
||||
document.getElementById('unit_bonus_capture').value = data.bonus_capture;
|
||||
document.getElementById('unit_destruction_resource_id').value = data.destruction_resource_id || "";
|
||||
document.getElementById('unit_destruction_amount').value = data.destruction_amount || 0;
|
||||
document.getElementById('unit_capture_resource_id').value = data.capture_resource_id || "";
|
||||
document.getElementById('unit_capture_amount').value = data.capture_amount || 0;
|
||||
document.getElementById('unit_grid_data').value = data.grid_data;
|
||||
setUnitGridFromData(data.grid_data);
|
||||
|
||||
toggleUnitField('destroyed');
|
||||
toggleUnitField('captured');
|
||||
|
||||
if (data.rewards) {
|
||||
data.rewards.forEach(r => {
|
||||
addUnitRewardRow(r.action_type, r.resource_id, r.amount);
|
||||
@ -2253,6 +2380,8 @@ elseif ($tab === "units") {
|
||||
document.getElementById('unitForm').reset();
|
||||
document.getElementById('unit_id').value = 0;
|
||||
document.getElementById('unit_grid_data').value = "";
|
||||
toggleUnitField('destroyed');
|
||||
toggleUnitField('captured');
|
||||
document.getElementById('unitRewardsContainer').innerHTML = `
|
||||
<div class="sub-form-header">
|
||||
<div style="flex: 1;">Action</div>
|
||||
|
||||
21
db/add_resource_columns_to_units.php
Normal file
21
db/add_resource_columns_to_units.php
Normal file
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/config.php';
|
||||
|
||||
try {
|
||||
$db = db();
|
||||
|
||||
// Add new columns to units table
|
||||
$db->exec("ALTER TABLE units ADD COLUMN IF NOT EXISTS cost_resource_id INT NULL AFTER faction_id");
|
||||
$db->exec("ALTER TABLE units ADD COLUMN IF NOT EXISTS cost_amount INT DEFAULT 1 AFTER cost_resource_id");
|
||||
|
||||
$db->exec("ALTER TABLE units ADD COLUMN IF NOT EXISTS destruction_resource_id INT NULL AFTER bonus_destruction");
|
||||
$db->exec("ALTER TABLE units ADD COLUMN IF NOT EXISTS destruction_amount INT DEFAULT 0 AFTER destruction_resource_id");
|
||||
|
||||
$db->exec("ALTER TABLE units ADD COLUMN IF NOT EXISTS capture_resource_id INT NULL AFTER bonus_capture");
|
||||
$db->exec("ALTER TABLE units ADD COLUMN IF NOT EXISTS capture_amount INT DEFAULT 0 AFTER capture_resource_id");
|
||||
|
||||
echo "Migration successful: new resource columns added to 'units' table.\n";
|
||||
} catch (PDOException $e) {
|
||||
echo "Migration failed: " . $e->getMessage() . "\n";
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user