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.
This commit is contained in:
Jesse Plamondon-Willard 2019-01-06 00:31:40 -05:00
parent cfe5cdc49e
commit 7ba11188bc
No known key found for this signature in database
GPG Key ID: 7D7C8097B62033CE
17 changed files with 106 additions and 176 deletions

View File

@ -14,7 +14,7 @@ namespace Omegasis.BuildEndurance
** Properties
*********/
/// <summary>The relative path for the current player's data file.</summary>
private string DataFilePath => Path.Combine("data", $"{Constants.SaveFolderName}.json");
private string RelativeDataPath => Path.Combine("data", $"{Constants.SaveFolderName}.json");
/// <summary>The mod settings.</summary>
private ModConfig Config;
@ -124,7 +124,7 @@ namespace Omegasis.BuildEndurance
this.WasEating = false;
// load player data
this.PlayerData = this.Helper.ReadJsonFile<PlayerData>(this.DataFilePath) ?? new PlayerData();
this.PlayerData = this.Helper.Data.ReadJsonFile<PlayerData>(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);
}
/// <summary>Try and emulate the old Game1.shouldFarmerPassout logic.</summary>

View File

@ -14,7 +14,7 @@ namespace Omegasis.BuildHealth
** Properties
*********/
/// <summary>The relative path for the current player's data file.</summary>
private string DataFilePath => Path.Combine("data", $"{Constants.SaveFolderName}.json");
private string RelativeDataPath => Path.Combine("data", $"{Constants.SaveFolderName}.json");
/// <summary>The mod settings and player data.</summary>
private ModConfig Config;
@ -118,7 +118,7 @@ namespace Omegasis.BuildHealth
this.WasCollapsed = false;
// load player data
this.PlayerData = this.Helper.ReadJsonFile<PlayerData>(this.DataFilePath) ?? new PlayerData();
this.PlayerData = this.Helper.Data.ReadJsonFile<PlayerData>(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()

View File

@ -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
/// <summary>Initialize the asset pool with some test variables.</summary>
public void initializeAssetPool()
{
string path = Path.Combine(ModHelper.DirectoryPath, "Content", "Graphics", "NPCS");
assetPool.getAssetManager("testNPC").addPathCreateDirectory(new KeyValuePair<string, string>("characters", path));
string relativePath = Path.Combine("Content", "Graphics", "NPCS");
assetPool.getAssetManager("testNPC").addPathCreateDirectory(new KeyValuePair<string, string>("characters", relativePath));
}
/// <summary>A function that is called when the game finishes saving.</summary>
@ -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<string, string>("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<string, string>("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>()
{
Seasons.spring,
Seasons.summer
}, PartType.hair
);
info2.writeToJson(filePath2);
}
}
}
/// <summary>Used to splice the mod directory to get relative paths.</summary>
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>() { Seasons.spring, Seasons.summer }, PartType.hair);
info2.writeToJson(relativeFilePath);
}
}
}
/// <summary>Used to finish cleaning up absolute asset paths into a shortened relative path.</summary>
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);
}
}
}

View File

@ -49,17 +49,17 @@ namespace CustomNPCFramework.Framework.Graphics
}
/// <summary>Save the json to a certain location.</summary>
/// <param name="path">The absolute path to save.</param>
public void writeToJson(string path)
/// <param name="relativeFilePath">The relative path to save.</param>
public void writeToJson(string relativeFilePath)
{
Class1.ModHelper.WriteJsonFile<AssetInfo>(path, this);
Class1.ModHelper.Data.WriteJsonFile(relativeFilePath, this);
}
/// <summary>Read the json from a certain location.</summary>
/// <param name="path">The absolute path to save.</param>
public static AssetInfo readFromJson(string path)
/// <param name="relativePath">The relative path to save.</param>
public static AssetInfo readFromJson(string relativePath)
{
return Class1.ModHelper.ReadJsonFile<AssetInfo>(path);
return Class1.ModHelper.Data.ReadJsonFile<AssetInfo>(relativePath);
}
}
}

View File

@ -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
{
/// <summary>A list of all of the assets held by this asset manager.</summary>
public List<AssetSheet> assets;
public List<AssetSheet> assets { get; } = new List<AssetSheet>();
/// <summary>A list of all of the directories managed by this asset manager.</summary>
public Dictionary<string, string> paths;
/// <summary>Construct an instance.</summary>
public AssetManager()
{
this.assets = new List<AssetSheet>();
this.paths = new Dictionary<string, string>();
}
/// <summary>Construct an instance.</summary>
/// <param name="assetsPathsToLoadFrom">A list of all directories to be managed by the asset manager. Name, path is the key pair value.</param>
public AssetManager(Dictionary<string, string> assetsPathsToLoadFrom)
{
this.assets = new List<AssetSheet>();
this.paths = assetsPathsToLoadFrom;
}
/// <summary>A list of directories managed by this asset manager, relative to the mod folder.</summary>
public Dictionary<string, string> relativePaths { get; } = new Dictionary<string, string>();
/// <summary>Default loading function from hardcoded paths.</summary>
public void loadAssets()
{
foreach (var path in this.paths)
this.ProcessDirectory(path.Value);
foreach (var relativePath in this.relativePaths)
this.ProcessDirectory(relativePath.Value);
}
/// <summary>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.</summary>
/// <param name="targetDirectory">The absolute directory path to process.</param>
/// <param name="relativeDirPath">The relative directory path to process.</param>
/// <remarks>Taken from Microsoft c# documented webpages.</remarks>
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));
}
/// <summary>Actually load in the asset information.</summary>
/// <param name="file">The absolute file path to process.</param>
/// <param name="path">The absolute directory path containing the file.</param>
private void ProcessFile(string file, string path)
/// <param name="relativeFilePath">The relative path to the file to process.</param>
/// <param name="relativeDirPath">The relative path containing the file.</param>
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
}
/// <summary>Add a path to the dictionary.</summary>
/// <param name="path">The absolute path to add.</param>
/// <param name="path">The relative path to add.</param>
private void addPath(KeyValuePair<string, string> path)
{
this.paths.Add(path.Key, path.Value);
this.relativePaths.Add(path.Key, path.Value);
}
/// <summary>Create appropriate directories for the path.</summary>
private void createDirectoriesFromPaths()
{
foreach (var v in this.paths)
foreach (var v in this.relativePaths)
Directory.CreateDirectory(Path.Combine(Class1.ModHelper.DirectoryPath, v.Value));
}

View File

@ -351,7 +351,7 @@ namespace CustomNPCFramework.Framework.Graphics
return new StandardCharacterAnimation(bodySprite, eyesSprite, hairSprite, shirtSprite, pantsSprite, shoesSprite, accessoryCollection, drawColors);
}
/// <summary>Get the string for the standard character sprite to be used from this asset sheet.</summary>
/// <summary>Get the relative path for the standard character sprite to be used from this asset sheet.</summary>
/// <param name="imageGraphics">The standard asset sheet to be used.</param>
public virtual string getDefaultSpriteImage(AssetSheet imageGraphics)
{

View File

@ -25,21 +25,13 @@ namespace CustomNPCFramework.Framework.Graphics
/// <summary>Construct an instance.</summary>
/// <param name="info">The asset info file to be read in or created. Holds path information.</param>
/// <param name="path">The path to the assetinfo file.</param>
/// <param name="relativeDirPath">The relative path to the assetinfo file.</param>
/// <param name="direction">The direction to set the animation.</param>
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;
}

View File

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

View File

@ -39,17 +39,17 @@ namespace CustomNPCFramework.Framework.Graphics
}
/// <summary>Save the json to a certain location.</summary>
/// <param name="path">The absolute path to write.</param>
public new void writeToJson(string path)
/// <param name="relativePath">The relative path to write.</param>
public new void writeToJson(string relativePath)
{
Class1.ModHelper.WriteJsonFile<ExtendedAssetInfo>(path, this);
Class1.ModHelper.Data.WriteJsonFile<ExtendedAssetInfo>(relativePath, this);
}
/// <summary>Read the json from a certain location.</summary>
/// <param name="path">The absolute path to read.</param>
public new static ExtendedAssetInfo readFromJson(string path)
/// <param name="relativePath">The relative path to read.</param>
public new static ExtendedAssetInfo readFromJson(string relativePath)
{
return Class1.ModHelper.ReadJsonFile<ExtendedAssetInfo>(path);
return Class1.ModHelper.Data.ReadJsonFile<ExtendedAssetInfo>(relativePath);
}
}
}

View File

@ -14,17 +14,10 @@ namespace CustomNPCFramework.Framework.ModularNpcs
public string relativePath;
/// <summary>Construct an instance.</summary>
/// <param name="path">The full path to the file.</param>
public Sprite(string path)
/// <param name="relativePath">The relative path to the file.</param>
public Sprite(string relativePath)
{
try
{
this.relativePath = Class1.getShortenedDirectory(path);
}
catch
{
this.relativePath = path;
}
this.relativePath = relativePath;
try
{
this.sprite = new AnimatedSprite();

View File

@ -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);
}
/// <summary>Try and emulate the old Game1.shouldFarmerPassout logic.</summary>

View File

@ -26,8 +26,8 @@ namespace Omegasis.SaveAnywhere.Framework
/// <summary>SMAPI's APIs for this mod.</summary>
private readonly IModHelper Helper;
/// <summary>The full path to the player data file.</summary>
private string SavePath => Path.Combine(this.Helper.DirectoryPath, "data", $"{Constants.SaveFolderName}.json");
/// <summary>The relative path to the player data file.</summary>
private string RelativeDataPath => Path.Combine("data", $"{Constants.SaveFolderName}.json");
/// <summary>Whether we should save at the next opportunity.</summary>
private bool WaitingToSave;
@ -80,7 +80,7 @@ namespace Omegasis.SaveAnywhere.Framework
/// <summary>Clear saved data.</summary>
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<PlayerData>(this.SavePath);
PlayerData data = this.Helper.Data.ReadJsonFile<PlayerData>(this.RelativeDataPath);
if (data == null)
return;

View File

@ -36,9 +36,9 @@ namespace SimpleSoundManager.Framework
}
/// <summary>Constructor for wav files.</summary>
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
{

View File

@ -37,9 +37,9 @@ namespace SimpleSoundManager
}
/// <summary>A constructor that takes a mod helper and a relative path to a wav file.</summary>
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;

View File

@ -26,17 +26,5 @@ namespace StardustCore.UIUtilities.SpriteFonts.Components
this.TopPadding = top;
this.BottomPadding = bottom;
}
/// <summary>Save this to a .json file.</summary>
public void WriteToJson(string path)
{
StardustCore.ModCore.ModHelper.WriteJsonFile(path, this);
}
/// <summary>Read the data from the .json file.</summary>
public static CharacterSpacing ReadFromJson(string path)
{
return StardustCore.ModCore.ModHelper.ReadJsonFile<CharacterSpacing>(path);
}
}
}

View File

@ -44,8 +44,7 @@ namespace Vocalization.Framework
{
foreach (LanguageName language in Vocalization.config.translationInfo.LanguageNames)
{
var loaded =
Vocalization.ModHelper.ReadJsonFile<SortedDictionary<string, VoiceAudioOptions>>(Path.Combine(Vocalization.ModHelper.DirectoryPath, "AudioCues", "AudioCues" + Seperator + language + ".json"))
var loaded = Vocalization.ModHelper.Data.ReadJsonFile<SortedDictionary<string, VoiceAudioOptions>>($"AudioCues/AudioCues{Seperator}{language}.json")
?? new SortedDictionary<string, VoiceAudioOptions>();
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<SortedDictionary<string, VoiceAudioOptions>>(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);
}
}
}

View File

@ -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<CharacterVoiceCue>(voiceCueFile);
CharacterVoiceCue cue = ModHelper.Data.ReadJsonFile<CharacterVoiceCue>(relativeCuePath);
//scrapeDictionaries(voiceCueFile,cue);
DialogueCues.Add(characterName, cue);
}
@ -670,7 +667,7 @@ namespace Vocalization
}
/// <summary>Used to obtain all strings for almost all possible dialogue in the game.</summary>
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<CharacterVoiceCue>(cuePath, cue);
ModHelper.Data.WriteJsonFile(relativeCuePath, cue);
//DialogueCues.Add(cue.name, cue);
}