update game for all

This commit is contained in:
mrtoine 2025-09-30 19:22:13 +02:00
parent 423134a840
commit 429112c335
29 changed files with 175 additions and 139 deletions

View file

@ -1 +0,0 @@
LE CODE

View file

@ -1,7 +0,0 @@
fileFormatVersion: 2
guid: 316f69e8b296f2045901b9fbc5e1a35c
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 7aeca2c5510942e5a3c45ff5272bc040
timeCreated: 1759234532

View file

@ -0,0 +1,8 @@
namespace Core.Runtime.Enums
{
public enum EnumLanguage
{
English,
French,
}
}

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: a1f020b6f635444c89c9d8b30acec48b
timeCreated: 1759234549

View file

@ -1,6 +1,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using Core.Runtime.Enums;
using UnityEngine;
using UnityEngine.SceneManagement;
@ -58,7 +59,7 @@ namespace Core.Runtime
set => _canPause = value;
}
public string CurrentLanguage
public EnumLanguage CurrentLanguage
{
get
{
@ -130,15 +131,25 @@ namespace Core.Runtime
m_gameFacts = new FactDictionnary();
_localTexts = new Dictionary<string, string>();
LoadFacts("GeneralSettings");
_fact = m_gameFacts;
CurrentLanguage = m_gameFacts.GetFact<string>("language");
if (!m_gameFacts.FactExists<string>("language", out _))
// Chargement ou création des paramètres
if (m_gameFacts.SaveFileExists("GeneralSettings"))
{
m_gameFacts.SetFact("language", "fr", FactPersistence.Persistent);
Debug.Log("<color=green>GeneralSettings exist</color>");
LoadFacts("GeneralSettings");
}
LocalizationSystem.Instance.LoadLanguage();
else
{
Debug.Log("<color=orange>GeneralSettings does not exist</color>");
GeneralSettings settings = new GeneralSettings
{
Language = EnumLanguage.English,
};
SetFact("GeneralSettings", settings, FactPersistence.Persistent);
SaveFacts("GeneralSettings");
}
CurrentLanguage = GetFact<GeneralSettings>("GeneralSettings").Language;
LocalizationSystem.Instance.LoadLanguage(CurrentLanguage);
}
#endregion
@ -192,13 +203,13 @@ namespace Core.Runtime
#region Privates and Protected
private bool isOnPause = false;
private SceneLoader _sceneLoader;
private FactDictionnary _fact;
private bool _canPause;
private string _profile;
private string _currentLanguage = "en";
private Dictionary<string, string> _localTexts;
bool isOnPause = false;
SceneLoader _sceneLoader;
FactDictionnary _fact;
bool _canPause;
string _profile;
EnumLanguage _currentLanguage;
Dictionary<string, string> _localTexts;
bool _launchedTime;
int _currentGameTime = 0;
GameTime _gameTime;

View file

@ -1,4 +1,6 @@
using System;
using System.IO;
using Core.Runtime.Enums;
using TMPro;
using UnityEngine;
@ -59,23 +61,18 @@ namespace Core.Runtime
SetFact<string>("language", newLanguage, FactPersistence.Persistent);
}
public void LoadLanguage()
public void LoadLanguage(EnumLanguage langReceived)
{
/*if (!FactExists<string>("language", out var language))
string lang = langReceived.ToString();
if (Enum.TryParse(lang, out EnumLanguage parsedLang))
{
SetFact("language", language, FactPersistence.Persistent);
}*/
string lang = GetLanguage();
GameManager.Instance.CurrentLanguage = lang;
string langFile = GetLanguageFile();
if (!string.IsNullOrEmpty(langFile))
{
GameManager.Instance.GetLocalTexts = XmlLoader.LoadDictionary(GetLanguageFile());
GameManager.Instance.GetLocalTexts = XmlLoader.LoadDictionary(GetLanguageFile(parsedLang));
}
else
{
Debug.LogError($"Language {lang} not found");
return;
}
}
@ -90,15 +87,16 @@ namespace Core.Runtime
return file.Split('/')[file.Split('/').Length - 1].Split('.')[0];
}
private string GetLanguageFile()
private string GetLanguageFile(EnumLanguage lang = EnumLanguage.French)
{
string filename = Application.dataPath + "/_/Database/Localization/" + GetFact<string>("language") + ".xml";
string filename = $"Localization/{lang}.xml";
string filepath = Path.Combine(Application.streamingAssetsPath, filename);
if (File.Exists(filename))
if (File.Exists(filepath))
{
return filename;
return filepath;
}
return "";
return Path.Combine(Application.streamingAssetsPath, "French.xml");
}
#endregion

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: c462b8bd55c644cd93431eff1f2da5d2
timeCreated: 1759234811

View file

@ -0,0 +1,26 @@
using Core.Runtime.Enums;
namespace Core.Runtime
{
public class GeneralSettings
{
#region Attributes
EnumLanguage _language;
#endregion
public EnumLanguage Language
{
get
{
return _language;
}
set
{
_language = value;
}
}
}
}

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 45ead23d22c643d8be8bf9c1e34904fc
timeCreated: 1759234823

View file

@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: 5ac3d52df8c674b6d8b4508eeb23d622
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: 0ced038fa2686a645995f62841bab076
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -1,16 +0,0 @@
{
"name": "Template.Editor",
"rootNamespace": "Template.Editor",
"references": [],
"includePlatforms": [
"Editor"
],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}

View file

@ -1,7 +0,0 @@
fileFormatVersion: 2
guid: e71f3931e213bd349b00738e7d5376d0
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -1,34 +0,0 @@
using Core.Runtime;
using UnityEngine;
namespace TestFacts.Runtime
{
public class testLocalization : BaseMonobehaviour
{
private LocalizationSystem _localization = LocalizationSystem.Instance;
[ContextMenu("Current Language ?")]
public void GetCurrentLanguage()
{
_localization.LoadLanguage();
// Affichage de la langue courante
}
[ContextMenu("Mettre en anglais")]
public void SetEnglish()
{
GameManager.Instance.CurrentLanguage = "en";
_localization.SaveLanguage(GameManager.Instance.CurrentLanguage);
SaveFacts("GeneralSettings");
}
[ContextMenu("Mettre en français")]
public void SetFrench()
{
GameManager.Instance.CurrentLanguage = "fr";
_localization.SaveLanguage(GameManager.Instance.CurrentLanguage);
SaveFacts("GeneralSettings");
}
}
}

View file

@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: 55ed85535e4d41bdadca7f7c2628ddff
timeCreated: 1752476966

View file

@ -1,4 +1,3 @@
using Codice.CM.Common;
using Core.Runtime;
using TMPro;
using UnityEngine;