Skip to content

Commit

Permalink
small refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
LazyDuchess committed Jun 28, 2024
1 parent 5396d7e commit b82da1c
Show file tree
Hide file tree
Showing 21 changed files with 47 additions and 69 deletions.
2 changes: 1 addition & 1 deletion Assets/Scripts/OpenTS2/Audio/MusicController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ private void OnNeighborhoodEntered()

private void OnLotLoaded()
{
if (CASController.Instance.InCAS)
if (CASManager.Instance.InCAS)
StartMusicCategory("CAS");
else
Stop();
Expand Down
1 change: 0 additions & 1 deletion Assets/Scripts/OpenTS2/Audio/MusicManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using OpenTS2.Engine;
using OpenTS2.Files.Formats.DBPF;
using OpenTS2.Files.Formats.XML;
using OpenTS2.Client;
using System;
using System.Collections.Generic;
using System.IO;
Expand Down
29 changes: 0 additions & 29 deletions Assets/Scripts/OpenTS2/Client/Settings.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@

namespace OpenTS2.Content
{
public class CASController
public class CASManager
{
public static CASController Instance { get; private set; }
public static CASManager Instance { get; private set; }
public bool InCAS = false;
private const string CASLotName = "CAS!";
private static ResourceKey CASLotKey = new ResourceKey(0, CASLotName, TypeIDs.BASE_LOT_INFO);

public CASController()
public CASManager()
{
Instance = this;
}
Expand Down
7 changes: 3 additions & 4 deletions Assets/Scripts/OpenTS2/Content/ContentLoading.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OpenTS2.Client;
using OpenTS2.Content.Interfaces;
using OpenTS2.Files;

Expand All @@ -26,7 +25,7 @@ public static class ContentLoading
public static void LoadContentStartup()
{
var startupPackages = Filesystem.GetStartupPackages();
if (Settings.Instance.CustomContentEnabled)
if (GameGlobals.allowCustomContent)
startupPackages.AddRange(Filesystem.GetStartupDownloadPackages());
ContentManager.Instance.AddPackages(startupPackages);
}
Expand All @@ -39,7 +38,7 @@ public static async Task LoadGameContentAsync(LoadProgress loadProgress)
{
var gamePackages = Filesystem.GetMainPackages();
gamePackages.AddRange(Filesystem.GetUserPackages());
if (Settings.Instance.CustomContentEnabled)
if (GameGlobals.allowCustomContent)
gamePackages.AddRange(Filesystem.GetStreamedDownloadPackages());
await ContentManager.Instance.AddPackagesAsync(gamePackages, loadProgress);
}
Expand All @@ -51,7 +50,7 @@ public static void LoadGameContentSync()
{
var gamePackages = Filesystem.GetMainPackages();
gamePackages.AddRange(Filesystem.GetUserPackages());
if (Settings.Instance.CustomContentEnabled)
if (GameGlobals.allowCustomContent)
gamePackages.AddRange(Filesystem.GetStreamedDownloadPackages());
ContentManager.Instance.AddPackages(gamePackages);
}
Expand Down
7 changes: 3 additions & 4 deletions Assets/Scripts/OpenTS2/Content/DBPF/StringSetAsset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
using System.Text;
using System.Threading.Tasks;
using OpenTS2.Files.Formats.DBPF;
using OpenTS2.Client;

namespace OpenTS2.Content.DBPF
{
Expand Down Expand Up @@ -122,12 +121,12 @@ public StringSetAsset(StringSetData stringData)
/// <returns>Localized string</returns>
public string GetString(int id)
{
return _stringData.GetString(id, Settings.Instance.Language);
return _stringData.GetString(id, GameGlobals.Instance.Language);
}

public string GetDescription(int id)
{
return _stringData.GetDescription(id, Settings.Instance.Language);
return _stringData.GetDescription(id, GameGlobals.Instance.Language);
}

/// <summary>
Expand All @@ -138,7 +137,7 @@ public string GetDescription(int id)
/// <param name="language">Language of string to replace.</param>
public void SetString(string str, int id)
{
var lang = Settings.Instance.Language;
var lang = GameGlobals.Instance.Language;
if (!StringData.HasLanguage(lang))
lang = Languages.USEnglish;
StringData.SetString(str, id, lang);
Expand Down
22 changes: 22 additions & 0 deletions Assets/Scripts/OpenTS2/Content/GameGlobals.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using OpenTS2.Engine;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OpenTS2.Content
{
public class GameGlobals
{
[GameProperty(true)]
public static bool allowCustomContent = true;
public static GameGlobals Instance { get; private set; }
public Languages Language = Languages.USEnglish;

public GameGlobals()
{
Instance = this;
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System.Text;
using System.Threading.Tasks;

namespace OpenTS2.Client
namespace OpenTS2.Content
{
public enum Languages : byte
{
Expand Down
3 changes: 1 addition & 2 deletions Assets/Scripts/OpenTS2/Content/Neighborhood.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using OpenTS2.Client;
using OpenTS2.Common;
using OpenTS2.Common;
using OpenTS2.Content.DBPF;
using OpenTS2.Files;
using OpenTS2.Files.Formats.DBPF;
Expand Down
2 changes: 1 addition & 1 deletion Assets/Scripts/OpenTS2/Diagnostic/EnterCASCheat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class EnterCASCheat : Cheat

public override void Execute(CheatArguments arguments, IConsoleOutput output = null)
{
CASController.Instance.EnterCAS();
CASManager.Instance.EnterCAS();
}
}
}
5 changes: 2 additions & 3 deletions Assets/Scripts/OpenTS2/Engine/Core.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.SceneManagement;
using OpenTS2.Client;
using OpenTS2.Game;
using OpenTS2.Audio;
using OpenTS2.Content.DBPF;
Expand All @@ -33,7 +32,7 @@ public static void InitializeCore()
{
if (CoreInitialized) return;

var settings = new Settings();
var gameGlobals = new GameGlobals();
var epManager = new EPManager();
var contentManager = new ContentManager();
var effectsManager = new EffectsManager();
Expand All @@ -43,7 +42,7 @@ public static void InitializeCore()
var audioManager = new AudioManager();
var objectManager = new ObjectManager();
var nhoodManager = new NeighborhoodManager();
var casController = new CASController();
var casController = new CASManager();
var lotManger = new LotManager();
var asyncContentLoader = new AsyncContentManager();

Expand Down
10 changes: 4 additions & 6 deletions Assets/Scripts/OpenTS2/Engine/Tests/UILayoutTest.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using OpenTS2.Client;
using OpenTS2.Common;
using OpenTS2.Common;
using OpenTS2.Content;
using OpenTS2.Files;
using OpenTS2.Files.Formats.DBPF;
Expand Down Expand Up @@ -35,8 +34,8 @@ void LoadBGUIPackage()

void CreateUI()
{
var settings = Settings.Instance;
settings.Language = Language;
var globals = GameGlobals.Instance;
globals.Language = Language;
foreach (var instance in _instances)
{
Destroy(instance.gameObject);
Expand Down Expand Up @@ -67,8 +66,7 @@ private void Update()

private void Start()
{
var settings = Settings.Instance;
settings.CustomContentEnabled = false;
GameGlobals.allowCustomContent = false;
if (LoadPackagesFromAllEPs)
LoadAllUIPackages();
else
Expand Down
1 change: 0 additions & 1 deletion Assets/Scripts/OpenTS2/Files/Formats/DBPF/STRCodec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
using OpenTS2.Content.DBPF;
using System.Text;
using OpenTS2.Common.Utils;
using OpenTS2.Client;

namespace OpenTS2.Files.Formats.DBPF
{
Expand Down
1 change: 0 additions & 1 deletion Assets/Scripts/OpenTS2/SimAntics/Primitives/VMLua.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System.Text;
using System.Threading.Tasks;
using MoonSharp.Interpreter;
using OpenTS2.Client;
using OpenTS2.Common;
using OpenTS2.Content;
using OpenTS2.Content.DBPF;
Expand Down
5 changes: 2 additions & 3 deletions Assets/Scripts/OpenTS2/SimAntics/VM.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using OpenTS2.Client;
using OpenTS2.Common;
using OpenTS2.Content;
using OpenTS2.Files.Formats.DBPF;
Expand Down Expand Up @@ -56,8 +55,8 @@ void InitializeGlobalState()
var epFlags2 = (short)(epManager.InstalledProducts >> 16);
SetGlobal(VMGlobals.GameEditionFlags1, epFlags1);
SetGlobal(VMGlobals.GameEditionFlags2, epFlags2);
var settings = Settings.Instance;
SetGlobal(VMGlobals.CurrentLanguage, (short)settings.Language);
var globals = GameGlobals.Instance;
SetGlobal(VMGlobals.CurrentLanguage, (short)globals.Language);
}

/// <summary>
Expand Down
1 change: 0 additions & 1 deletion Assets/Tests/OpenTS2/Content/ContentManagerTest.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using NUnit.Framework;
using OpenTS2.Client;
using OpenTS2.Common;
using OpenTS2.Content;
using OpenTS2.Content.DBPF;
Expand Down
2 changes: 1 addition & 1 deletion Assets/Tests/OpenTS2/Content/DBPF/StringSetTest.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using NUnit.Framework;
using OpenTS2.Content.DBPF;
using OpenTS2.Client;
using System.Collections.Generic;
using OpenTS2.Content;

public class StringSetTest
{
Expand Down
8 changes: 2 additions & 6 deletions Assets/Tests/TestCore.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using OpenTS2.Assemblies;
using OpenTS2.Client;
using OpenTS2.Content;
using OpenTS2.Engine;
using OpenTS2.Files;
Expand All @@ -18,11 +17,8 @@ public static class TestCore
/// </summary>
public static void Initialize()
{
var settings = new Settings()
{
CustomContentEnabled = false,
Language = Languages.USEnglish
};
var globals = new GameGlobals();
GameGlobals.allowCustomContent = false;
var epManager = new EPManager((int)ProductFlags.BaseGame);
var contentManager = new ContentManager();
var luaManager = new LuaManager();
Expand Down

0 comments on commit b82da1c

Please sign in to comment.