mirror of
https://github.com/Outer-Wilds-New-Horizons/new-horizons.git
synced 2025-12-11 20:15:44 +01:00
Addon manifest used to set up achievements
This commit is contained in:
parent
13a7e5ea4a
commit
1f96f55a35
@ -1,3 +1,4 @@
|
||||
using NewHorizons.External.Configs;
|
||||
using NewHorizons.Utility;
|
||||
using OWML.ModHelper;
|
||||
using System;
|
||||
@ -28,6 +29,8 @@ namespace NewHorizons.AchievementsPlus
|
||||
|
||||
_enabled = true;
|
||||
|
||||
_achievements = new List<AchievementInfo>();
|
||||
|
||||
// Register base NH achievements
|
||||
NH.WarpDriveAchievement.Init();
|
||||
NH.MultipleSystemAchievement.Init();
|
||||
@ -47,6 +50,20 @@ namespace NewHorizons.AchievementsPlus
|
||||
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 Earn(string unique_id)
|
||||
|
||||
25
NewHorizons/External/Configs/AddonConfig.cs
vendored
Normal file
25
NewHorizons/External/Configs/AddonConfig.cs
vendored
Normal 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;
|
||||
|
||||
}
|
||||
}
|
||||
@ -1,9 +1,11 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace NewHorizons.External.Configs
|
||||
{
|
||||
[JsonObject]
|
||||
public class TranslationConfig
|
||||
{
|
||||
/// <summary>
|
||||
@ -21,25 +23,27 @@ namespace NewHorizons.External.Configs
|
||||
/// </summary>
|
||||
public Dictionary<string, string> UIDictionary;
|
||||
|
||||
|
||||
// Literally only exists for the schema generation, Achievements+ handles the parsing
|
||||
#region Achievements+
|
||||
|
||||
/// <summary>
|
||||
/// Translation table for achievements. The key is the unique ID of the achievement
|
||||
/// </summary>
|
||||
private Dictionary<string, AchievementTranslationInfo> AchievementTranslations;
|
||||
public readonly Dictionary<string, AchievementTranslationInfo> AchievementTranslations;
|
||||
|
||||
private class AchievementTranslationInfo
|
||||
[JsonObject]
|
||||
public class AchievementTranslationInfo
|
||||
{
|
||||
/// <summary>
|
||||
/// The name of the achievement.
|
||||
/// </summary>
|
||||
private string Name;
|
||||
public string Name;
|
||||
|
||||
/// <summary>
|
||||
/// The short description for this achievement.
|
||||
/// </summary>
|
||||
private string Description;
|
||||
public readonly string Description;
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
@ -363,11 +363,19 @@ namespace NewHorizons
|
||||
BodyDict[body.Config.starSystem].Add(body);
|
||||
}
|
||||
}
|
||||
}
|
||||
// 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\"))
|
||||
{
|
||||
LoadTranslations(folder, mod);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user