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

@ -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