Skip to content

Commit 790a64d

Browse files
committed
Refactor Filesystem, get rid of JSONPathProvider
1 parent 241ea9e commit 790a64d

20 files changed

+125
-239
lines changed

Assets/Editor/OpenTS2/Engine/Tests/LotLoadingTestEditor.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ private void PopulateNhoodList()
2828
{
2929
NhoodNames.Clear();
3030

31-
var nhoodFolderPath = Path.Combine(Filesystem.GetUserPath(), $"Neighborhoods");
31+
var nhoodFolderPath = Path.Combine(Filesystem.UserDataDirectory, $"Neighborhoods");
3232

3333
foreach (var nhood in Directory.GetDirectories(nhoodFolderPath))
3434
{
@@ -44,7 +44,7 @@ private void PopulateNhoodList()
4444
private void PopulateLotList(string nhood)
4545
{
4646
_cachedNhood = nhood;
47-
var lotsFolderPath = Path.Combine(Filesystem.GetUserPath(), $"Neighborhoods/{nhood}/Lots");
47+
var lotsFolderPath = Path.Combine(Filesystem.UserDataDirectory, $"Neighborhoods/{nhood}/Lots");
4848

4949
LotIds.Clear();
5050

Assets/Editor/OpenTS2/SPXConverter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ private static void ConvertSPX()
3333
if (baseGameOnly)
3434
EPManager.Instance.InstalledProducts = (int)ProductFlags.BaseGame;
3535
var epManager = EPManager.Instance;
36-
var products = epManager.GetInstalledProducts();
36+
var products = Filesystem.GetProductDirectories();
3737
var contentManager = ContentManager.Instance;
3838

3939
foreach (var product in products)
4040
{
41-
var packages = Filesystem.GetPackagesInDirectory(Path.Combine(Filesystem.GetDataPathForProduct(product), "Res/Sound"));
41+
var packages = Filesystem.GetPackagesInDirectory(Path.Combine(product, "TSData/Res/Sound"));
4242
contentManager.AddPackages(packages);
4343
}
4444

Assets/Scripts/OpenTS2/Audio/AudioManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ private void OnFinishedLoading()
5757
private void LoadCustomMusic()
5858
{
5959
CustomSongNames = new Dictionary<ResourceKey, string>();
60-
var musicDir = Path.Combine(Filesystem.GetUserPath(), "Music");
60+
var musicDir = Path.Combine(Filesystem.UserDataDirectory, "Music");
6161
var stationDirs = Directory.GetDirectories(musicDir);
6262
foreach(var stationDir in stationDirs)
6363
{

Assets/Scripts/OpenTS2/Audio/MusicManager.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,11 @@ private void LocalizeMusicCategories(List<ResourceKey> musicTitles)
141141

142142
private void LoadIniMusicCategories()
143143
{
144-
var epManager = EPManager.Instance;
145-
var products = epManager.GetInstalledProducts();
144+
var products = Filesystem.GetProductDirectories();
146145
foreach(var product in products)
147146
{
148-
var sysFolder = Path.Combine(Filesystem.GetDataPathForProduct(product), "Sys");
147+
var sysFolder = Path.Combine(product, "TSData/Sys");
148+
if (!Directory.Exists(sysFolder)) continue;
149149
var unpackedAudioIni = Directory.GetFiles(sysFolder, "TSAudioUnpacked*.ini", SearchOption.TopDirectoryOnly).FirstOrDefault();
150150
if (!string.IsNullOrEmpty(unpackedAudioIni))
151151
{

Assets/Scripts/OpenTS2/Content/ContentManager.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public ContentManager()
4242

4343
public void MapFileToResource(string path, ResourceKey key)
4444
{
45-
_fileMap[key] = Filesystem.GetRealPath(path);
45+
_fileMap[key] = FileUtils.CleanPath(path);
4646
var entry = new DBPFEntry();
4747
entry.TGI = key;
4848
ResourceMap[key] = entry;
@@ -217,7 +217,7 @@ await Task.WhenAll(tasks).ContinueWith((task) =>
217217
/// <returns>Package.</returns>
218218
public DBPFFile AddPackage(string path)
219219
{
220-
path = Filesystem.GetRealPath(path);
220+
path = FileUtils.CleanPath(path);
221221
if (_entryByPath.ContainsKey(path))
222222
return _entryByPath[path];
223223
var package = new DBPFFile(path);
@@ -436,7 +436,7 @@ public DBPFFile GetPackageByGroup(string groupName)
436436
/// <returns>Content entry for package.</returns>
437437
public DBPFFile GetPackageByPath(string path)
438438
{
439-
path = Filesystem.GetRealPath(path);
439+
path = FileUtils.CleanPath(path);
440440
if (_entryByPath.ContainsKey(path))
441441
return _entryByPath[path];
442442
else

Assets/Scripts/OpenTS2/Content/EffectsManager.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ public void Initialize()
2828
{
2929
// Load effects package.
3030
_manager.AddPackages(
31-
Filesystem.GetPackagesInDirectory(Filesystem.GetDataPathForProduct(ProductFlags.BaseGame) +
32-
"/Res/Effects"));
31+
Filesystem.GetPackagesInDirectory(Filesystem.GetPathForProduct(ProductFlags.BaseGame) +
32+
"TSData/Res/Effects"));
3333
_effects = _manager.GetAsset<EffectsAsset>(new ResourceKey(instanceID: 1, groupID: GroupIDs.Effects,
3434
typeID: TypeIDs.EFFECTS));
3535

Assets/Scripts/OpenTS2/Engine/Core.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public static void InitializeCore()
4747

4848
TerrainManager.Initialize();
4949
MaterialManager.Initialize();
50-
Filesystem.Initialize(new JSONPathManager(), epManager);
50+
Filesystem.InitializeFromJSON("config.json");
5151
CodecAttribute.Initialize();
5252
CheatSystem.Initialize();
5353
VMPrimitiveRegistry.Initialize();

Assets/Scripts/OpenTS2/Engine/JSONPathProvider.cs

Lines changed: 0 additions & 59 deletions
This file was deleted.

Assets/Scripts/OpenTS2/Engine/JSONPathProvider.cs.meta

Lines changed: 0 additions & 11 deletions
This file was deleted.

Assets/Scripts/OpenTS2/Engine/Tests/EffectsTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ private void Start()
1212

1313
// Load base game assets.
1414
contentManager.AddPackages(
15-
Filesystem.GetPackagesInDirectory(Filesystem.GetDataPathForProduct(ProductFlags.BaseGame) + "/Res/Sims3D"));
15+
Filesystem.GetPackagesInDirectory(Filesystem.GetPathForProduct(ProductFlags.BaseGame) + "TSData/Res/Sims3D"));
1616

1717
// Initialize effects manager manually since we aren't using startup controller.
1818
EffectsManager.Instance.Initialize();

Assets/Scripts/OpenTS2/Engine/Tests/LotImposterGMDCTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class LotImposterGMDCTest : MonoBehaviour
1717
private void Start()
1818
{
1919
var contentManager = ContentManager.Instance;
20-
var lotsFolderPath = Path.Combine(Filesystem.GetUserPath(), $"Neighborhoods/{NeighborhoodPrefix}/Lots");
20+
var lotsFolderPath = Path.Combine(Filesystem.UserDataDirectory, $"Neighborhoods/{NeighborhoodPrefix}/Lots");
2121
var lotFilename = $"{NeighborhoodPrefix}_Lot{LotID}.package";
2222
var lotFullPath = Path.Combine(lotsFolderPath, lotFilename);
2323
contentManager.AddPackage(lotFullPath);

Assets/Scripts/OpenTS2/Engine/Tests/LotLoadingTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ private void LoadLot(string neighborhoodPrefix, int id)
120120

121121
var contentManager = ContentManager.Instance;
122122

123-
var lotsFolderPath = Path.Combine(Filesystem.GetUserPath(), $"Neighborhoods/{NeighborhoodPrefix}/Lots");
123+
var lotsFolderPath = Path.Combine(Filesystem.UserDataDirectory, $"Neighborhoods/{NeighborhoodPrefix}/Lots");
124124
var lotFilename = $"{NeighborhoodPrefix}_Lot{LotID}.package";
125125
var lotFullPath = Path.Combine(lotsFolderPath, lotFilename);
126126

Assets/Scripts/OpenTS2/Engine/Tests/LuaTestController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ void Start()
4040

4141
if (DumpLuaScripts)
4242
{
43-
var objectScriptsPath = Filesystem.GetLatestFilePath("Res/ObjectScripts/ObjectScripts.package");
43+
var objectScriptsPath = Filesystem.GetLatestFilePath("TSData/Res/ObjectScripts/ObjectScripts.package");
4444
var objectScriptsFile = new DBPFFile(objectScriptsPath);
4545

4646
foreach(var entry in objectScriptsFile.Entries)

Assets/Scripts/OpenTS2/Engine/Tests/ReiaTest.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,14 @@ public class ReiaTest : MonoBehaviour
2929

3030
private void Start()
3131
{
32-
var realPath = Filesystem.GetRealPath(reiaPath);
33-
var streamFs = File.OpenRead(realPath);
32+
var streamFs = File.OpenRead(reiaPath);
3433
reia = ReiaFile.Read(streamFs, stream);
3534
}
3635

3736
void Reload()
3837
{
3938
reia.Dispose();
40-
var realPath = Filesystem.GetRealPath(reiaPath);
41-
var streamFs = File.OpenRead(realPath);
39+
var streamFs = File.OpenRead(reiaPath);
4240
reia = ReiaFile.Read(streamFs, stream);
4341
reload = false;
4442
frameCounter = 0f;

Assets/Scripts/OpenTS2/Engine/Tests/ScenegraphGMDCTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ private void Start()
1414

1515
// Load base game assets.
1616
contentManager.AddPackages(
17-
Filesystem.GetPackagesInDirectory(Filesystem.GetDataPathForProduct(ProductFlags.BaseGame) + "/Res/Sims3D"));
17+
Filesystem.GetPackagesInDirectory(Filesystem.GetPathForProduct(ProductFlags.BaseGame) + "TSData/Res/Sims3D"));
1818

1919
//var resourceName = "vehiclePizza_cres";
2020
var resourceName = "chairReclinerPuffy_cres";

Assets/Scripts/OpenTS2/Engine/Tests/SimAnimationTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ private void Start()
2828

2929
// Load base game assets.
3030
contentManager.AddPackages(
31-
Filesystem.GetPackagesInDirectory(Filesystem.GetDataPathForProduct(ProductFlags.BaseGame) +
32-
"/Res/Sims3D"));
31+
Filesystem.GetPackagesInDirectory(Filesystem.GetPathForProduct(ProductFlags.BaseGame) +
32+
"TSData/Res/Sims3D"));
3333

3434
// Load all animations involving auskel and put them in the dictionary.
3535
foreach (var animationAsset in contentManager.GetAssetsOfType<ScenegraphAnimationAsset>(TypeIDs.SCENEGRAPH_ANIM))

0 commit comments

Comments
 (0)