Addon manifest used to set up achievements

This commit is contained in:
Nick 2022-06-19 15:06:03 -04:00
parent 13a7e5ea4a
commit 1f96f55a35
4 changed files with 59 additions and 5 deletions

View File

@ -1,3 +1,4 @@
using NewHorizons.External.Configs;
using NewHorizons.Utility; using NewHorizons.Utility;
using OWML.ModHelper; using OWML.ModHelper;
using System; using System;
@ -28,6 +29,8 @@ namespace NewHorizons.AchievementsPlus
_enabled = true; _enabled = true;
_achievements = new List<AchievementInfo>();
// Register base NH achievements // Register base NH achievements
NH.WarpDriveAchievement.Init(); NH.WarpDriveAchievement.Init();
NH.MultipleSystemAchievement.Init(); NH.MultipleSystemAchievement.Init();
@ -47,6 +50,20 @@ namespace NewHorizons.AchievementsPlus
GlobalMessenger<string, bool>.RemoveListener("DialogueConditionChanged", OnDialogueConditionChanged); GlobalMessenger<string, bool>.RemoveListener("DialogueConditionChanged", OnDialogueConditionChanged);
} }
public static void RegisterAddon(AddonConfig addon, ModBehaviour mod)
{
if (addon.achievements == null) return;
if (!_enabled) return;
foreach (var achievement in addon.achievements)
{
_achievements.Add(achievement);
API.RegisterAchievement(achievement.ID, achievement.secret, mod);
}
}
public static void RegisterTranslationsFromFiles(ModBehaviour mod, string path) => API.RegisterTranslationsFromFiles(mod, path); public static void RegisterTranslationsFromFiles(ModBehaviour mod, string path) => API.RegisterTranslationsFromFiles(mod, path);
public static void Earn(string unique_id) public static void Earn(string unique_id)

View File

@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using NewHorizons.AchievementsPlus;
using NewHorizons.External.Modules;
using NewHorizons.External.Modules.VariableSize;
using Newtonsoft.Json;
namespace NewHorizons.External.Configs
{
/// <summary>
/// Describes the New Horizons addon itself
/// </summary>
[JsonObject]
public class AddonConfig
{
/// <summary>
/// Achievements for this mod if the user is playing with Achievements+
/// </summary>
public AchievementInfo[] achievements;
}
}

View File

@ -1,9 +1,11 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
namespace NewHorizons.External.Configs namespace NewHorizons.External.Configs
{ {
[JsonObject]
public class TranslationConfig public class TranslationConfig
{ {
/// <summary> /// <summary>
@ -21,25 +23,27 @@ namespace NewHorizons.External.Configs
/// </summary> /// </summary>
public Dictionary<string, string> UIDictionary; public Dictionary<string, string> UIDictionary;
// Literally only exists for the schema generation, Achievements+ handles the parsing // Literally only exists for the schema generation, Achievements+ handles the parsing
#region Achievements+ #region Achievements+
/// <summary> /// <summary>
/// Translation table for achievements. The key is the unique ID of the achievement /// Translation table for achievements. The key is the unique ID of the achievement
/// </summary> /// </summary>
private Dictionary<string, AchievementTranslationInfo> AchievementTranslations; public readonly Dictionary<string, AchievementTranslationInfo> AchievementTranslations;
private class AchievementTranslationInfo [JsonObject]
public class AchievementTranslationInfo
{ {
/// <summary> /// <summary>
/// The name of the achievement. /// The name of the achievement.
/// </summary> /// </summary>
private string Name; public string Name;
/// <summary> /// <summary>
/// The short description for this achievement. /// The short description for this achievement.
/// </summary> /// </summary>
private string Description; public readonly string Description;
} }
#endregion #endregion

View File

@ -364,10 +364,18 @@ namespace NewHorizons
} }
} }
} }
// Has to go before translations for achievements
if (File.Exists("addon-manifest.json"))
{
var addonConfig = mod.ModHelper.Storage.Load<AddonConfig>("addon-manifest.json");
AchievementHandler.RegisterAddon(addonConfig, mod as ModBehaviour);
}
if (Directory.Exists(folder + @"translations\")) if (Directory.Exists(folder + @"translations\"))
{ {
LoadTranslations(folder, mod); LoadTranslations(folder, mod);
} }
} }
catch (Exception ex) catch (Exception ex)
{ {