From 7ba11188bc1f97dd8c9efcdf242aac2426964f3b Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sun, 6 Jan 2019 00:31:40 -0500 Subject: [PATCH] migrate to new data API SMAPI 3.0 no longer allows access to arbitrary file paths through its APIs, so this commit refactors affected code to use relative paths instead. --- GeneralMods/BuildEndurance/BuildEndurance.cs | 6 +- GeneralMods/BuildHealth/BuildHealth.cs | 6 +- GeneralMods/CustomNPCFramework/Class1.cs | 59 +++++++----------- .../Framework/Graphics/AssetInfo.cs | 12 ++-- .../Framework/Graphics/AssetManager.cs | 62 +++++++------------ .../Framework/Graphics/AssetPool.cs | 2 +- .../Framework/Graphics/AssetSheet.cs | 16 ++--- .../Framework/Graphics/DirectionalTexture.cs | 15 ++--- .../Framework/Graphics/ExtendedAssetInfo.cs | 12 ++-- .../Framework/ModularNPCS/Sprite.cs | 13 +--- GeneralMods/NightOwl/NightOwl.cs | 3 +- .../SaveAnywhere/Framework/SaveManager.cs | 18 +++--- .../Framework/SoundManager.cs | 4 +- .../SimpleSoundManager/Framework/WavSound.cs | 4 +- .../Fonts/Components/CharacterSpacing.cs | 12 ---- .../Vocalization/Framework/AudioCues.cs | 5 +- .../Vocalization/Vocalization/Vocalization.cs | 33 +++++----- 17 files changed, 106 insertions(+), 176 deletions(-) diff --git a/GeneralMods/BuildEndurance/BuildEndurance.cs b/GeneralMods/BuildEndurance/BuildEndurance.cs index d826fbc4..ca94483d 100644 --- a/GeneralMods/BuildEndurance/BuildEndurance.cs +++ b/GeneralMods/BuildEndurance/BuildEndurance.cs @@ -14,7 +14,7 @@ namespace Omegasis.BuildEndurance ** Properties *********/ /// The relative path for the current player's data file. - private string DataFilePath => Path.Combine("data", $"{Constants.SaveFolderName}.json"); + private string RelativeDataPath => Path.Combine("data", $"{Constants.SaveFolderName}.json"); /// The mod settings. private ModConfig Config; @@ -124,7 +124,7 @@ namespace Omegasis.BuildEndurance this.WasEating = false; // load player data - this.PlayerData = this.Helper.ReadJsonFile(this.DataFilePath) ?? new PlayerData(); + this.PlayerData = this.Helper.Data.ReadJsonFile(this.RelativeDataPath) ?? new PlayerData(); if (this.PlayerData.OriginalMaxStamina == 0) this.PlayerData.OriginalMaxStamina = Game1.player.MaxStamina; @@ -179,7 +179,7 @@ namespace Omegasis.BuildEndurance this.PlayerData.NightlyStamina = Game1.player.MaxStamina; // save data - this.Helper.WriteJsonFile(this.DataFilePath, this.PlayerData); + this.Helper.Data.WriteJsonFile(this.RelativeDataPath, this.PlayerData); } /// Try and emulate the old Game1.shouldFarmerPassout logic. diff --git a/GeneralMods/BuildHealth/BuildHealth.cs b/GeneralMods/BuildHealth/BuildHealth.cs index bbdee068..4e994332 100644 --- a/GeneralMods/BuildHealth/BuildHealth.cs +++ b/GeneralMods/BuildHealth/BuildHealth.cs @@ -14,7 +14,7 @@ namespace Omegasis.BuildHealth ** Properties *********/ /// The relative path for the current player's data file. - private string DataFilePath => Path.Combine("data", $"{Constants.SaveFolderName}.json"); + private string RelativeDataPath => Path.Combine("data", $"{Constants.SaveFolderName}.json"); /// The mod settings and player data. private ModConfig Config; @@ -118,7 +118,7 @@ namespace Omegasis.BuildHealth this.WasCollapsed = false; // load player data - this.PlayerData = this.Helper.ReadJsonFile(this.DataFilePath) ?? new PlayerData(); + this.PlayerData = this.Helper.Data.ReadJsonFile(this.RelativeDataPath) ?? new PlayerData(); if (this.PlayerData.OriginalMaxHealth == 0) this.PlayerData.OriginalMaxHealth = Game1.player.maxHealth; @@ -169,7 +169,7 @@ namespace Omegasis.BuildHealth } // save data - this.Helper.WriteJsonFile(this.DataFilePath, this.PlayerData); + this.Helper.Data.WriteJsonFile(this.RelativeDataPath, this.PlayerData); } public bool shouldFarmerPassout() diff --git a/GeneralMods/CustomNPCFramework/Class1.cs b/GeneralMods/CustomNPCFramework/Class1.cs index 49ea38ef..0e9892fb 100644 --- a/GeneralMods/CustomNPCFramework/Class1.cs +++ b/GeneralMods/CustomNPCFramework/Class1.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Linq; using CustomNPCFramework.Framework.Enums; using CustomNPCFramework.Framework.Graphics; using CustomNPCFramework.Framework.ModularNpcs.ColorCollections; @@ -82,8 +83,8 @@ namespace CustomNPCFramework /// Initialize the asset pool with some test variables. public void initializeAssetPool() { - string path = Path.Combine(ModHelper.DirectoryPath, "Content", "Graphics", "NPCS"); - assetPool.getAssetManager("testNPC").addPathCreateDirectory(new KeyValuePair("characters", path)); + string relativePath = Path.Combine("Content", "Graphics", "NPCS"); + assetPool.getAssetManager("testNPC").addPathCreateDirectory(new KeyValuePair("characters", relativePath)); } /// A function that is called when the game finishes saving. @@ -145,52 +146,40 @@ namespace CustomNPCFramework public void initializeExamples() { return; - string dirPath = Path.Combine(ModHelper.DirectoryPath, "Content", "Templates"); + string relativeDirPath = Path.Combine("Content", "Templates"); var aManager = assetPool.getAssetManager("testNPC"); - aManager.addPathCreateDirectory(new KeyValuePair("templates", dirPath)); - string filePath = Path.Combine(dirPath, "Example.json"); - if (!File.Exists(filePath)) - { - string getRelativePath = getShortenedDirectory(filePath); - ModMonitor.Log("THIS IS THE PATH::: " + getRelativePath); - AssetInfo info = new AssetInfo("MyExample", new NamePairings("StandingExampleL", "StandingExampleR", "StandingExampleU", "StandingExampleD"), new NamePairings("MovingExampleL", "MovingExampleR", "MovingExampleU", "MovingExampleD"), new NamePairings("SwimmingExampleL", "SwimmingExampleR", "SwimmingExampleU", "SwimmingExampleD"), new NamePairings("SittingExampleL", "SittingExampleR", "SittingExampleU", "SittingExampleD"), new Vector2(16, 16), false); - info.writeToJson(filePath); + aManager.addPathCreateDirectory(new KeyValuePair("templates", relativeDirPath)); - } - string filePath2 = Path.Combine(dirPath, "AdvancedExample.json"); - if (!File.Exists(filePath2)) + // write example { + string relativeFilePath = Path.Combine(relativeDirPath, "Example.json"); + if (!File.Exists(Path.Combine(this.Helper.DirectoryPath, relativeFilePath))) + { + ModMonitor.Log("THIS IS THE PATH::: " + relativeFilePath); + AssetInfo info = new AssetInfo("MyExample", new NamePairings("StandingExampleL", "StandingExampleR", "StandingExampleU", "StandingExampleD"), new NamePairings("MovingExampleL", "MovingExampleR", "MovingExampleU", "MovingExampleD"), new NamePairings("SwimmingExampleL", "SwimmingExampleR", "SwimmingExampleU", "SwimmingExampleD"), new NamePairings("SittingExampleL", "SittingExampleR", "SittingExampleU", "SittingExampleD"), new Vector2(16, 16), false); + info.writeToJson(relativeFilePath); - ExtendedAssetInfo info2 = new ExtendedAssetInfo("AdvancedExample", new NamePairings("AdvancedStandingExampleL", "AdvancedStandingExampleR", "AdvancedStandingExampleU", "AdvancedStandingExampleD"), new NamePairings("AdvancedMovingExampleL", "AdvancedMovingExampleR", "AdvancedMovingExampleU", "AdvancedMovingExampleD"), new NamePairings("AdvancedSwimmingExampleL", "AdvancedSwimmingExampleR", "AdvancedSwimmingExampleU", "AdvancedSwimmingExampleD"), new NamePairings("AdvancedSittingExampleL", "AdvancedSittingExampleR", "AdvancedSittingExampleU", "AdvancedSittingExampleD"), new Vector2(16, 16), false, Genders.female, new List() - { - Seasons.spring, - Seasons.summer - }, PartType.hair - ); - info2.writeToJson(filePath2); + } } - } - /// Used to splice the mod directory to get relative paths. - public static string getShortenedDirectory(string path) - { - string lol = (string)path.Clone(); - string[] spliter = lol.Split(new string[] { ModHelper.DirectoryPath }, StringSplitOptions.None); - try + // write advanced example { - return spliter[1]; - } - catch - { - return spliter[0]; + string relativeFilePath = Path.Combine(relativeDirPath, "AdvancedExample.json"); + if (!File.Exists(Path.Combine(this.Helper.DirectoryPath, relativeFilePath))) + { + ExtendedAssetInfo info2 = new ExtendedAssetInfo("AdvancedExample", new NamePairings("AdvancedStandingExampleL", "AdvancedStandingExampleR", "AdvancedStandingExampleU", "AdvancedStandingExampleD"), new NamePairings("AdvancedMovingExampleL", "AdvancedMovingExampleR", "AdvancedMovingExampleU", "AdvancedMovingExampleD"), new NamePairings("AdvancedSwimmingExampleL", "AdvancedSwimmingExampleR", "AdvancedSwimmingExampleU", "AdvancedSwimmingExampleD"), new NamePairings("AdvancedSittingExampleL", "AdvancedSittingExampleR", "AdvancedSittingExampleU", "AdvancedSittingExampleD"), new Vector2(16, 16), false, Genders.female, new List() { Seasons.spring, Seasons.summer }, PartType.hair); + info2.writeToJson(relativeFilePath); + } } } /// Used to finish cleaning up absolute asset paths into a shortened relative path. public static string getRelativeDirectory(string path) { - string s = getShortenedDirectory(path); - return s.Remove(0, 1); + return path + .Split(new[] { ModHelper.DirectoryPath }, 2, StringSplitOptions.None) + .Last() + .TrimStart(Path.DirectorySeparatorChar); } } } diff --git a/GeneralMods/CustomNPCFramework/Framework/Graphics/AssetInfo.cs b/GeneralMods/CustomNPCFramework/Framework/Graphics/AssetInfo.cs index 8ad12a14..ad4ab1e2 100644 --- a/GeneralMods/CustomNPCFramework/Framework/Graphics/AssetInfo.cs +++ b/GeneralMods/CustomNPCFramework/Framework/Graphics/AssetInfo.cs @@ -49,17 +49,17 @@ namespace CustomNPCFramework.Framework.Graphics } /// Save the json to a certain location. - /// The absolute path to save. - public void writeToJson(string path) + /// The relative path to save. + public void writeToJson(string relativeFilePath) { - Class1.ModHelper.WriteJsonFile(path, this); + Class1.ModHelper.Data.WriteJsonFile(relativeFilePath, this); } /// Read the json from a certain location. - /// The absolute path to save. - public static AssetInfo readFromJson(string path) + /// The relative path to save. + public static AssetInfo readFromJson(string relativePath) { - return Class1.ModHelper.ReadJsonFile(path); + return Class1.ModHelper.Data.ReadJsonFile(relativePath); } } } diff --git a/GeneralMods/CustomNPCFramework/Framework/Graphics/AssetManager.cs b/GeneralMods/CustomNPCFramework/Framework/Graphics/AssetManager.cs index ef6fc18f..82a27c43 100644 --- a/GeneralMods/CustomNPCFramework/Framework/Graphics/AssetManager.cs +++ b/GeneralMods/CustomNPCFramework/Framework/Graphics/AssetManager.cs @@ -1,4 +1,3 @@ -using System; using System.Collections.Generic; using System.IO; using CustomNPCFramework.Framework.Enums; @@ -9,65 +8,48 @@ namespace CustomNPCFramework.Framework.Graphics public class AssetManager { /// A list of all of the assets held by this asset manager. - public List assets; + public List assets { get; } = new List(); - /// A list of all of the directories managed by this asset manager. - public Dictionary paths; - - /// Construct an instance. - public AssetManager() - { - this.assets = new List(); - this.paths = new Dictionary(); - } - - /// Construct an instance. - /// A list of all directories to be managed by the asset manager. Name, path is the key pair value. - public AssetManager(Dictionary assetsPathsToLoadFrom) - { - this.assets = new List(); - this.paths = assetsPathsToLoadFrom; - } + /// A list of directories managed by this asset manager, relative to the mod folder. + public Dictionary relativePaths { get; } = new Dictionary(); /// Default loading function from hardcoded paths. public void loadAssets() { - foreach (var path in this.paths) - this.ProcessDirectory(path.Value); + foreach (var relativePath in this.relativePaths) + this.ProcessDirectory(relativePath.Value); } /// Process all .json files in the given directory. If there are more nested directories, keep digging to find more .json files. Also allows us to specify a broader directory like Content/Grahphics/ModularNPC/Hair to have multiple hair styles. - /// The absolute directory path to process. + /// The relative directory path to process. /// Taken from Microsoft c# documented webpages. - private void ProcessDirectory(string targetDirectory) + private void ProcessDirectory(string relativeDirPath) { - // Process the list of files found in the directory. - string[] files = Directory.GetFiles(targetDirectory, "*.json"); - foreach (string file in files) - this.ProcessFile(file, targetDirectory); + DirectoryInfo root = new DirectoryInfo(Path.Combine(Class1.ModHelper.DirectoryPath, relativeDirPath)); + foreach (FileInfo file in root.GetFiles("*.json")) + this.ProcessFile(Path.Combine(relativeDirPath, file.Name), relativeDirPath); // Recurse into subdirectories of this directory. - string[] subdirectoryEntries = Directory.GetDirectories(targetDirectory); - foreach (string subdirectory in subdirectoryEntries) - this.ProcessDirectory(subdirectory); + foreach (DirectoryInfo subdir in root.GetDirectories()) + this.ProcessDirectory(Path.Combine(relativeDirPath, subdir.Name)); } /// Actually load in the asset information. - /// The absolute file path to process. - /// The absolute directory path containing the file. - private void ProcessFile(string file, string path) + /// The relative path to the file to process. + /// The relative path containing the file. + private void ProcessFile(string relativeFilePath, string relativeDirPath) { try { - ExtendedAssetInfo info = ExtendedAssetInfo.readFromJson(file); - AssetSheet sheet = new AssetSheet(info, path); + ExtendedAssetInfo info = ExtendedAssetInfo.readFromJson(relativeFilePath); + AssetSheet sheet = new AssetSheet(info, relativeDirPath); this.addAsset(sheet); Class1.ModMonitor.Log("Loaded in new modular asset: " + info.assetName + " asset type: " + info.type); } catch { - AssetInfo info = AssetInfo.readFromJson(file); - AssetSheet sheet = new AssetSheet(info, path); + AssetInfo info = AssetInfo.readFromJson(relativeFilePath); + AssetSheet sheet = new AssetSheet(info, relativeDirPath); this.addAsset(sheet); } } @@ -102,16 +84,16 @@ namespace CustomNPCFramework.Framework.Graphics } /// Add a path to the dictionary. - /// The absolute path to add. + /// The relative path to add. private void addPath(KeyValuePair path) { - this.paths.Add(path.Key, path.Value); + this.relativePaths.Add(path.Key, path.Value); } /// Create appropriate directories for the path. private void createDirectoriesFromPaths() { - foreach (var v in this.paths) + foreach (var v in this.relativePaths) Directory.CreateDirectory(Path.Combine(Class1.ModHelper.DirectoryPath, v.Value)); } diff --git a/GeneralMods/CustomNPCFramework/Framework/Graphics/AssetPool.cs b/GeneralMods/CustomNPCFramework/Framework/Graphics/AssetPool.cs index caf97e00..0361206c 100644 --- a/GeneralMods/CustomNPCFramework/Framework/Graphics/AssetPool.cs +++ b/GeneralMods/CustomNPCFramework/Framework/Graphics/AssetPool.cs @@ -351,7 +351,7 @@ namespace CustomNPCFramework.Framework.Graphics return new StandardCharacterAnimation(bodySprite, eyesSprite, hairSprite, shirtSprite, pantsSprite, shoesSprite, accessoryCollection, drawColors); } - /// Get the string for the standard character sprite to be used from this asset sheet. + /// Get the relative path for the standard character sprite to be used from this asset sheet. /// The standard asset sheet to be used. public virtual string getDefaultSpriteImage(AssetSheet imageGraphics) { diff --git a/GeneralMods/CustomNPCFramework/Framework/Graphics/AssetSheet.cs b/GeneralMods/CustomNPCFramework/Framework/Graphics/AssetSheet.cs index d868de75..93126765 100644 --- a/GeneralMods/CustomNPCFramework/Framework/Graphics/AssetSheet.cs +++ b/GeneralMods/CustomNPCFramework/Framework/Graphics/AssetSheet.cs @@ -25,21 +25,13 @@ namespace CustomNPCFramework.Framework.Graphics /// Construct an instance. /// The asset info file to be read in or created. Holds path information. - /// The path to the assetinfo file. + /// The relative path to the assetinfo file. /// The direction to set the animation. - public AssetSheet(AssetInfo info, string path, Direction direction = Direction.down) + public AssetSheet(AssetInfo info, string relativeDirPath, Direction direction = Direction.down) { this.assetInfo = info; - this.textures = new TextureGroup(info, path, direction); - try - { - this.path = Class1.getShortenedDirectory(path); - } - catch - { - this.path = path; - } - + this.textures = new TextureGroup(info, relativeDirPath, direction); + this.path = relativeDirPath; this.index = 0; } diff --git a/GeneralMods/CustomNPCFramework/Framework/Graphics/DirectionalTexture.cs b/GeneralMods/CustomNPCFramework/Framework/Graphics/DirectionalTexture.cs index 524dd53b..2834ea98 100644 --- a/GeneralMods/CustomNPCFramework/Framework/Graphics/DirectionalTexture.cs +++ b/GeneralMods/CustomNPCFramework/Framework/Graphics/DirectionalTexture.cs @@ -56,17 +56,12 @@ namespace CustomNPCFramework.Framework.Graphics } } - public DirectionalTexture(IModHelper helper, NamePairings info, string path, Direction direction = Direction.down) + public DirectionalTexture(IModHelper helper, NamePairings info, string relativePath, Direction direction = Direction.down) { - string leftString = Class1.getShortenedDirectory(Path.Combine(path, info.leftString + ".png")).Remove(0, 1); - string rightString = Class1.getShortenedDirectory(Path.Combine(path, info.rightString + ".png")).Remove(0, 1); - string upString = Class1.getShortenedDirectory(Path.Combine(path, info.upString + ".png")).Remove(0, 1); - string downString = Class1.getShortenedDirectory(Path.Combine(path, info.downString + ".png")).Remove(0, 1); - - this.leftTexture = new Texture2DExtended(helper, leftString); - this.rightTexture = new Texture2DExtended(helper, rightString); - this.upTexture = new Texture2DExtended(helper, upString); - this.downTexture = new Texture2DExtended(helper, downString); + this.leftTexture = new Texture2DExtended(helper, Path.Combine(relativePath, $"{info.leftString}.png")); + this.rightTexture = new Texture2DExtended(helper, Path.Combine(relativePath, $"{info.rightString}.png")); + this.upTexture = new Texture2DExtended(helper, Path.Combine(relativePath, $"{info.upString}.png")); + this.downTexture = new Texture2DExtended(helper, Path.Combine(relativePath, $"{info.downString}.png")); switch (direction) { diff --git a/GeneralMods/CustomNPCFramework/Framework/Graphics/ExtendedAssetInfo.cs b/GeneralMods/CustomNPCFramework/Framework/Graphics/ExtendedAssetInfo.cs index 41745722..58d020d5 100644 --- a/GeneralMods/CustomNPCFramework/Framework/Graphics/ExtendedAssetInfo.cs +++ b/GeneralMods/CustomNPCFramework/Framework/Graphics/ExtendedAssetInfo.cs @@ -39,17 +39,17 @@ namespace CustomNPCFramework.Framework.Graphics } /// Save the json to a certain location. - /// The absolute path to write. - public new void writeToJson(string path) + /// The relative path to write. + public new void writeToJson(string relativePath) { - Class1.ModHelper.WriteJsonFile(path, this); + Class1.ModHelper.Data.WriteJsonFile(relativePath, this); } /// Read the json from a certain location. - /// The absolute path to read. - public new static ExtendedAssetInfo readFromJson(string path) + /// The relative path to read. + public new static ExtendedAssetInfo readFromJson(string relativePath) { - return Class1.ModHelper.ReadJsonFile(path); + return Class1.ModHelper.Data.ReadJsonFile(relativePath); } } } diff --git a/GeneralMods/CustomNPCFramework/Framework/ModularNPCS/Sprite.cs b/GeneralMods/CustomNPCFramework/Framework/ModularNPCS/Sprite.cs index 2a02bbff..0ee288e4 100644 --- a/GeneralMods/CustomNPCFramework/Framework/ModularNPCS/Sprite.cs +++ b/GeneralMods/CustomNPCFramework/Framework/ModularNPCS/Sprite.cs @@ -14,17 +14,10 @@ namespace CustomNPCFramework.Framework.ModularNpcs public string relativePath; /// Construct an instance. - /// The full path to the file. - public Sprite(string path) + /// The relative path to the file. + public Sprite(string relativePath) { - try - { - this.relativePath = Class1.getShortenedDirectory(path); - } - catch - { - this.relativePath = path; - } + this.relativePath = relativePath; try { this.sprite = new AnimatedSprite(); diff --git a/GeneralMods/NightOwl/NightOwl.cs b/GeneralMods/NightOwl/NightOwl.cs index 41b37fbb..05724888 100644 --- a/GeneralMods/NightOwl/NightOwl.cs +++ b/GeneralMods/NightOwl/NightOwl.cs @@ -353,8 +353,7 @@ namespace Omegasis.NightOwl this.PreCollapseStamina, this.PreCollapseHealth }; - string path = Path.Combine(this.Helper.DirectoryPath, "Error_Logs", "Mod_State.json"); - this.Helper.WriteJsonFile(path, state); + this.Helper.Data.WriteJsonFile("Error_Logs/Mod_State.json", state); } /// Try and emulate the old Game1.shouldFarmerPassout logic. diff --git a/GeneralMods/SaveAnywhere/Framework/SaveManager.cs b/GeneralMods/SaveAnywhere/Framework/SaveManager.cs index 96789e17..94c6e52e 100644 --- a/GeneralMods/SaveAnywhere/Framework/SaveManager.cs +++ b/GeneralMods/SaveAnywhere/Framework/SaveManager.cs @@ -26,8 +26,8 @@ namespace Omegasis.SaveAnywhere.Framework /// SMAPI's APIs for this mod. private readonly IModHelper Helper; - /// The full path to the player data file. - private string SavePath => Path.Combine(this.Helper.DirectoryPath, "data", $"{Constants.SaveFolderName}.json"); + /// The relative path to the player data file. + private string RelativeDataPath => Path.Combine("data", $"{Constants.SaveFolderName}.json"); /// Whether we should save at the next opportunity. private bool WaitingToSave; @@ -80,7 +80,7 @@ namespace Omegasis.SaveAnywhere.Framework /// Clear saved data. public void ClearData() { - File.Delete(this.SavePath); + File.Delete(Path.Combine(this.Helper.DirectoryPath, this.RelativeDataPath)); this.RemoveLegacyDataForThisPlayer(); } @@ -105,20 +105,16 @@ namespace Omegasis.SaveAnywhere.Framework } - // get data + // save data to disk PlayerData data = new PlayerData { Time = Game1.timeOfDay, Characters = this.GetPositions().ToArray(), IsCharacterSwimming = Game1.player.swimming.Value }; + this.Helper.Data.WriteJsonFile(this.RelativeDataPath, data); - // save to disk - // ReSharper disable once PossibleNullReferenceException -- not applicable - Directory.CreateDirectory(new FileInfo(this.SavePath).Directory.FullName); - this.Helper.WriteJsonFile(this.SavePath, data); - - // clear any legacy data (no longer needed as backup)1 + // clear any legacy data (no longer needed as backup) this.RemoveLegacyDataForThisPlayer(); } @@ -126,7 +122,7 @@ namespace Omegasis.SaveAnywhere.Framework public void LoadData() { // get data - PlayerData data = this.Helper.ReadJsonFile(this.SavePath); + PlayerData data = this.Helper.Data.ReadJsonFile(this.RelativeDataPath); if (data == null) return; diff --git a/GeneralMods/SimpleSoundManager/Framework/SoundManager.cs b/GeneralMods/SimpleSoundManager/Framework/SoundManager.cs index 617baa6e..7d19f501 100644 --- a/GeneralMods/SimpleSoundManager/Framework/SoundManager.cs +++ b/GeneralMods/SimpleSoundManager/Framework/SoundManager.cs @@ -36,9 +36,9 @@ namespace SimpleSoundManager.Framework } /// Constructor for wav files. - public void loadWavFile(IModHelper helper, string soundName, string pathToWav) + public void loadWavFile(IModHelper helper, string soundName, string relativePath) { - WavSound wav = new WavSound(helper, soundName, pathToWav); + WavSound wav = new WavSound(helper, soundName, relativePath); SimpleSoundManagerMod.ModMonitor.Log("Getting sound file:" + soundName); try { diff --git a/GeneralMods/SimpleSoundManager/Framework/WavSound.cs b/GeneralMods/SimpleSoundManager/Framework/WavSound.cs index 923248e4..4c31fdf2 100644 --- a/GeneralMods/SimpleSoundManager/Framework/WavSound.cs +++ b/GeneralMods/SimpleSoundManager/Framework/WavSound.cs @@ -37,9 +37,9 @@ namespace SimpleSoundManager } /// A constructor that takes a mod helper and a relative path to a wav file. - public WavSound(IModHelper modHelper, string name, string pathInModDirectory, bool loop = false) + public WavSound(IModHelper modHelper, string name, string relativePath, bool loop = false) { - string path = Path.Combine(modHelper.DirectoryPath, pathInModDirectory); + string path = Path.Combine(modHelper.DirectoryPath, relativePath); this.path = path; this.soundName = name; this.loop = loop; diff --git a/GeneralMods/StardustCore/UIUtilities/SpriteFonts/Fonts/Components/CharacterSpacing.cs b/GeneralMods/StardustCore/UIUtilities/SpriteFonts/Fonts/Components/CharacterSpacing.cs index c2b8f057..e1ae369c 100644 --- a/GeneralMods/StardustCore/UIUtilities/SpriteFonts/Fonts/Components/CharacterSpacing.cs +++ b/GeneralMods/StardustCore/UIUtilities/SpriteFonts/Fonts/Components/CharacterSpacing.cs @@ -26,17 +26,5 @@ namespace StardustCore.UIUtilities.SpriteFonts.Components this.TopPadding = top; this.BottomPadding = bottom; } - - /// Save this to a .json file. - public void WriteToJson(string path) - { - StardustCore.ModCore.ModHelper.WriteJsonFile(path, this); - } - - /// Read the data from the .json file. - public static CharacterSpacing ReadFromJson(string path) - { - return StardustCore.ModCore.ModHelper.ReadJsonFile(path); - } } } diff --git a/GeneralMods/Vocalization/Vocalization/Framework/AudioCues.cs b/GeneralMods/Vocalization/Vocalization/Framework/AudioCues.cs index 95a42c60..b2edff66 100644 --- a/GeneralMods/Vocalization/Vocalization/Framework/AudioCues.cs +++ b/GeneralMods/Vocalization/Vocalization/Framework/AudioCues.cs @@ -44,8 +44,7 @@ namespace Vocalization.Framework { foreach (LanguageName language in Vocalization.config.translationInfo.LanguageNames) { - var loaded = - Vocalization.ModHelper.ReadJsonFile>(Path.Combine(Vocalization.ModHelper.DirectoryPath, "AudioCues", "AudioCues" + Seperator + language + ".json")) + var loaded = Vocalization.ModHelper.Data.ReadJsonFile>($"AudioCues/AudioCues{Seperator}{language}.json") ?? new SortedDictionary(); DictionaryReferences.Add(Vocalization.config.translationInfo.getTranslationName(language), loaded); } @@ -54,7 +53,7 @@ namespace Vocalization.Framework public static void saveAudioCues() { foreach (var v in DictionaryReferences) - Vocalization.ModHelper.WriteJsonFile>(Path.Combine(Vocalization.ModHelper.DirectoryPath, "AudioCues", "AudioCues" + Seperator + v.Key + ".json"), v.Value); + Vocalization.ModHelper.Data.WriteJsonFile($"AudioCues/AudioCues{Seperator}{v.Key}.json", v.Value); } } } diff --git a/GeneralMods/Vocalization/Vocalization/Vocalization.cs b/GeneralMods/Vocalization/Vocalization/Vocalization.cs index b5428f5d..db3fd619 100644 --- a/GeneralMods/Vocalization/Vocalization/Vocalization.cs +++ b/GeneralMods/Vocalization/Vocalization/Vocalization.cs @@ -609,38 +609,35 @@ namespace Vocalization { foreach (LanguageName language in config.translationInfo.LanguageNames) { + string relativeLanguagePath = Path.Combine(RelativeVoicePath, language.ToString()); + // check if mod supports language - DirectoryInfo languageDir = new DirectoryInfo(Path.Combine(ModHelper.DirectoryPath, RelativeVoicePath, language.ToString())); + DirectoryInfo languageDir = new DirectoryInfo(Path.Combine(ModHelper.DirectoryPath, relativeLanguagePath)); if (!languageDir.Exists) return; // get characters supported in this translation and load their voice cue file - foreach (string dir in Directory.GetDirectories(languageDir.FullName)) + foreach (DirectoryInfo subdir in languageDir.GetDirectories()) { - ModMonitor.Log(dir); - - string[] clips = Directory.GetFiles(dir, "*.wav"); + string characterName = subdir.Name; + string relativeCuePath = Path.Combine(relativeLanguagePath, subdir.Name, "VoiceCues.json"); // dialogue cues (aka when the character should "speak") //For every .wav file in every character voice clip directory load in the voice clip. - foreach (string file in clips) + foreach (FileInfo file in subdir.GetFiles("*.wav")) { - string fileName = Path.GetFileNameWithoutExtension(file); - soundManager.loadWavFile(ModHelper, fileName, file); - ModMonitor.Log("Loaded sound file: " + fileName + " from: " + file); + string fileName = Path.GetFileNameWithoutExtension(file.Name); + soundManager.loadWavFile(ModHelper, fileName, file.FullName); + ModMonitor.Log($"Loaded sound file: {fileName} from: {file.FullName}"); } - //Get the character dialogue cues (aka when the character should "speak") from the .json file. - string voiceCueFile = Path.Combine(dir, "VoiceCues.json"); - string characterName = Path.GetFileName(dir); - //If a file was not found, create one and add it to the list of character voice cues. //I have to scrape all files if they don't exist so that way all options are available for release. - if (!File.Exists(voiceCueFile)) + if (!File.Exists(Path.Combine(ModHelper.DirectoryPath, relativeCuePath))) { CharacterVoiceCue cue = new CharacterVoiceCue(characterName); cue.initializeEnglishScrape(); cue.initializeForTranslation(language); - scrapeDictionaries(voiceCueFile, cue, language, languageDir); + scrapeDictionaries(relativeCuePath, cue, language, languageDir); try { if (language == config.translationInfo.CurrentTranslation) @@ -655,7 +652,7 @@ namespace Vocalization //Only load in the cues for the current translation. if (language == config.translationInfo.CurrentTranslation) { - CharacterVoiceCue cue = ModHelper.ReadJsonFile(voiceCueFile); + CharacterVoiceCue cue = ModHelper.Data.ReadJsonFile(relativeCuePath); //scrapeDictionaries(voiceCueFile,cue); DialogueCues.Add(characterName, cue); } @@ -670,7 +667,7 @@ namespace Vocalization } /// Used to obtain all strings for almost all possible dialogue in the game. - public static void scrapeDictionaries(string cuePath, CharacterVoiceCue cue, LanguageName language, DirectoryInfo languageDir) + public static void scrapeDictionaries(string relativeCuePath, CharacterVoiceCue cue, LanguageName language, DirectoryInfo languageDir) { string dialoguePath = Path.Combine("Characters", "Dialogue"); string stringsPath = Path.Combine("Strings"); //Used for all sorts of extra strings and stuff for like StringsFromCS @@ -2860,7 +2857,7 @@ namespace Vocalization } } - ModHelper.WriteJsonFile(cuePath, cue); + ModHelper.Data.WriteJsonFile(relativeCuePath, cue); //DialogueCues.Add(cue.name, cue); }