Alpha v0.6

This commit is contained in:
Flatlogic Bot 2026-02-23 00:18:45 +00:00
parent e33f37b2a1
commit 4698c65f42
6 changed files with 691 additions and 96 deletions

View File

@ -171,6 +171,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['
$name = $_POST['name'];
$slug = $_POST['slug'];
$fa_icon = $_POST['fa_icon'];
$color = $_POST['color'];
$image_url = null;
if ($id > 0) {
$stmt_img = $db->prepare("SELECT image_url FROM factions WHERE id = ?");
@ -186,11 +187,11 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['
}
}
if ($id > 0) {
$stmt = $db->prepare("UPDATE factions SET name = ?, slug = ?, image_url = ?, fa_icon = ? WHERE id = ?");
$stmt->execute([$name, $slug, $image_url, $fa_icon, $id]);
$stmt = $db->prepare("UPDATE factions SET name = ?, slug = ?, image_url = ?, fa_icon = ?, color = ? WHERE id = ?");
$stmt->execute([$name, $slug, $image_url, $fa_icon, $color, $id]);
} else {
$stmt = $db->prepare("INSERT INTO factions (name, slug, image_url, fa_icon) VALUES (?, ?, ?, ?)");
$stmt->execute([$name, $slug, $image_url, $fa_icon]);
$stmt = $db->prepare("INSERT INTO factions (name, slug, image_url, fa_icon, color) VALUES (?, ?, ?, ?, ?)");
$stmt->execute([$name, $slug, $image_url, $fa_icon, $color]);
}
header("Location: admin.php?tab=factions&success=1");
exit;
@ -410,7 +411,7 @@ if ($tab === 'users') {
<h2 style="margin: 0; color: #bf616a;"><i class="fa-solid fa-shield-halved"></i> CONSOLE ADMIN</h2>
<nav class="nav-links">
<a href="index.php"><i class="fa-solid fa-eye"></i> Vue Joueur</a>
<a href="gm_console.php" target="_blank"><i class="fa-solid fa-headset"></i> Console MJ</a>
<a href="gm_console.php"><i class="fa-solid fa-headset"></i> Console MJ</a>
</nav>
</div>
<div>
@ -713,6 +714,10 @@ if ($tab === 'users') {
<label>Slug</label>
<input type="text" name="slug" id="fac_slug" required placeholder="Ex: federation, empire...">
</div>
<div class="form-group" style="flex: 1;">
<label>Couleur</label>
<input type="color" name="color" id="fac_color" value="#808080">
</div>
<div class="form-group" style="flex: 1;">
<label>Icône (FontAwesome)</label>
<input type="text" name="fa_icon" id="fac_fa_icon" placeholder="Ex: fa-users">
@ -728,17 +733,18 @@ if ($tab === 'users') {
</div>
<table>
<thead><tr><th>Visuel</th><th>Nom</th><th>Slug</th><th>Actions</th></tr></thead>
<thead><tr><th>Couleur</th><th>Visuel</th><th>Nom</th><th>Slug</th><th>Actions</th></tr></thead>
<tbody>
<?php foreach ($factions_list as $f): ?>
<tr>
<td><div style="width: 25px; height: 25px; border-radius: 50%; background: <?php echo htmlspecialchars($f['color'] ?? '#808080'); ?>; border: 1px solid #334155;"></div></td>
<td style="text-align: center;">
<?php if (!empty($f['image_url'])): ?>
<img src="<?php echo htmlspecialchars($f['image_url']); ?>?v=<?php echo time(); ?>" style="max-width: 40px; max-height: 40px;">
<?php elseif (!empty($f['fa_icon'])): ?>
<i class="fa-solid <?php echo htmlspecialchars($f['fa_icon']); ?> fa-lg"></i>
<i class="fa-solid <?php echo htmlspecialchars($f['fa_icon']); ?> fa-lg" style="color: <?php echo htmlspecialchars($f['color'] ?? '#fff'); ?>;"></i>
<?php else: ?>
<i class="fa-solid fa-flag fa-lg" style="color: #4c566a;"></i>
<i class="fa-solid fa-flag fa-lg" style="color: <?php echo htmlspecialchars($f['color'] ?? '#4c566a'); ?>;"></i>
<?php endif; ?>
</td>
<td><strong><?php echo htmlspecialchars($f['name']); ?></strong></td>
@ -992,10 +998,11 @@ if ($tab === 'users') {
document.getElementById('fac_id').value = data.id;
document.getElementById('fac_name').value = data.name;
document.getElementById('fac_slug').value = data.slug || '';
document.getElementById('fac_color').value = data.color || '#808080';
document.getElementById('fac_fa_icon').value = data.fa_icon || '';
window.scrollTo(0,0);
}
function resetFactionForm() { document.getElementById('factionForm').reset(); document.getElementById('fac_id').value = 0; }
function resetFactionForm() { document.getElementById('factionForm').reset(); document.getElementById('fac_id').value = 0; document.getElementById('fac_color').value = '#808080'; }
function editResource(data) {
document.getElementById('res_id').value = data.id;

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.4 KiB

View File

@ -0,0 +1,11 @@
<?php
require_once __DIR__ . '/config.php';
try {
$pdo = db();
$pdo->exec("ALTER TABLE factions ADD COLUMN color VARCHAR(7) DEFAULT '#808080' AFTER fa_icon");
echo "Successfully added 'color' column to 'factions' table.\n";
} catch (PDOException $e) {
echo "Error adding column: " . $e->getMessage() . "\n";
}

View File

@ -0,0 +1,9 @@
-- Create table for orbital faction control
CREATE TABLE IF NOT EXISTS planet_faction_control (
planet_id INT(11) NOT NULL,
faction_id INT(11) NOT NULL,
control_level INT(11) NOT NULL DEFAULT 0,
PRIMARY KEY (planet_id, faction_id),
CONSTRAINT fk_planet_faction_control_planet FOREIGN KEY (planet_id) REFERENCES planets(id) ON DELETE CASCADE,
CONSTRAINT fk_planet_faction_control_faction FOREIGN KEY (faction_id) REFERENCES factions(id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

View File

@ -32,33 +32,96 @@ $factions_map = []; foreach($factions_db as $f) $factions_map[$f['id']] = $f;
// Handle Planet/Slot Update
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'update_slot') {
$slot_id = (int)$_POST['slot_id'];
$galaxy_id = (int)$_POST['galaxy_id'];
$sector_id = (int)$_POST['sector_id'];
$slot_num = (int)$_POST['slot_num'];
$name = $_POST['name'];
$type = $_POST['type'];
$status = $_POST['status'];
$faction_id = (int)$_POST['faction_id'];
$orbital = (int)$_POST['orbital_control'];
$terrestrial = (int)$_POST['terrestrial_control'];
$slot_id = (int)($_POST['slot_id'] ?? 0);
$galaxy_id = (int)($_POST['galaxy_id'] ?? 1);
$sector_id = (int)($_POST['sector_id'] ?? 1);
$slot_num = (int)($_POST['slot_num'] ?? 0);
$name = $_POST['name'] ?? 'Inconnu';
$type = $_POST['type'] ?? 'empty';
// Orbital control is now detailed by faction
$orbital_controls = $_POST['orbital_controls'] ?? [];
$dominant_orbital_val = 0;
$dominant_orbital_faction = null;
foreach($orbital_controls as $fid => $val) {
if ((int)$val > $dominant_orbital_val && (int)$fid != 1) { // Not "Aucune"
$dominant_orbital_val = (int)$val;
$dominant_orbital_faction = (int)$fid;
}
}
// Derive Status and Faction from Settlements
$status = 'sta_empty';
$faction_id = null;
$total_non_aucun = 0;
$active_factions = [];
$num_cities = 0;
$avg_terrestrial_control = 0;
if (isset($_POST['cities']) && is_array($_POST['cities'])) {
foreach ($_POST['cities'] as $city_data) {
if (empty($city_data['name'])) continue;
$num_cities++;
if (isset($city_data['controls']) && is_array($city_data['controls'])) {
foreach ($city_data['controls'] as $f_id => $lvl) {
$lvl = (int)$lvl;
if ($lvl > 0 && $f_id != 1) { // 1 is "Aucune"
$total_non_aucun += $lvl;
$active_factions[$f_id] = ($active_factions[$f_id] ?? 0) + $lvl;
$avg_terrestrial_control += $lvl;
}
}
}
}
}
if ($num_cities > 0) {
$avg_terrestrial_control = round($avg_terrestrial_control / $num_cities);
}
if ($num_cities > 0 && $total_non_aucun > 0) {
arsort($active_factions);
$faction_id = (int)key($active_factions);
if (count($active_factions) > 1) {
$status = 'sta_hostile';
} else {
if ($total_non_aucun >= ($num_cities * 100)) {
$status = 'sta_controlled';
} else {
$status = 'sta_contested';
}
}
} else if ($type !== 'empty') {
$status = 'sta_empty';
$faction_id = null;
}
if ($type === 'empty') {
if ($slot_id > 0) {
$db->prepare("DELETE FROM cities WHERE planet_id = ?")->execute([$slot_id]);
$db->prepare("DELETE FROM planet_faction_control WHERE planet_id = ?")->execute([$slot_id]);
$db->prepare("DELETE FROM planets WHERE id = ?")->execute([$slot_id]);
}
} else {
if ($slot_id > 0) {
$stmt = $db->prepare("UPDATE planets SET name = ?, type = ?, status = ?, faction_id = ?, orbital_control = ?, terrestrial_control = ? WHERE id = ?");
$stmt->execute([$name, $type, $status, $faction_id, $orbital, $terrestrial, $slot_id]);
$stmt->execute([$name, $type, $status, $faction_id, $dominant_orbital_val, $avg_terrestrial_control, $slot_id]);
$planet_id = $slot_id;
} else {
$stmt = $db->prepare("INSERT INTO planets (galaxy_id, sector_id, slot, name, type, status, faction_id, orbital_control, terrestrial_control) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)");
$stmt->execute([$galaxy_id, $sector_id, $slot_num, $name, $type, $status, $faction_id, $orbital, $terrestrial]);
$stmt->execute([$galaxy_id, $sector_id, $slot_num, $name, $type, $status, $faction_id, $dominant_orbital_val, $avg_terrestrial_control]);
$planet_id = $db->lastInsertId();
}
// Handle Orbital Faction Control
$db->prepare("DELETE FROM planet_faction_control WHERE planet_id = ?")->execute([$planet_id]);
foreach($orbital_controls as $fid => $lvl) {
if ((int)$lvl > 0) {
$db->prepare("INSERT INTO planet_faction_control (planet_id, faction_id, control_level) VALUES (?, ?, ?)")->execute([$planet_id, (int)$fid, (int)$lvl]);
}
}
// Handle Multiple Settlements
$sent_city_ids = [];
if (isset($_POST['cities']) && is_array($_POST['cities'])) {
@ -67,20 +130,32 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['
$c_id = (int)($city_data['id'] ?? 0);
$c_name = $city_data['name'];
$c_type_id = (int)$city_data['type_id'];
$c_type_id = !empty($city_data['type_id']) ? (int)$city_data['type_id'] : null;
if ($c_id > 0) {
$stmt = $db->prepare("UPDATE cities SET name = ?, settlement_type_id = ? WHERE id = ? AND planet_id = ?");
$stmt->execute([$c_name, $c_type_id, $c_id, $planet_id]);
$sent_city_ids[] = $c_id;
$city_id = $c_id;
} else {
$stmt = $db->prepare("INSERT INTO cities (planet_id, name, settlement_type_id) VALUES (?, ?, ?)");
$stmt->execute([$c_name, $c_type_id]);
$sent_city_ids[] = $db->lastInsertId();
$stmt->execute([$planet_id, $c_name, $c_type_id]);
$city_id = $db->lastInsertId();
}
$sent_city_ids[] = $city_id;
// Handle Faction Control
$db->prepare("DELETE FROM city_faction_control WHERE city_id = ?")->execute([$city_id]);
if (isset($city_data['controls']) && is_array($city_data['controls'])) {
foreach ($city_data['controls'] as $fac_id => $control_lvl) {
$control_lvl = (int)$control_lvl;
if ($control_lvl > 0) {
$stmt = $db->prepare("INSERT INTO city_faction_control (city_id, faction_id, control_level) VALUES (?, ?, ?)");
$stmt->execute([$city_id, (int)$fac_id, $control_lvl]);
}
}
}
}
}
// Delete cities that were removed in the UI
if ($planet_id > 0) {
if (empty($sent_city_ids)) {
$db->prepare("DELETE FROM cities WHERE planet_id = ?")->execute([$planet_id]);
@ -100,8 +175,8 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'update_sector') {
$sector_id = (int)$_POST['sector_id'];
$galaxy_id = (int)$_POST['galaxy_id'];
$s_name = $_POST['sector_name'];
$s_status = $_POST['sector_status'];
$s_name = $_POST['sector_name'] ?? "Secteur $sector_id";
$s_status = $_POST['sector_status'] ?? 'unexplored';
$stmt = $db->prepare("INSERT INTO sectors (id, galaxy_id, name, status) VALUES (?, ?, ?, ?) ON DUPLICATE KEY UPDATE name = ?, status = ?");
$stmt->execute([$sector_id, $galaxy_id, $s_name, $s_status, $s_name, $s_status]);
@ -126,14 +201,42 @@ if ($view === 'sector') {
$grid[$obj['slot']] = $obj;
$planet_ids[] = $obj['id'];
$grid[$obj['slot']]['cities'] = [];
$grid[$obj['slot']]['orbital_controls'] = [];
}
if (!empty($planet_ids)) {
// Fetch Orbital Controls
$placeholders = implode(',', array_fill(0, count($planet_ids), '?'));
$stmt = $db->prepare("SELECT * FROM planet_faction_control WHERE planet_id IN ($placeholders)");
$stmt->execute($planet_ids);
$orb_controls_raw = $stmt->fetchAll(PDO::FETCH_ASSOC);
foreach ($orb_controls_raw as $ocr) {
foreach ($grid as &$slot_data) {
if ($slot_data && $slot_data['id'] == $ocr['planet_id']) {
$slot_data['orbital_controls'][$ocr['faction_id']] = $ocr['control_level'];
}
}
}
// Fetch Cities
$stmt = $db->prepare("SELECT * FROM cities WHERE planet_id IN ($placeholders)");
$stmt->execute($planet_ids);
$all_cities = $stmt->fetchAll();
$all_cities = $stmt->fetchAll(PDO::FETCH_ASSOC);
$city_ids = array_column($all_cities, 'id');
$city_controls = [];
if (!empty($city_ids)) {
$c_placeholders = implode(',', array_fill(0, count($city_ids), '?'));
$c_stmt = $db->prepare("SELECT * FROM city_faction_control WHERE city_id IN ($c_placeholders)");
$c_stmt->execute($city_ids);
$controls_raw = $c_stmt->fetchAll(PDO::FETCH_ASSOC);
foreach ($controls_raw as $cr) {
$city_controls[$cr['city_id']][$cr['faction_id']] = $cr['control_level'];
}
}
foreach ($all_cities as $city) {
$city['controls'] = $city_controls[$city['id']] ?? [];
foreach ($grid as &$slot_data) {
if ($slot_data && $slot_data['id'] == $city['planet_id']) {
$slot_data['cities'][] = $city;
@ -141,7 +244,7 @@ if ($view === 'sector') {
}
}
}
$stmt = $db->prepare("SELECT name FROM sectors WHERE id = ?");
$stmt = $db->prepare("SELECT name, status FROM sectors WHERE id = ?");
$stmt->execute([$sector_id]);
$sector_info = $stmt->fetch();
} else {
@ -263,19 +366,8 @@ function getStatusColor($status, $type, $statuses_map, $object_types_map) {
text-shadow: 0 0 4px rgba(0,0,0,0.8);
}
.sector-grid {
display: grid;
grid-template-columns: repeat(6, 180px);
grid-template-rows: repeat(6, 180px);
gap: 15px;
}
.sector-card { background: rgba(10, 15, 30, 0.95); border: 1px solid #2d3545; padding: 20px; display: flex; flex-direction: column; align-items: center; justify-content: center; text-decoration: none; color: #fff; transition: all 0.2s; width: 180px; height: 180px; box-sizing: border-box; }
.sector-card:hover { border-color: #88c0d0; background: #1a202c; transform: translateY(-3px); }
.mini-map { display: grid; grid-template-columns: repeat(6, 12px); gap: 4px; margin-bottom: 10px; background: #000; padding: 6px; }
.mini-dot { width: 12px; height: 12px; border-radius: 1px; }
#editModal, #sectorModal { display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.8); z-index: 1000; align-items: center; justify-content: center; }
.modal-content { background: #1e293b; padding: 30px; border: 1px solid #88c0d0; width: 550px; max-height: 90vh; overflow-y: auto; border-radius: 8px; box-shadow: 0 10px 30px rgba(0,0,0,0.5); }
.modal-content { background: #1e293b; padding: 30px; border: 1px solid #88c0d0; width: 650px; max-height: 90vh; overflow-y: auto; border-radius: 8px; box-shadow: 0 10px 30px rgba(0,0,0,0.5); }
.form-group { margin-bottom: 20px; }
.form-group label { display: block; font-size: 12px; color: #8c92a3; margin-bottom: 8px; font-weight: bold; }
.form-group input, .form-group select, .form-group textarea { width: 100%; background: #0f172a; border: 1px solid #334155; color: #fff; padding: 10px; box-sizing: border-box; border-radius: 4px; font-size: 14px; }
@ -287,8 +379,28 @@ function getStatusColor($status, $type, $statuses_map, $object_types_map) {
.btn-remove-settlement { position: absolute; right: 8px; top: 8px; background: #bf616a; color: #fff; border: none; width: 22px; height: 22px; cursor: pointer; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: bold; }
.btn-add-settlement { background: #81a1c1; color: #000; border: none; padding: 8px 15px; cursor: pointer; font-size: 11px; font-weight: bold; border-radius: 4px; width: 100%; margin-bottom: 15px; transition: 0.2s; }
.btn-add-settlement:hover { background: #88c0d0; }
.compact-row { display: flex; gap: 15px; align-items: flex-end; }
.compact-row { display: flex; gap: 15px; align-items: flex-end; margin-bottom: 15px; }
.compact-row .form-group { margin-bottom: 0; }
.control-bars { margin-top: 15px; display: flex; flex-direction: column; gap: 10px; padding-top: 10px; border-top: 1px dashed #334155; }
.control-bar-row { display: flex; align-items: center; gap: 10px; }
.control-bar-label { width: 100px; font-size: 11px; color: #eceff4; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: flex; align-items: center; gap: 5px; }
.control-bar-input { flex: 1; -webkit-appearance: none; height: 8px; background: #0f172a; border-radius: 4px; outline: none; }
.control-bar-input::-webkit-slider-thumb { -webkit-appearance: none; width: 16px; height: 16px; background: #88c0d0; border-radius: 50%; cursor: pointer; }
.control-bar-value { width: 35px; text-align: right; font-size: 11px; color: #88c0d0; font-weight: bold; }
.sector-grid {
display: grid;
grid-template-columns: repeat(6, 180px);
grid-template-rows: repeat(6, 180px);
gap: 15px;
}
.sector-card { background: rgba(10, 15, 30, 0.95); border: 1px solid #2d3545; padding: 20px; display: flex; flex-direction: column; align-items: center; justify-content: center; text-decoration: none; color: #fff; transition: all 0.2s; width: 180px; height: 180px; box-sizing: border-box; }
.sector-card:hover { border-color: #88c0d0; background: #1a202c; transform: translateY(-3px); }
.mini-map { display: grid; grid-template-columns: repeat(6, 12px); gap: 4px; margin-bottom: 10px; background: #000; padding: 6px; }
.mini-dot { width: 12px; height: 12px; border-radius: 1px; }
.faction-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
</style>
</head>
<body>
@ -302,7 +414,7 @@ function getStatusColor($status, $type, $statuses_map, $object_types_map) {
<?php endif; ?>
</nav>
</div>
<div style="font-size: 14px;">Connecté en tant que MJ: <strong style="color: #ebcb8b;">@<?php echo htmlspecialchars($_SESSION['username']); ?></strong></div>
<div style="font-size: 14px;">Connecté en tant que MJ: <strong style="color: #ebcb8b;">@<?php echo htmlspecialchars($_SESSION['username'] ?? 'MJ'); ?></strong></div>
</header>
<div class="container">
@ -347,7 +459,7 @@ function getStatusColor($status, $type, $statuses_map, $object_types_map) {
<?php if (!empty($fac_info['image_url'])): ?>
<img src="<?php echo htmlspecialchars($fac_info['image_url']); ?>?v=<?php echo time(); ?>" style="width: 100%; height: 100%; object-fit: contain;" title="<?php echo htmlspecialchars($fac_info['name']); ?>">
<?php elseif (!empty($fac_info['fa_icon'])): ?>
<i class="fa-solid <?php echo htmlspecialchars($fac_info['fa_icon']); ?>" style="color: #fff; font-size: 16px;" title="<?php echo htmlspecialchars($fac_info['name']); ?>"></i>
<i class="fa-solid <?php echo htmlspecialchars($fac_info['fa_icon']); ?>" style="color: <?php echo htmlspecialchars($fac_info['color'] ?? '#fff'); ?>; font-size: 16px;" title="<?php echo htmlspecialchars($fac_info['name']); ?>"></i>
<?php endif; ?>
</div>
<?php endif; ?>
@ -407,45 +519,23 @@ function getStatusColor($status, $type, $statuses_map, $object_types_map) {
</select>
</div>
</div>
<div style="display: flex; gap: 15px;">
<div class="form-group" style="flex: 1;">
<label>Statut / État</label>
<select name="status" id="form_status">
<?php foreach($statuses_db as $st): ?>
<option value="<?php echo $st['slug']; ?>"><?php echo $st['name']; ?></option>
<?php endforeach; ?>
</select>
</div>
<div class="form-group" style="flex: 1;">
<label>Faction</label>
<select name="faction_id" id="form_faction">
<?php foreach($factions_db as $fac): ?>
<option value="<?php echo $fac['id']; ?>"><?php echo $fac['name']; ?></option>
<?php endforeach; ?>
</select>
<!-- Orbital Faction Control Section -->
<div style="background: rgba(0,0,0,0.1); padding: 15px; border-radius: 6px; border: 1px solid #334155; margin-bottom: 20px;">
<label style="font-size: 11px; color: #88c0d0; font-weight: bold; display: block; margin-bottom: 15px; text-align: center; border-bottom: 1px solid #334155; padding-bottom: 8px;">CONTRÔLE ORBITAL PAR FACTION (%)</label>
<div id="orbitalControlContainer" class="control-bars">
<!-- Orbital sliders injected by JS -->
</div>
</div>
<div style="background: rgba(0,0,0,0.1); padding: 15px; border-radius: 6px; border: 1px solid #334155; margin-bottom: 20px;">
<label style="font-size: 11px; color: #88c0d0; font-weight: bold; display: block; margin-bottom: 15px; text-align: center; border-bottom: 1px solid #334155; padding-bottom: 8px;">ÉTABLISSEMENTS</label>
<label style="font-size: 11px; color: #88c0d0; font-weight: bold; display: block; margin-bottom: 15px; text-align: center; border-bottom: 1px solid #334155; padding-bottom: 8px;">ÉTABLISSEMENTS & PROGRESSIONS</label>
<div id="settlementsContainer">
<!-- Settlements will be injected here -->
</div>
<button type="button" class="btn-add-settlement" onclick="addSettlementRow()"><i class="fa-solid fa-plus"></i> AJOUTER UN ÉTABLISSEMENT</button>
</div>
<div style="display: flex; gap: 15px;">
<div class="form-group" style="flex: 1;">
<label>Contrôle Orbital (%)</label>
<input type="number" name="orbital_control" id="form_orbital" min="0" max="100" value="0">
</div>
<div class="form-group" style="flex: 1;">
<label>Contrôle Sol (%)</label>
<input type="number" name="terrestrial_control" id="form_terrestrial" min="0" max="100" value="0">
</div>
</div>
<button type="submit" class="btn-save">ENREGISTRER</button>
<button type="button" class="btn-cancel" onclick="closeModal()">ANNULER</button>
</form>
@ -485,6 +575,40 @@ function getStatusColor($status, $type, $statuses_map, $object_types_map) {
<script>
let settlementIndex = 0;
const settlementTypes = <?php echo json_encode($settlement_types_db); ?>;
const allFactions = <?php echo json_encode($factions_db); ?>;
const AUCUN_ID = 1; // ID for "Aucune" faction
function initOrbitalSliders(orbitalData = null) {
const container = document.getElementById('orbitalControlContainer');
container.innerHTML = '';
const hasExisting = orbitalData && Object.keys(orbitalData).length > 0;
allFactions.forEach(f => {
let val = 0;
if (hasExisting) {
val = orbitalData[f.id] !== undefined ? parseInt(orbitalData[f.id]) : 0;
} else {
val = (f.id == AUCUN_ID ? 100 : 0);
}
const div = document.createElement('div');
div.className = 'control-bar-row';
div.innerHTML = `
<div class="control-bar-label" title="${f.name}">
<span class="faction-dot" style="background: ${f.color || '#808080'}"></span>
${f.name}
</div>
<input type="range" name="orbital_controls[${f.id}]"
class="control-bar-input orbital-slider"
data-faction-id="${f.id}"
min="0" max="100" value="${val}"
oninput="handleSliderChangeGeneric('orbital-slider', ${f.id}, this.value)">
<div class="control-bar-value" id="val_orbital_${f.id}">${val}%</div>
`;
container.appendChild(div);
});
}
function addSettlementRow(data = null) {
const container = document.getElementById('settlementsContainer');
@ -507,11 +631,103 @@ function getStatusColor($status, $type, $statuses_map, $object_types_map) {
html += `<option value="${t.id}" ${sel}>${t.name}</option>`;
});
html += `</select></div></div>`;
// Progress bars for each faction
html += `<div class="control-bars"><label style="font-size: 10px; color: #8c92a3; font-weight: bold; margin-bottom: 5px;">CONTRÔLE PAR FACTION (%)</label>`;
const initialControls = {};
const hasAnyControls = data && data.controls && Object.keys(data.controls).length > 0;
allFactions.forEach(f => {
if (hasAnyControls) {
initialControls[f.id] = (data.controls[f.id] !== undefined) ? parseInt(data.controls[f.id]) : 0;
} else {
initialControls[f.id] = (f.id == AUCUN_ID ? 100 : 0);
}
});
allFactions.forEach(f => {
const controlVal = initialControls[f.id];
html += `
<div class="control-bar-row">
<div class="control-bar-label" title="${f.name}">
<span class="faction-dot" style="background: ${f.color || '#808080'}"></span>
${f.name}
</div>
<input type="range" name="cities[${index}][controls][${f.id}]"
class="control-bar-input city-slider-${index}"
data-faction-id="${f.id}"
min="0" max="100" value="${controlVal}"
oninput="handleSliderChangeGeneric('city-slider-${index}', ${f.id}, this.value, ${index})">
<div class="control-bar-value" id="val_${index}_${f.id}">${controlVal}%</div>
</div>`;
});
html += `</div>`;
div.innerHTML = html;
container.appendChild(div);
}
function handleSliderChangeGeneric(className, changedFid, newVal, rowIdx = null) {
newVal = parseInt(newVal);
const sliders = Array.from(document.querySelectorAll(`.${className}`));
let otherSum = 0;
sliders.forEach(s => {
if (parseInt(s.dataset.factionId) !== changedFid) {
otherSum += parseInt(s.value);
}
});
let targetOtherSum = 100 - newVal;
if (otherSum === 0 && targetOtherSum > 0) {
const aucun = sliders.find(s => parseInt(s.dataset.factionId) === AUCUN_ID);
if (aucun && changedFid !== AUCUN_ID) {
aucun.value = targetOtherSum;
} else {
const other = sliders.find(s => parseInt(s.dataset.factionId) !== AUCUN_ID);
if (other) other.value = targetOtherSum;
}
} else {
let diff = targetOtherSum - otherSum;
if (diff < 0) {
const aucun = sliders.find(s => parseInt(s.dataset.factionId) === AUCUN_ID);
if (aucun && parseInt(aucun.dataset.factionId) !== changedFid && parseInt(aucun.value) > 0) {
let take = Math.min(parseInt(aucun.value), Math.abs(diff));
aucun.value = parseInt(aucun.value) - take;
diff += take;
}
if (diff < 0) {
sliders.forEach(s => {
if (diff === 0 || parseInt(s.dataset.factionId) === changedFid || parseInt(s.dataset.factionId) === AUCUN_ID) return;
let val = parseInt(s.value);
let take = Math.min(val, Math.abs(diff));
s.value = val - take;
diff += take;
});
}
} else if (diff > 0) {
const aucun = sliders.find(s => parseInt(s.dataset.factionId) === AUCUN_ID);
if (aucun && parseInt(aucun.dataset.factionId) !== changedFid) {
aucun.value = parseInt(aucun.value) + diff;
diff = 0;
} else {
const other = sliders.find(s => parseInt(s.dataset.factionId) !== changedFid);
if (other) {
other.value = parseInt(other.value) + diff;
diff = 0;
}
}
}
}
sliders.forEach(s => {
const displayId = rowIdx !== null ? `val_${rowIdx}_${s.dataset.factionId}` : `val_orbital_${s.dataset.factionId}`;
document.getElementById(displayId).innerText = s.value + '%';
});
}
function editSlot(num, data) {
document.getElementById('form_slot_num').value = num;
document.getElementById('form_slot_id').value = data ? data.id : 0;
@ -520,10 +736,9 @@ function getStatusColor($status, $type, $statuses_map, $object_types_map) {
if (data) {
document.getElementById('form_name').value = data.name;
document.getElementById('form_type').value = data.type;
document.getElementById('form_status').value = data.status;
document.getElementById('form_faction').value = data.faction_id || 0;
document.getElementById('form_orbital').value = data.orbital_control;
document.getElementById('form_terrestrial').value = data.terrestrial_control;
// Load orbital sliders
initOrbitalSliders(data.orbital_controls);
// Load settlements
document.getElementById('settlementsContainer').innerHTML = '';
@ -534,10 +749,7 @@ function getStatusColor($status, $type, $statuses_map, $object_types_map) {
} else {
document.getElementById('form_name').value = '';
document.getElementById('form_type').value = 'empty';
document.getElementById('form_status').value = 'sta_empty';
document.getElementById('form_faction').value = document.querySelector('#form_faction option').value;
document.getElementById('form_orbital').value = 0;
document.getElementById('form_terrestrial').value = 0;
initOrbitalSliders(null);
document.getElementById('settlementsContainer').innerHTML = '';
}
@ -549,4 +761,4 @@ function getStatusColor($status, $type, $statuses_map, $object_types_map) {
function closeSectorModal() { document.getElementById('sectorModal').style.display = 'none'; }
</script>
</body>
</html>
</html>

382
index.php
View File

@ -55,17 +55,46 @@ if ($view === 'sector') {
$grid[$obj['slot']] = $obj;
$planet_ids[] = $obj['id'];
$grid[$obj['slot']]['cities'] = [];
$grid[$obj['slot']]['orbital_controls'] = [];
}
if (!empty($planet_ids)) {
$placeholders = implode(',', array_fill(0, count($planet_ids), '?'));
// Fetch Orbital Controls
$stmt = $db->prepare("SELECT * FROM planet_faction_control WHERE planet_id IN ($placeholders)");
$stmt->execute($planet_ids);
$orb_controls_raw = $stmt->fetchAll(PDO::FETCH_ASSOC);
foreach ($orb_controls_raw as $ocr) {
foreach ($grid as &$slot_data) {
if ($slot_data && $slot_data['id'] == $ocr['planet_id']) {
$slot_data['orbital_controls'][$ocr['faction_id']] = $ocr['control_level'];
}
}
}
// Fetch Cities
$stmt = $db->prepare("SELECT c.*, st.name as type_name
FROM cities c
LEFT JOIN settlement_types st ON c.settlement_type_id = st.id
WHERE c.planet_id IN ($placeholders)");
$stmt->execute($planet_ids);
$all_cities = $stmt->fetchAll();
$all_cities = $stmt->fetchAll(PDO::FETCH_ASSOC);
$city_ids = array_column($all_cities, 'id');
$city_controls = [];
if (!empty($city_ids)) {
$c_placeholders = implode(',', array_fill(0, count($city_ids), '?'));
$c_stmt = $db->prepare("SELECT * FROM city_faction_control WHERE city_id IN ($c_placeholders)");
$c_stmt->execute($city_ids);
$controls_raw = $c_stmt->fetchAll(PDO::FETCH_ASSOC);
foreach ($controls_raw as $cr) {
$city_controls[$cr['city_id']][$cr['faction_id']] = $cr['control_level'];
}
}
foreach ($all_cities as $city) {
$city['controls'] = $city_controls[$city['id']] ?? [];
foreach ($grid as &$slot_data) {
if ($slot_data && $slot_data['id'] == $city['planet_id']) {
$slot_data['cities'][] = $city;
@ -132,7 +161,7 @@ function getStatusColor($status, $statuses_map) {
gap: 10px;
padding: 15px;
background: rgba(10, 15, 30, 0.5);
border: 1px solid #2d3545;
border: 1px solid #2d3545;
box-shadow: 0 0 30px rgba(0,0,0,0.5);
}
.slot {
@ -229,7 +258,138 @@ function getStatusColor($status, $statuses_map) {
.mini-map { display: grid; grid-template-columns: repeat(6, 12px); gap: 4px; margin-bottom: 15px; background: #000; padding: 6px; border-radius: 2px; }
.mini-dot { width: 12px; height: 12px; border-radius: 1px; }
.tooltip-box { display: none; position: absolute; top: -10px; left: 105%; width: 220px; background: #1e293b; border: 1px solid #88c0d0; padding: 15px; z-index: 100; pointer-events: none; box-shadow: 10px 10px 20px rgba(0,0,0,0.5); }
/* MODAL STYLES */
.modal-overlay {
display: none;
position: fixed;
top: 0; left: 0;
width: 100%; height: 100%;
background: rgba(0, 0, 0, 0.85);
backdrop-filter: blur(5px);
z-index: 2000;
align-items: center;
justify-content: center;
}
.modal-container {
background: #0f172a;
border: 1px solid #1e293b;
border-radius: 12px;
width: 600px;
max-height: 90vh;
overflow-y: auto;
position: relative;
box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
}
.modal-header {
padding: 20px;
border-bottom: 1px solid #1e293b;
display: flex;
justify-content: space-between;
align-items: center;
background: rgba(30, 41, 59, 0.5);
}
.modal-header h2 { margin: 0; font-size: 20px; color: #88c0d0; }
.modal-close {
background: none; border: none; color: #8c92a3; font-size: 24px; cursor: pointer;
transition: color 0.2s;
}
.modal-close:hover { color: #fff; }
.modal-body { padding: 25px; }
.planet-hero {
display: flex;
gap: 25px;
margin-bottom: 25px;
align-items: center;
}
.planet-preview-img {
width: 120px;
height: 120px;
object-fit: contain;
filter: drop-shadow(0 0 15px rgba(136, 192, 208, 0.3));
}
.planet-meta { flex: 1; }
.planet-status-badge {
display: inline-block;
padding: 4px 10px;
border-radius: 20px;
font-size: 11px;
font-weight: bold;
text-transform: uppercase;
margin-bottom: 10px;
}
.planet-description {
font-size: 13px;
color: #94a3b8;
line-height: 1.6;
margin-bottom: 15px;
}
.control-section {
margin-bottom: 25px;
padding: 15px;
background: rgba(30, 41, 59, 0.3);
border-radius: 8px;
border: 1px solid rgba(136, 192, 208, 0.1);
}
.control-title {
font-size: 12px;
font-weight: bold;
color: #88c0d0;
text-transform: uppercase;
margin-bottom: 15px;
display: flex;
align-items: center;
gap: 10px;
}
.control-title i { font-size: 14px; }
/* Multi-colored Progress Bar */
.multi-control-bar {
height: 14px;
background: #1e293b;
border-radius: 7px;
overflow: hidden;
display: flex;
margin-bottom: 10px;
box-shadow: inset 0 2px 4px rgba(0,0,0,0.3);
}
.control-segment {
height: 100%;
transition: width 0.3s ease;
position: relative;
}
.control-legend {
display: flex;
flex-wrap: wrap;
gap: 15px;
margin-top: 10px;
}
.legend-tag {
display: flex;
align-items: center;
gap: 6px;
font-size: 11px;
color: #cbd5e1;
}
.legend-color { width: 10px; height: 10px; border-radius: 2px; }
.settlement-card {
background: rgba(15, 23, 42, 0.6);
border: 1px solid #1e293b;
border-radius: 8px;
padding: 15px;
margin-bottom: 15px;
}
.settlement-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 10px;
}
.settlement-name { font-weight: bold; font-size: 14px; color: #fff; }
.settlement-type { font-size: 10px; color: #8c92a3; text-transform: uppercase; }
.tooltip-box { display: none; position: absolute; top: -10px; left: 105%; width: 240px; background: #1e293b; border: 1px solid #88c0d0; padding: 15px; z-index: 100; pointer-events: none; box-shadow: 10px 10px 20px rgba(0,0,0,0.5); }
.slot:hover .tooltip-box { display: block; }
.tooltip-title { font-size: 14px; color: #88c0d0; font-weight: bold; border-bottom: 1px solid #334155; padding-bottom: 8px; margin-bottom: 8px; }
.tooltip-desc { font-size: 11px; color: #d8dee9; line-height: 1.4; font-style: italic; margin-bottom: 10px; }
@ -239,8 +399,12 @@ function getStatusColor($status, $statuses_map) {
.mod-malus { background: rgba(191, 97, 106, 0.15); color: #bf616a; border: 1px solid rgba(191, 97, 106, 0.3); }
.mod-item i { font-size: 12px; }
.settlement-title { font-size: 10px; color: #ebcb8b; font-weight: bold; border-top: 1px solid #334155; margin-top: 8px; padding-top: 5px; }
.settlement-item-tool { font-size: 9px; color: #fff; margin-bottom: 3px; }
.settlement-title { font-size: 10px; color: #ebcb8b; font-weight: bold; border-top: 1px solid #334155; margin-top: 8px; padding-top: 5px; margin-bottom: 5px; }
.settlement-item-tool { font-size: 9px; color: #fff; margin-bottom: 10px; background: rgba(0,0,0,0.2); padding: 5px; border-radius: 3px; }
.control-bars-mini { margin-top: 5px; display: flex; flex-direction: column; gap: 3px; }
.control-bar-mini { height: 4px; background: #000; border-radius: 2px; overflow: hidden; display: flex; }
.control-fill { height: 100%; }
.control-label-mini { font-size: 7px; color: #8c92a3; display: flex; justify-content: space-between; margin-bottom: 1px; }
.legend { margin-top: 20px; background: rgba(10, 15, 30, 0.95); border: 1px solid #2d3545; padding: 10px 20px; display: flex; gap: 15px; font-size: 10px; flex-wrap: wrap; max-width: 1000px; justify-content: center; }
.legend-item { display: flex; align-items: center; gap: 5px; }
@ -299,9 +463,13 @@ function getStatusColor($status, $statuses_map) {
<?php if($view === 'sector'): ?>
<div class="galaxy-map">
<?php for($i=1; $i<=$grid_size; $i++): ?>
<div class="slot">
<?php
$obj = $grid[$i] ?? null;
$json_data = $obj ? htmlspecialchars(json_encode($obj)) : 'null';
?>
<div class="slot" onclick="openPlanetModal(<?php echo $json_data; ?>)">
<span class="slot-id"><?php echo $i; ?></span>
<?php if (isset($grid[$i])): $obj = $grid[$i];
<?php if ($obj):
$type_info = $object_types_map[$obj['type']] ?? null;
$fac_info = isset($obj['faction_id']) ? ($factions_map[$obj['faction_id']] ?? null) : null;
?>
@ -309,16 +477,60 @@ function getStatusColor($status, $statuses_map) {
<div class="tooltip-title"><?php echo htmlspecialchars($obj['name']); ?></div>
<div style="font-size: 10px; color: #88c0d0; margin-bottom: 5px;"><i class="fa-solid fa-circle-info"></i> <?php echo $statuses_map[$obj['status']]['name'] ?? ucfirst($obj['status']); ?></div>
<?php if ($fac_info && $fac_info['name'] !== 'Aucune'): ?>
<div style="font-size: 10px; color: #ebcb8b; margin-bottom: 5px;"><i class="fa-solid fa-flag"></i> Faction: <?php echo htmlspecialchars($fac_info['name']); ?></div>
<div style="font-size: 10px; color: <?php echo htmlspecialchars($fac_info['color'] ?? '#ebcb8b'); ?>; margin-bottom: 5px;"><i class="fa-solid fa-flag"></i> Faction: <?php echo htmlspecialchars($fac_info['name']); ?></div>
<?php endif; ?>
<div class="tooltip-desc"><?php echo htmlspecialchars($type_info['description'] ?? ''); ?></div>
<!-- Orbital Control Breakdown -->
<?php if (!empty($obj['orbital_controls'])): ?>
<div class="settlement-title" style="color: #88c0d0;"><i class="fa-solid fa-satellite-dish"></i> Contrôle Orbital:</div>
<div class="settlement-item-tool">
<div class="control-bars-mini">
<?php
foreach ($obj['orbital_controls'] as $fid => $lvl):
if ($lvl <= 0) continue;
$fName = $factions_map[$fid]['name'] ?? 'Inconnue';
$fColor = $factions_map[$fid]['color'] ?? '#88c0d0';
?>
<div class="control-label-mini">
<span><?php echo htmlspecialchars($fName); ?></span>
<span><?php echo $lvl; ?>%</span>
</div>
<div class="control-bar-mini">
<div class="control-fill" style="width: <?php echo $lvl; ?>%; background: <?php echo htmlspecialchars($fColor); ?>;"></div>
</div>
<?php endforeach; ?>
</div>
</div>
<?php endif; ?>
<?php if (!empty($obj['cities'])): ?>
<div class="settlement-title"><i class="fa-solid fa-city"></i> Établissements:</div>
<?php foreach ($obj['cities'] as $c): ?>
<div class="settlement-item-tool">
<strong><?php echo htmlspecialchars($c['name']); ?></strong>
<span style="color: #8c92a3; font-size: 8px;">(<?php echo htmlspecialchars($c['type_name']); ?>)</span>
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px;">
<strong><?php echo htmlspecialchars($c['name']); ?></strong>
<span style="color: #8c92a3; font-size: 7px;"><?php echo htmlspecialchars($c['type_name']); ?></span>
</div>
<?php if (!empty($c['controls'])): ?>
<div class="control-bars-mini">
<?php
foreach ($c['controls'] as $fid => $lvl):
if ($lvl <= 0) continue;
$fName = $factions_map[$fid]['name'] ?? 'Inconnue';
$fColor = $factions_map[$fid]['color'] ?? '#88c0d0';
?>
<div class="control-label-mini">
<span><?php echo htmlspecialchars($fName); ?></span>
<span><?php echo $lvl; ?>%</span>
</div>
<div class="control-bar-mini">
<div class="control-fill" style="width: <?php echo $lvl; ?>%; background: <?php echo htmlspecialchars($fColor); ?>;"></div>
</div>
<?php endforeach; ?>
</div>
<?php endif; ?>
</div>
<?php endforeach; ?>
<?php endif; ?>
@ -341,7 +553,7 @@ function getStatusColor($status, $statuses_map) {
<?php if (!empty($fac_info['image_url'])): ?>
<img src="<?php echo htmlspecialchars($fac_info['image_url']); ?>?v=<?php echo time(); ?>" style="width: 100%; height: 100%; object-fit: contain;" title="<?php echo htmlspecialchars($fac_info['name']); ?>">
<?php elseif (!empty($fac_info['fa_icon'])): ?>
<i class="fa-solid <?php echo htmlspecialchars($fac_info['fa_icon']); ?>" style="color: #fff; font-size: 16px;" title="<?php echo htmlspecialchars($fac_info['name']); ?>"></i>
<i class="fa-solid <?php echo htmlspecialchars($fac_info['fa_icon']); ?>" style="color: <?php echo htmlspecialchars($fac_info['color'] ?? '#fff'); ?>; font-size: 16px;" title="<?php echo htmlspecialchars($fac_info['name']); ?>"></i>
<?php endif; ?>
</div>
<?php endif; ?>
@ -402,13 +614,157 @@ function getStatusColor($status, $statuses_map) {
</main>
</div>
<!-- MODAL OVERLAY -->
<div id="planetModal" class="modal-overlay" onclick="if(event.target === this) closePlanetModal()">
<div class="modal-container">
<div class="modal-header">
<h2 id="m-planet-name">Planet Name</h2>
<button class="modal-close" onclick="closePlanetModal()">&times;</button>
</div>
<div class="modal-body">
<div class="planet-hero">
<img id="m-planet-img" src="" class="planet-preview-img">
<div class="planet-meta">
<div id="m-planet-status" class="planet-status-badge">Status</div>
<div id="m-planet-faction" style="font-size: 13px; font-weight: bold; margin-bottom: 8px;">Faction: None</div>
<div id="m-planet-mods" class="mod-list"></div>
</div>
</div>
<div id="m-orbital-section" class="control-section">
<div class="control-title"><i class="fa-solid fa-satellite-dish"></i> Contrôle Orbital</div>
<div id="m-orbital-bar" class="multi-control-bar"></div>
<div id="m-orbital-legend" class="control-legend"></div>
</div>
<div id="m-cities-section">
<div class="control-title"><i class="fa-solid fa-city"></i> Établissements & Villes</div>
<div id="m-cities-container"></div>
</div>
</div>
</div>
</div>
<?php if ($user_role === 'admin' || $user_role === 'gm'): ?>
<div class="admin-footer">
<a href="gm_console.php" target="_blank" class="btn-mj"><i class="fa-solid fa-headset"></i> CONSOLE MG</a>
<a href="gm_console.php" class="btn-mj"><i class="fa-solid fa-headset"></i> CONSOLE MG</a>
<?php if ($user_role === 'admin'): ?>
<a href="admin.php" target="_blank" class="btn-adm"><i class="fa-solid fa-shield-halved"></i> CONSOLE ADMIN</a>
<a href="admin.php" class="btn-adm"><i class="fa-solid fa-shield-halved"></i> CONSOLE ADMIN</a>
<?php endif; ?>
</div>
<?php endif; ?>
<script>
const factionsMap = <?php echo json_encode($factions_map); ?>;
const typesMap = <?php echo json_encode($object_types_map); ?>;
const statusesMap = <?php echo json_encode($statuses_map); ?>;
function openPlanetModal(data) {
if (!data) return;
const typeInfo = typesMap[data.type] || {};
const statusInfo = statusesMap[data.status] || {};
const factionInfo = factionsMap[data.faction_id] || { name: 'Aucune', color: '#8c92a3' };
document.getElementById('m-planet-name').innerText = data.name;
document.getElementById('m-planet-img').src = typeInfo.image_url || '';
document.getElementById('m-planet-status').innerText = statusInfo.name || data.status;
document.getElementById('m-planet-status').style.background = statusInfo.color || 'rgba(255,255,255,0.1)';
document.getElementById('m-planet-faction').innerText = 'Faction dominante: ' + factionInfo.name;
document.getElementById('m-planet-faction').style.color = factionInfo.color || '#fff';
// Display modifiers instead of description
const modContainer = document.getElementById('m-planet-mods');
modContainer.innerHTML = '';
if (typeInfo.modifiers && typeInfo.modifiers.length > 0) {
typeInfo.modifiers.forEach(m => {
const modDiv = document.createElement('div');
modDiv.className = 'mod-item ' + (m.type === 'bonus' ? 'mod-bonus' : 'mod-malus');
modDiv.innerHTML = `
<i class="fa-solid ${m.type === 'bonus' ? 'fa-circle-up' : 'fa-circle-down'}"></i>
<strong>${m.name}:</strong> ${m.description}
`;
modContainer.appendChild(modDiv);
});
} else {
modContainer.innerHTML = '<div style="font-size: 11px; color: #64748b; font-style: italic;">Aucun modificateur particulier.</div>';
}
// Orbital Control
const orbitalBar = document.getElementById('m-orbital-bar');
const orbitalLegend = document.getElementById('m-orbital-legend');
orbitalBar.innerHTML = '';
orbitalLegend.innerHTML = '';
if (data.orbital_controls && Object.keys(data.orbital_controls).length > 0) {
document.getElementById('m-orbital-section').style.display = 'block';
renderMultiBar(data.orbital_controls, orbitalBar, orbitalLegend);
} else {
document.getElementById('m-orbital-section').style.display = 'none';
}
// Cities
const citiesContainer = document.getElementById('m-cities-container');
citiesContainer.innerHTML = '';
if (data.cities && data.cities.length > 0) {
document.getElementById('m-cities-section').style.display = 'block';
data.cities.forEach(city => {
const card = document.createElement('div');
card.className = 'settlement-card';
const header = document.createElement('div');
header.className = 'settlement-header';
header.innerHTML = `<span class="settlement-name">${city.name}</span><span class="settlement-type">${city.type_name}</span>`;
card.appendChild(header);
if (city.controls && Object.keys(city.controls).length > 0) {
const bar = document.createElement('div');
bar.className = 'multi-control-bar';
const legend = document.createElement('div');
legend.className = 'control-legend';
renderMultiBar(city.controls, bar, legend);
card.appendChild(bar);
card.appendChild(legend);
}
citiesContainer.appendChild(card);
});
} else {
document.getElementById('m-cities-section').style.display = 'none';
}
document.getElementById('planetModal').style.display = 'flex';
}
function renderMultiBar(controls, barElement, legendElement) {
Object.entries(controls).forEach(([fid, lvl]) => {
const level = parseInt(lvl);
const fac = factionsMap[fid] || { name: 'Inconnue', color: '#88c0d0' };
if (level <= 0) return;
// Segment
const segment = document.createElement('div');
segment.className = 'control-segment';
segment.style.width = level + '%';
segment.style.backgroundColor = fac.color || '#88c0d0';
segment.title = `${fac.name}: ${level}%`;
barElement.appendChild(segment);
// Legend
const tag = document.createElement('div');
tag.className = 'legend-tag';
tag.innerHTML = `<span class="legend-color" style="background:${fac.color}"></span> ${fac.name}: ${level}%`;
legendElement.appendChild(tag);
});
}
function closePlanetModal() {
document.getElementById('planetModal').style.display = 'none';
}
</script>
</body>
</html>