Line 348: |
Line 348: |
| namespace MyMail | | namespace MyMail |
| { | | { |
− | public class MailData : IAssetEditor | + | internal sealed class ModEntry: Mod |
| { | | { |
| // This collection holds any letters loaded after the initial load or last cache refresh | | // This collection holds any letters loaded after the initial load or last cache refresh |
− | private Dictionary<string, string> dynamicMail = new Dictionary<string, string>(); | + | private Dictionary<string, string> dynamicMail = new(); |
− | | + | |
− | public MailData() | + | public override void Entry(IModHelper helper) |
| { | | { |
| + | helper.Events.Content.AssetRequested += this.OnAssetRequested; |
| } | | } |
| | | |
− | public bool CanEdit<T>(IAssetInfo asset) | + | private void OnAssetRequested(object? sender, AssetRequestedEventArgs e) |
| { | | { |
− | return asset.AssetNameEquals("Data\\mail");
| + | if (e.NameWithoutLocale.IsEquivalentTo("Data/mail")) |
| + | e.Edit(this.EditImpl); |
| } | | } |
| | | |
− | public void Edit<T>(IAssetData asset) | + | public void EditImpl(IAssetData asset) |
| { | | { |
| var data = asset.AsDictionary<string, string>().Data; | | var data = asset.AsDictionary<string, string>().Data; |
Line 388: |
Line 390: |
| if (!string.IsNullOrEmpty(mailId)) | | if (!string.IsNullOrEmpty(mailId)) |
| { | | { |
− | if (dynamicMail.ContainsKey(mailId)) | + | dynamicMail[mailId] = mailText; |
− | dynamicMail[mailId] = mailText;
| |
− | else
| |
− | dynamicMail.Add(mailId, mailText);
| |
| } | | } |
| } | | } |