Settings : tab A PROPOS (version, chemin du debug log, Gitea + check MAJ)
Retour v0.13.0 ('ajouter un écran à propos dans les settings — on peut
remplacer la partie graphique') : la tab GRAPHICS 2017 était une coque
vide sans réglage actif -> remplacée par AboutSettingsTab : version
(Dethsquare.VERSION, source unique), emplacement du debug log par
plateforme, lien Gitea + bouton VERIFIER LES MAJ (GET API publique
releases/latest sur un thread dédié, timeouts 5s, résultat poussé au
thread GL via sonde volatile dans update() ; comparaison sémantique
X.Y.Z ; HORS LIGNE sans crash). Libellés sans glyphes absents de
l'atlas. versionName 0.13.0 / versionCode 14 (bump à 2 endroits :
Dethsquare.VERSION + build.gradle — cf. AGENTS.md).
This commit is contained in:
parent
e9c3469f39
commit
e33edad7e7
@ -34,8 +34,13 @@ android {
|
|||||||
applicationId 'fr.siphonight.lostsectorport'
|
applicationId 'fr.siphonight.lostsectorport'
|
||||||
minSdk 24 // java.util.stream (parallelStream dans GraphicsEngine)
|
minSdk 24 // java.util.stream (parallelStream dans GraphicsEngine)
|
||||||
targetSdk 36
|
targetSdk 36
|
||||||
versionCode 13
|
// À bump EN MÊME TEMPS que Dethsquare.VERSION (dethsquare/base .../
|
||||||
versionName '0.12.1'
|
// util/Dethsquare.java) à chaque release : l'écran A PROPOS affiche
|
||||||
|
// la constante, la numérotation APK vient d'ici — deux sources qui
|
||||||
|
// doivent rester en phase (leçon v0.4.0..v0.11.0 : versionName
|
||||||
|
// restée '0.2.2' faute de bump).
|
||||||
|
versionCode 14
|
||||||
|
versionName '0.13.0'
|
||||||
}
|
}
|
||||||
|
|
||||||
compileOptions {
|
compileOptions {
|
||||||
|
|||||||
@ -1,6 +1,20 @@
|
|||||||
package com.ezardlabs.dethsquare.util;
|
package com.ezardlabs.dethsquare.util;
|
||||||
|
|
||||||
public final class Dethsquare {
|
public final class Dethsquare {
|
||||||
|
/*
|
||||||
|
* Version du jeu, source UNIQUE de l'affichage (tab A PROPOS des
|
||||||
|
* settings, retour utilisateur v0.13.0) et du check de mises à jour.
|
||||||
|
*
|
||||||
|
* POURQUOI une constante plutôt que PackageManager (Android) ou un
|
||||||
|
* version.txt généré au build : SIMPLICITÉ PRIME — un seul point de
|
||||||
|
* lecture sur les deux plateformes, aucune API plateforme à exposer.
|
||||||
|
* Contrepartie documentée : À CHAQUE RELEASE, bump manuel en MÊME
|
||||||
|
* TEMPS que versionName/versionCode d'android-app/build.gradle (la
|
||||||
|
* fuite v0.4.0..v0.11.0 sur versionName restée '0.2.2' montre ce que
|
||||||
|
* coûte un bump oublié — ce champ ne doit pas suivre le même chemin).
|
||||||
|
*/
|
||||||
|
public static final String VERSION = "0.13.0";
|
||||||
|
|
||||||
public static Platform PLATFORM;
|
public static Platform PLATFORM;
|
||||||
public static AudioUtils AUDIO;
|
public static AudioUtils AUDIO;
|
||||||
public static IOUtils IO;
|
public static IOUtils IO;
|
||||||
|
|||||||
@ -10,6 +10,16 @@ import com.ezardlabs.dethsquare.Script;
|
|||||||
import com.ezardlabs.dethsquare.TextureAtlas;
|
import com.ezardlabs.dethsquare.TextureAtlas;
|
||||||
import com.ezardlabs.dethsquare.Time;
|
import com.ezardlabs.dethsquare.Time;
|
||||||
import com.ezardlabs.dethsquare.Vector2;
|
import com.ezardlabs.dethsquare.Vector2;
|
||||||
|
import com.ezardlabs.dethsquare.util.Dethsquare;
|
||||||
|
import com.ezardlabs.dethsquare.util.GameLog;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
|
import javax.net.ssl.HttpsURLConnection;
|
||||||
|
|
||||||
public class SettingsMenu extends Script {
|
public class SettingsMenu extends Script {
|
||||||
private static final String AUDIO_MASTER_VOLUME = "audio_master_volume";
|
private static final String AUDIO_MASTER_VOLUME = "audio_master_volume";
|
||||||
@ -65,7 +75,7 @@ public class SettingsMenu extends Script {
|
|||||||
132f - menuText.getFontSize() / 2))).transform.setParent(transform);
|
132f - menuText.getFontSize() / 2))).transform.setParent(transform);
|
||||||
|
|
||||||
GameObject.instantiate(new GameObject("Settings Tab Manager",
|
GameObject.instantiate(new GameObject("Settings Tab Manager",
|
||||||
new SettingsTabManager(new AudioSettingsTab(), new GraphicsSettingsTab(), new ControlsSettingsTab())),
|
new SettingsTabManager(new AudioSettingsTab(), new AboutSettingsTab(), new ControlsSettingsTab())),
|
||||||
new Vector2(transform.position)).transform.setParent(transform);
|
new Vector2(transform.position)).transform.setParent(transform);
|
||||||
gameObject.setActive(false);
|
gameObject.setActive(false);
|
||||||
}
|
}
|
||||||
@ -171,16 +181,224 @@ public class SettingsMenu extends Script {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class GraphicsSettingsTab implements SettingsTab {
|
/*
|
||||||
|
* Tab A PROPOS (retour utilisateur v0.13.0, REMPLACE GRAPHICS). POURQUOI
|
||||||
|
* la suppression est sans perte : la tab GRAPHICS d'origine 2017 était
|
||||||
|
* une coque vide — getRootObject() instanciait un GameObject sans
|
||||||
|
* AUCUN composant, aucun réglage graphique actif n'a jamais existé
|
||||||
|
* derrière (aucun réglage à reporter en 5ᵉ tab). Contenu : version du
|
||||||
|
* jeu, emplacement du debug log, lien Gitea + check de mises à jour.
|
||||||
|
*/
|
||||||
|
private class AboutSettingsTab implements SettingsTab {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getTitle() {
|
public String getTitle() {
|
||||||
return "GRAPHICS";
|
// Sans accent : l'atlas de fonte n'a aucun glyphe É (fonts/atlas
|
||||||
|
// .txt) — un É serait silencieusement sauté par GuiText.
|
||||||
|
return "A PROPOS";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GameObject getRootObject() {
|
public GameObject getRootObject() {
|
||||||
return GameObject.instantiate(new GameObject(), new Vector2());
|
GameObject root = GameObject.instantiate(new GameObject(), new Vector2());
|
||||||
|
addText(root, "VERSION : " + Dethsquare.VERSION, 256.25f, 31.25f);
|
||||||
|
addText(root, "DEBUG LOG :", 356.25f, 31.25f);
|
||||||
|
if (Dethsquare.PLATFORM == Dethsquare.Platform.ANDROID) {
|
||||||
|
/*
|
||||||
|
* POURQUOI sans "/" : le glyphe n'existe pas dans l'atlas de
|
||||||
|
* fonte 2017 (GuiText saute les caractères absents, cf. son
|
||||||
|
* commentaire v0.11.0) — le chemin est décrit par segments
|
||||||
|
* séparés d'espaces. Fichiers réels : gamelog-latest.txt
|
||||||
|
* (dump périodique) et crash-<date>.txt (crash handler).
|
||||||
|
*/
|
||||||
|
addText(root, "SDCARD ANDROID DATA FR.SIPHONIGHT.LOSTSECTORPORT FILES",
|
||||||
|
412.5f, 20f);
|
||||||
|
addText(root, "FICHIERS : GAMELOG-LATEST.TXT ET CRASH-DATE.TXT", 450f, 20f);
|
||||||
|
} else {
|
||||||
|
addText(root, "DOSSIER DE LANCEMENT DU JEU", 412.5f, 20f);
|
||||||
|
addText(root, "LE JOURNAL SORT AUSSI DANS LA CONSOLE", 450f, 20f);
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
* URL de la page releases, même contrainte de glyphe ("/"
|
||||||
|
* absent) : segments séparés d'espaces.
|
||||||
|
*/
|
||||||
|
addText(root, "GITEA.CLOUDYFY.FR SIPHONIGHT LOST-SECTOR-PORT RELEASES", 556.25f, 20f);
|
||||||
|
GameObject.instantiate(new GameObject("Update Checker", new UpdateChecker()),
|
||||||
|
new Vector2(transform.position)).transform.setParent(root.transform);
|
||||||
|
return root;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Texte d'information : depth 12, au-dessus du fond du panneau (10). */
|
||||||
|
private void addText(GameObject root, String text, float offsetY, float fontSize) {
|
||||||
|
GuiText guiText = new GuiText(text, font, fontSize, 12);
|
||||||
|
GameObject.instantiate(new GameObject("About Text", guiText),
|
||||||
|
new Vector2(transform.position.offset(206.25f, offsetY))).transform.setParent(
|
||||||
|
root.transform);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Check de mises à jour : HTTP GET sur l'API publique Gitea (aucun
|
||||||
|
* token), comparaison du tag de la dernière release avec Dethsquare
|
||||||
|
* .VERSION, résultat en TEXTE (pas d'ouverture de navigateur, pas
|
||||||
|
* d'auto-update).
|
||||||
|
*
|
||||||
|
* PATTERN THREADING (calqué sur Network/UDPReader -> Matchmaker) : le
|
||||||
|
* HTTP tourne sur un thread dédié (JAMAIS le thread GL, timeouts de
|
||||||
|
* 5 s) et publie le résultat dans un champ volatile ; update() (thread
|
||||||
|
* GL) sonde ce champ chaque frame et pousse le texte dans le GuiText.
|
||||||
|
* POURQUOI pas GameListeners.addUpdateListener : l'interface n'est
|
||||||
|
* JAMAIS vidée au changement de niveau (GameListeners.java, aucun
|
||||||
|
* clearAll) — un listener enregistré ici survivrait au menu détruit et
|
||||||
|
* fuiterait à chaque niveau chargé ; un Script lié au menu vit et meurt
|
||||||
|
* avec lui (coût : le résultat d'un check resté en vol est appliqué à
|
||||||
|
* la réouverture du menu).
|
||||||
|
*/
|
||||||
|
private class UpdateChecker extends Script {
|
||||||
|
private GuiText button;
|
||||||
|
private GuiText status;
|
||||||
|
/*
|
||||||
|
* volatile : écrit par le thread HTTP, lu par le thread GL ;
|
||||||
|
* String immuable = publication sûre dès la lecture du champ.
|
||||||
|
*/
|
||||||
|
private volatile String pendingResult = null;
|
||||||
|
/** Écrit puis lu par le thread GL uniquement (volatile par discipline). */
|
||||||
|
private volatile boolean inFlight = false;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void start() {
|
||||||
|
runWhenPaused = true;
|
||||||
|
button = new GuiText("VERIFIER LES MAJ", font, 31.25f, 12);
|
||||||
|
GameObject.instantiate(new GameObject("Update Check Button", button),
|
||||||
|
new Vector2(transform.position.offset(206.25f, 656.25f))).transform.setParent(
|
||||||
|
transform);
|
||||||
|
status = new GuiText("", font, 25f, 12);
|
||||||
|
GameObject.instantiate(new GameObject("Update Check Status", status),
|
||||||
|
new Vector2(transform.position.offset(206.25f, 721.25f))).transform.setParent(
|
||||||
|
transform);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void update() {
|
||||||
|
// Drain du résultat produit par le thread HTTP (pattern Network).
|
||||||
|
String result = pendingResult;
|
||||||
|
if (result != null) {
|
||||||
|
pendingResult = null;
|
||||||
|
inFlight = false;
|
||||||
|
status.setText(result);
|
||||||
|
}
|
||||||
|
if (inFlight) {
|
||||||
|
return; // pas de re-spam du bouton pendant la requête (5 s max)
|
||||||
|
}
|
||||||
|
if (Input.getKeyDown(KeyCode.MOUSE_LEFT) && button.hitTest(Input.mousePosition)) {
|
||||||
|
startCheck();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void startCheck() {
|
||||||
|
inFlight = true;
|
||||||
|
status.setText("VERIFICATION...");
|
||||||
|
GameLog.i("LS-INPUT", "Settings A PROPOS : check de maj lance (local v"
|
||||||
|
+ Dethsquare.VERSION + ")");
|
||||||
|
// Daemon : un check resté en vol ne doit pas retenir le process.
|
||||||
|
Thread thread = new Thread(this::checkForUpdate, "LS-UPDATE-CHECK");
|
||||||
|
thread.setDaemon(true);
|
||||||
|
thread.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Thread HTTP : I/O réseau seule, aucun contact avec le rendu. */
|
||||||
|
private void checkForUpdate() {
|
||||||
|
String result;
|
||||||
|
try {
|
||||||
|
String tag = fetchLatestReleaseTag();
|
||||||
|
result = compareWithLocal(tag);
|
||||||
|
GameLog.i("LS-INPUT", "check de maj termine : tag=" + tag + " -> " + result);
|
||||||
|
} catch (Throwable t) {
|
||||||
|
// Absence de réseau, DNS mort, timeout : message sans crash.
|
||||||
|
GameLog.w("LS-INPUT", "check de maj impossible (reseau)", t);
|
||||||
|
result = "HORS LIGNE";
|
||||||
|
}
|
||||||
|
pendingResult = result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String compareWithLocal(String tag) {
|
||||||
|
if (tag == null) {
|
||||||
|
return "ERREUR : AUCUNE RELEASE";
|
||||||
|
}
|
||||||
|
int comparison = compareVersions(
|
||||||
|
tag.startsWith("v") ? tag.substring(1) : tag, Dethsquare.VERSION);
|
||||||
|
// comparison < 0 : le local est plus récent que la dernière
|
||||||
|
// release publiée (build de dev) — aucune mise à jour à proposer.
|
||||||
|
return comparison > 0 ? "NOUVELLE VERSION : " + tag : "A JOUR";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Comparaison X.Y.Z (signification SemVer du dépôt :
|
||||||
|
* MAJOR.MINOR.PATCH). Retourne > 0 si a est plus récent que b.
|
||||||
|
* POURQUOI pas une simple égalité de tag : un build de dev local
|
||||||
|
* (0.13.0) face à la release précédente (v0.12.1) ne doit PAS
|
||||||
|
* afficher "NOUVELLE VERSION" vers une version plus ancienne.
|
||||||
|
*/
|
||||||
|
private int compareVersions(String a, String b) {
|
||||||
|
try {
|
||||||
|
String[] partsA = a.split("\\.");
|
||||||
|
String[] partsB = b.split("\\.");
|
||||||
|
int length = Math.max(partsA.length, partsB.length);
|
||||||
|
for (int i = 0; i < length; i++) {
|
||||||
|
int va = i < partsA.length ? Integer.parseInt(partsA[i]) : 0;
|
||||||
|
int vb = i < partsB.length ? Integer.parseInt(partsB[i]) : 0;
|
||||||
|
if (va != vb) {
|
||||||
|
return va - vb;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
// Tag au format inattendu : comparaison lexicale de repli.
|
||||||
|
return a.compareTo(b);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* GET https://gitea.cloudyfy.fr/api/v1/repos/Siphonight/
|
||||||
|
* lost-sector-port/releases/latest (API publique, testée v0.12.1).
|
||||||
|
* Extraction manuelle de "tag_name" : org.json n'est pas exposé au
|
||||||
|
* module du jeu (implementation dans dethsquare/core/build.gradle —
|
||||||
|
* invisible du classpath de compilation :lost-sector desktop) et le
|
||||||
|
* JSON Gitea est stable, inutile d'ajouter une dépendance.
|
||||||
|
*/
|
||||||
|
private String fetchLatestReleaseTag() throws IOException {
|
||||||
|
HttpsURLConnection connection = (HttpsURLConnection) new URL(
|
||||||
|
"https://gitea.cloudyfy.fr/api/v1/repos/Siphonight/lost-sector-port/releases/latest")
|
||||||
|
.openConnection();
|
||||||
|
try {
|
||||||
|
// Timeouts courts (5 s) : un serveur injoignable ne doit ni
|
||||||
|
// bloquer l'utilisateur ni laisser un thread mort indéfini.
|
||||||
|
connection.setConnectTimeout(5000);
|
||||||
|
connection.setReadTimeout(5000);
|
||||||
|
connection.setRequestMethod("GET");
|
||||||
|
int code = connection.getResponseCode();
|
||||||
|
if (code != 200) {
|
||||||
|
throw new IOException("HTTP " + code);
|
||||||
|
}
|
||||||
|
StringBuilder body = new StringBuilder();
|
||||||
|
try (BufferedReader reader = new BufferedReader(new InputStreamReader(
|
||||||
|
connection.getInputStream(), StandardCharsets.UTF_8))) {
|
||||||
|
String line;
|
||||||
|
while ((line = reader.readLine()) != null) {
|
||||||
|
body.append(line);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String marker = "\"tag_name\"";
|
||||||
|
int markerIndex = body.indexOf(marker);
|
||||||
|
if (markerIndex < 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
int openQuote = body.indexOf("\"", body.indexOf(":", markerIndex) + 1);
|
||||||
|
int closeQuote = body.indexOf("\"", openQuote + 1);
|
||||||
|
return body.substring(openQuote + 1, closeQuote);
|
||||||
|
} finally {
|
||||||
|
connection.disconnect();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user