From 9c1617c9ee51a0f6b93242fe8fc789336957460c Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Wed, 11 Apr 2018 21:15:16 -0400 Subject: drop support for Stardew Valley 1.2 (#453) --- src/SMAPI/Framework/ContentCore.cs | 83 ++++---------------------------------- 1 file changed, 8 insertions(+), 75 deletions(-) (limited to 'src/SMAPI/Framework/ContentCore.cs') diff --git a/src/SMAPI/Framework/ContentCore.cs b/src/SMAPI/Framework/ContentCore.cs index 43357553..9da18481 100644 --- a/src/SMAPI/Framework/ContentCore.cs +++ b/src/SMAPI/Framework/ContentCore.cs @@ -44,10 +44,8 @@ namespace StardewModdingAPI.Framework /// The underlying asset cache. private readonly ContentCache Cache; -#if STARDEW_VALLEY_1_3 /// A lookup which indicates whether the asset is localisable (i.e. the filename contains the locale), if previously loaded. private readonly IDictionary IsLocalisableLookup; -#endif /// The locale codes used in asset keys indexed by enum value. private readonly IDictionary Locales; @@ -111,9 +109,7 @@ namespace StardewModdingAPI.Framework this.CoreAssets = new CoreAssetPropagator(this.NormaliseAssetName, reflection); this.Locales = this.GetKeyLocales(reflection); this.LanguageCodes = this.Locales.ToDictionary(p => p.Value, p => p.Key, StringComparer.InvariantCultureIgnoreCase); -#if STARDEW_VALLEY_1_3 this.IsLocalisableLookup = reflection.GetField>(this.Content, "_localizedAsset").GetValue(); -#endif } /// Get a new content manager which defers loading to the content core. @@ -209,11 +205,7 @@ namespace StardewModdingAPI.Framework /// The language code for which to load content. /// The is empty or contains invalid characters. /// The content asset couldn't be loaded (e.g. because it doesn't exist). - public T Load(string assetName, ContentManager instance -#if STARDEW_VALLEY_1_3 - , LocalizedContentManager.LanguageCode language -#endif - ) + public T Load(string assetName, ContentManager instance, LocalizedContentManager.LanguageCode language) { // normalise asset key this.AssertValidAssetKeyFormat(assetName); @@ -221,11 +213,7 @@ namespace StardewModdingAPI.Framework // load game content if (!assetName.StartsWith(this.ModContentPrefix)) -#if STARDEW_VALLEY_1_3 return this.LoadImpl(assetName, instance, language); -#else - return this.LoadImpl(assetName, instance); -#endif // load mod content SContentLoadException GetContentError(string reasonPhrase) => new SContentLoadException($"Failed loading content asset '{assetName}': {reasonPhrase}"); @@ -235,11 +223,7 @@ namespace StardewModdingAPI.Framework { // try cache if (this.IsLoaded(assetName)) -#if STARDEW_VALLEY_1_3 return this.LoadImpl(assetName, instance, language); -#else - return this.LoadImpl(assetName, instance); -#endif // get file FileInfo file = this.GetModFile(assetName); @@ -251,11 +235,7 @@ namespace StardewModdingAPI.Framework { // XNB file case ".xnb": -#if STARDEW_VALLEY_1_3 return this.LoadImpl(assetName, instance, language); -#else - return this.LoadImpl(assetName, instance); -#endif // unpacked map case ".tbin": @@ -436,10 +416,6 @@ namespace StardewModdingAPI.Framework /// Simplifies access to private game code. private IDictionary GetKeyLocales(Reflector reflection) { -#if !STARDEW_VALLEY_1_3 - IReflectedField codeField = reflection.GetField(typeof(LocalizedContentManager), "_currentLangCode"); - LocalizedContentManager.LanguageCode previousCode = codeField.GetValue(); -#endif string previousOverride = this.Content.LanguageCodeOverride; try @@ -448,21 +424,11 @@ namespace StardewModdingAPI.Framework this.Content.LanguageCodeOverride = null; // create locale => code map - IReflectedMethod languageCodeString = reflection -#if STARDEW_VALLEY_1_3 - .GetMethod(this.Content, "languageCodeString"); -#else - .GetMethod(this.Content, "languageCode"); -#endif + IReflectedMethod languageCodeString = reflection.GetMethod(this.Content, "languageCodeString"); IDictionary map = new Dictionary(); foreach (LocalizedContentManager.LanguageCode code in Enum.GetValues(typeof(LocalizedContentManager.LanguageCode))) { -#if STARDEW_VALLEY_1_3 map[code] = languageCodeString.Invoke(code); -#else - codeField.SetValue(code); - map[code] = languageCodeString.Invoke(); -#endif } return map; @@ -471,10 +437,6 @@ namespace StardewModdingAPI.Framework { // restore previous settings this.Content.LanguageCodeOverride = previousOverride; -#if !STARDEW_VALLEY_1_3 - codeField.SetValue(previousCode); -#endif - } } @@ -520,18 +482,12 @@ namespace StardewModdingAPI.Framework /// The normalised asset name. private bool IsNormalisedKeyLoaded(string normalisedAssetName) { -#if STARDEW_VALLEY_1_3 if (!this.IsLocalisableLookup.TryGetValue(normalisedAssetName, out bool localisable)) return false; return localisable ? this.Cache.ContainsKey($"{normalisedAssetName}.{this.Locales[this.Content.GetCurrentLanguage()]}") : this.Cache.ContainsKey(normalisedAssetName); -#else - return - this.Cache.ContainsKey(normalisedAssetName) - || this.Cache.ContainsKey($"{normalisedAssetName}.{this.Locales[this.Content.GetCurrentLanguage()]}"); // translated asset -#endif } /// Track that a content manager loaded an asset. @@ -552,11 +508,7 @@ namespace StardewModdingAPI.Framework /// The asset path relative to the loader root directory, not including the .xnb extension. /// The content manager instance for which to load the asset. /// The language code for which to load content. - private T LoadImpl(string assetName, ContentManager instance -#if STARDEW_VALLEY_1_3 - , LocalizedContentManager.LanguageCode language -#endif - ) + private T LoadImpl(string assetName, ContentManager instance, LocalizedContentManager.LanguageCode language) { return this.WithWriteLock(() => { @@ -564,13 +516,7 @@ namespace StardewModdingAPI.Framework if (this.IsNormalisedKeyLoaded(assetName)) { this.TrackAssetLoader(assetName, instance); - return this.Content - -#if STARDEW_VALLEY_1_3 - .Load(assetName, language); -#else - .Load(assetName); -#endif + return this.Content.Load(assetName, language); } // load asset @@ -579,30 +525,17 @@ namespace StardewModdingAPI.Framework { this.Monitor.Log($"Broke loop while loading asset '{assetName}'.", LogLevel.Warn); this.Monitor.Log($"Bypassing mod loaders for this asset. Stack trace:\n{Environment.StackTrace}", LogLevel.Trace); - data = this.Content -#if STARDEW_VALLEY_1_3 - .Load(assetName, language); -#else - .Load(assetName); -#endif + data = this.Content.Load(assetName, language); } else { data = this.AssetsBeingLoaded.Track(assetName, () => { - string locale = -#if STARDEW_VALLEY_1_3 - this.GetLocale(language); -#else - this.GetLocale(); -#endif + string locale = this.GetLocale(language); IAssetInfo info = new AssetInfo(locale, assetName, typeof(T), this.NormaliseAssetName); - IAssetData asset = this.ApplyLoader(info) -#if STARDEW_VALLEY_1_3 + IAssetData asset = + this.ApplyLoader(info) ?? new AssetDataForObject(info, this.Content.Load(assetName, language), this.NormaliseAssetName); -#else - ?? new AssetDataForObject(info, this.Content.Load(assetName), this.NormaliseAssetName); -#endif asset = this.ApplyEditors(info, asset); return (T)asset.Data; }); -- cgit