Skip to content

Commit

Permalink
Merge branch 'Release2.0.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Glyceri committed Jul 24, 2024
2 parents 9c04f8c + 0e8b7ca commit 9293620
Show file tree
Hide file tree
Showing 17 changed files with 96 additions and 311 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/Release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,4 @@ jobs:
git checkout main
git add PetNicknames.json
git commit -m "[CI] Updating PetNicknames.json for ${{ github.ref_name }}" || true
git push origin main
git push origin main
62 changes: 31 additions & 31 deletions PetNicknames.json
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
[
{
"Author": "Glyceri",
"Name": "Pet Nicknames",
"InternalName": "PetNicknames",
"AssemblyVersion": "2.0.0.0",
"TestingAssemblyVersion": "2.0.0.0",
"Description": "Give your minions, Carbuncles and Faeries cute nicknames\nand share them with your friends.",
"ApplicableVersion": "any",
"RepoUrl": "https://github.com/Glyceri/FFXIVPetRenamer",
"Tags": [
"Pet",
"plugin",
"Rename",
"Nickname",
"Name",
"Minion"
],
"DalamudApiLevel": 10,
"LoadRequiredState": 0,
"LoadSync": false,
"CanUnloadAsync": false,
"LoadPriority": 0,
"IconUrl": "https://github.com/Glyceri/FFXIVPetRenamer/raw/main/icon.png",
"Punchline": "Give your minions, Carbuncles and Faeries cute nicknames\nand share them with your friends.",
"AcceptsFeedback": true,
"DownloadLinkInstall": "https://github.com/Glyceri/FFXIVPetRenamer/releases/download/2.0.0.0/PetNicknames.zip",
"DownloadLinkUpdate": "https://github.com/Glyceri/FFXIVPetRenamer/releases/download/2.0.0.0/PetNicknames.zip",
"DownloadLinkTesting": "https://github.com/Glyceri/FFXIVPetRenamer/releases/download/2.0.0.0/PetNicknames.zip"
}
]
[
{
"Author": "Glyceri",
"Name": "Pet Nicknames",
"InternalName": "PetNicknames",
"AssemblyVersion": "2.0.0.0",
"TestingAssemblyVersion": "2.0.0.0",
"Description": "Give your minions, Carbuncles and Faeries cute nicknames\nand share them with your friends.",
"ApplicableVersion": "any",
"RepoUrl": "https://github.com/Glyceri/FFXIVPetRenamer",
"Tags": [
"Pet",
"plugin",
"Rename",
"Nickname",
"Name",
"Minion"
],
"DalamudApiLevel": 10,
"LoadRequiredState": 0,
"LoadSync": false,
"CanUnloadAsync": false,
"LoadPriority": 0,
"IconUrl": "https://github.com/Glyceri/FFXIVPetRenamer/raw/main/icon.png",
"Punchline": "Give your minions, Carbuncles and Faeries cute nicknames\nand share them with your friends.",
"AcceptsFeedback": true,
"DownloadLinkInstall": "https://github.com/Glyceri/FFXIVPetRenamer/releases/download/2.0.0.0/PetNicknames.zip",
"DownloadLinkUpdate": "https://github.com/Glyceri/FFXIVPetRenamer/releases/download/2.0.0.0/PetNicknames.zip",
"DownloadLinkTesting": "https://github.com/Glyceri/FFXIVPetRenamer/releases/download/2.0.0.0/PetNicknames.zip"
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ public NamePlateHook(DalamudServices services, IPetServices petServices, IPettab
public override void Init()
{
DalamudServices.NameplateGUI.OnNamePlateUpdate += OnPlateUpdate;
Refresh();
}

protected override void OnDispose()
{
Refresh();
DalamudServices.NameplateGUI.OnNamePlateUpdate -= OnPlateUpdate;
}

Expand Down
12 changes: 8 additions & 4 deletions PetNicknames/PetNicknames/IPC/SharingDictionary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,23 @@ internal class SharingDictionary : ISharingDictionary
readonly DalamudServices DalamudServices;

// Data Sharing
readonly Dictionary<uint, string> PetNicknameDict = new Dictionary<uint, string>();
readonly Dictionary<ulong, string> PetNicknameDict = new Dictionary<ulong, string>();

public SharingDictionary(in DalamudServices dalamudServices)
{
DalamudServices = dalamudServices;

// Data sharing
PetNicknameDict = DalamudServices.PetNicknamesPlugin.GetOrCreateData($"PetRenamer.GameObjectRenameDict", () => new Dictionary<uint, string>());
try
{
// Data sharing
PetNicknameDict = DalamudServices.PetNicknamesPlugin.GetOrCreateData($"PetRenamer.GameObjectRenameDict", () => new Dictionary<ulong, string>());
}
catch { }
}

public void Set(GameObjectId gameObjectID, string customName)
{
PetNicknameDict.Add(gameObjectID.ObjectId, customName);
PetNicknameDict.Add(gameObjectID, customName);
}

public void Clear()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ internal interface IPettableDatabase
/// </summary>
/// <param name="name">Player Name</param>
/// <returns>The Data Base Entry</returns>
IPettableDatabaseEntry GetEntry(string name, ushort homeworld);
IPettableDatabaseEntry? GetEntry(string name, ushort homeworld, bool create);
/// <summary>
/// Get's the database entry if it exists. In the case it doesn't it creates a new one!
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ public LegacyPettableDatabase(in IPetServices PetServices, in IPettableDirtyCall

public void ApplyParseResult(IBaseParseResult parseResult, bool isFromIPC)
{
IPettableDatabaseEntry entry = GetEntry(parseResult.UserName, parseResult.Homeworld);
IPettableDatabaseEntry? entry = GetEntry(parseResult.UserName, parseResult.Homeworld, true);
if (entry == null) return;

entry.UpdateEntryBase(parseResult, isFromIPC);
SetDirty();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public PettableDatabase(in IPetServices petServices, in IPettableDirtyCaller dir
_entries = newEntries;
}

public IPettableDatabaseEntry GetEntry(string name, ushort homeworld)
public IPettableDatabaseEntry? GetEntry(string name, ushort homeworld, bool create)
{
int entriesCount = _entries.Count;
for (int i = 0; i < entriesCount; i++)
Expand All @@ -64,6 +64,11 @@ public IPettableDatabaseEntry GetEntry(string name, ushort homeworld)
return entry;
}

if (!create)
{
return null;
}

IPettableDatabaseEntry newEntry = new PettableDataBaseEntry(in PetServices, in DirtyCaller, 0, name, homeworld, [], [], PluginConstants.BaseSkeletons, DateTime.Now.ToString("yyyyMMdd"), PetRenamerPlugin.PuginVersion.ToString(), false);
_entries.Add(newEntry);
return newEntry;
Expand Down
12 changes: 11 additions & 1 deletion PetNicknames/PetNicknames/PettableUsers/PettableUser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using FFXIVClientStructs.FFXIV.Client.Game.Object;
using FFXIVClientStructs.Interop;
using PetRenamer.PetNicknames.IPC.Interfaces;
using PetRenamer.PetNicknames.PettableDatabase;
using PetRenamer.PetNicknames.PettableDatabase.Interfaces;
using PetRenamer.PetNicknames.PettableUsers.Interfaces;
using PetRenamer.PetNicknames.Services.Interface;
Expand Down Expand Up @@ -35,7 +36,7 @@ internal unsafe class PettableUser : IPettableUser
readonly IPettableDirtyListener DirtyListener;
readonly ISharingDictionary SharingDictionary;

public PettableUser(in ISharingDictionary sharingDictionary, in IPettableDatabase dataBase, in IPetServices petServices, in IPettableDirtyListener dirtyListener, Pointer<BattleChara> battleChara)
public PettableUser(in ISharingDictionary sharingDictionary, in IPettableDatabase dataBase, in ILegacyDatabase legacyDatabase, in IPetServices petServices, in IPettableDirtyListener dirtyListener, Pointer<BattleChara> battleChara)
{
DirtyListener = dirtyListener;
SharingDictionary = sharingDictionary;
Expand All @@ -53,6 +54,15 @@ public PettableUser(in ISharingDictionary sharingDictionary, in IPettableDatabas

ObjectID = BattleChara->GetGameObjectId();
ShortObjectID = BattleChara->GetGameObjectId().ObjectId;

IPettableDatabaseEntry? legacyEntry = legacyDatabase.GetEntry(Name, Homeworld, false);
if (legacyEntry != null)
{
legacyEntry.UpdateContentID(ContentID, true);
legacyDatabase.RemoveEntry(legacyEntry);
legacyEntry.MoveToDataBase(dataBase);
}

DataBaseEntry = dataBase.GetEntry(ContentID);
DataBaseEntry.UpdateEntry(this);
PetServices = petServices;
Expand Down
27 changes: 26 additions & 1 deletion PetNicknames/PetNicknames/Services/PetServices.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
using PetRenamer.Legacy.LegacyStepper;
using Dalamud.Utility;
using PetRenamer.Legacy.LegacyStepper;
using PetRenamer.PetNicknames.Services.Interface;
using PetRenamer.PetNicknames.Services.ServiceWrappers;
using PetRenamer.PetNicknames.Services.ServiceWrappers.Interfaces;
using System;
using System.IO;

namespace PetRenamer.PetNicknames.Services;

Expand All @@ -13,9 +16,14 @@ internal class PetServices : IPetServices
public IStringHelper StringHelper { get; init; }
public IPetCastHelper PetCastHelper { get; init; }

readonly DalamudServices DalamudServices;

public PetServices(DalamudServices services)
{
DalamudServices = services;

PetLog = new PetLogWrapper(services.PluginLog);
MoveOldConfig();
Configuration = services.PetNicknamesPlugin.GetPluginConfig() as Configuration ?? new Configuration();
StringHelper = new StringHelperWrapper();
PetSheets = new SheetsWrapper(ref services, StringHelper);
Expand All @@ -29,4 +37,21 @@ void CheckConfigFailure()
if (Configuration.currentSaveFileVersion == Configuration.Version) return;
_ = new LegacyStepper(Configuration, this);
}

void MoveOldConfig()
{
DirectoryInfo directory = DalamudServices.PetNicknamesPlugin.ConfigDirectory;
if (directory == null) return;

try
{
string? path = directory.Parent!.FullName;
if (path.IsNullOrWhitespace()) return;

string oldPath = path + "\\PetRenamer.json";
string newPath = path + "\\PetNicknames.json";

File.Move(oldPath, newPath);
} catch { }
}
}
110 changes: 0 additions & 110 deletions PetNicknames/PetNicknames/Update/Updatables/LegacyDatabaseHelper.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,18 @@ internal unsafe class PettableUserHandler : IUpdatable
readonly IPettableUserList PettableUserList;
readonly IPetLog PetLog;
readonly IPettableDatabase PettableDatabase;
readonly ILegacyDatabase LegacyDatabase;
readonly IPettableDirtyListener DirtyListener;

public PettableUserHandler(in DalamudServices dalamudServices, in ISharingDictionary sharingDictionary, in IPettableUserList pettableUserList, in IPettableDatabase pettableDatabase, in IPetServices petServices, in IPettableDirtyListener dirtyListener)
public PettableUserHandler(in DalamudServices dalamudServices, in ISharingDictionary sharingDictionary, in IPettableUserList pettableUserList, in IPettableDatabase pettableDatabase, in ILegacyDatabase legacyDatabase, in IPetServices petServices, in IPettableDirtyListener dirtyListener)
{
DalamudServices = dalamudServices;
SharingDictionary = sharingDictionary;
PetServices = petServices;
PettableUserList = pettableUserList;
PetLog = PetServices.PetLog;
PettableDatabase = pettableDatabase;
LegacyDatabase = legacyDatabase;
DirtyListener = dirtyListener;
}

Expand Down Expand Up @@ -74,7 +76,7 @@ public void OnUpdate(IFramework framework)
if (pettableUser == null && battleChara != null && currentObjectKind == ObjectKind.Pc)
{
// Create a user
IPettableUser newUser = new PettableUser(in SharingDictionary, in PettableDatabase, in PetServices, in DirtyListener, battleChara);
IPettableUser newUser = new PettableUser(in SharingDictionary, in PettableDatabase, in LegacyDatabase, in PetServices, in DirtyListener, battleChara);
PettableUserList.PettableUsers[i] = newUser;
continue;
}
Expand Down
7 changes: 3 additions & 4 deletions PetNicknames/PetNicknames/Update/UpdateHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ internal class UpdateHandler : IDisposable
readonly IPetServices PetServices;
readonly IPettableUserList PettableUserList;
readonly IPettableDatabase PettableDatabase;
readonly IPettableDatabase LegacyPettableDatabase;
readonly ILegacyDatabase LegacyPettableDatabase;
readonly IPettableDirtyListener DirtyListener;
readonly IImageDatabase ImageDatabase;
readonly LodestoneNetworker LodestoneNetworker;
readonly List<IUpdatable> _updatables = new List<IUpdatable>();

public UpdateHandler(in DalamudServices dalamudServices, in ISharingDictionary sharingDictionary, in IPettableUserList pettableUserList, in IPettableDatabase legacyDatabase, in IPettableDatabase pettableDatabase, in IPetServices petServices, in LodestoneNetworker lodestoneNetworker, in IImageDatabase imageDatabase, in IPettableDirtyListener dirtyListener)
public UpdateHandler(in DalamudServices dalamudServices, in ISharingDictionary sharingDictionary, in IPettableUserList pettableUserList, in ILegacyDatabase legacyDatabase, in IPettableDatabase pettableDatabase, in IPetServices petServices, in LodestoneNetworker lodestoneNetworker, in IImageDatabase imageDatabase, in IPettableDirtyListener dirtyListener)
{
DalamudServices = dalamudServices;
SharingDictionary = sharingDictionary;
Expand All @@ -45,8 +45,7 @@ public UpdateHandler(in DalamudServices dalamudServices, in ISharingDictionary s

void Setup()
{
_updatables.Add(new LegacyDatabaseHelper(in DalamudServices, in LegacyPettableDatabase, in PettableDatabase, in PetServices, in PettableUserList));
_updatables.Add(new PettableUserHandler(in DalamudServices, in SharingDictionary, in PettableUserList, in PettableDatabase, in PetServices, in DirtyListener));
_updatables.Add(new PettableUserHandler(in DalamudServices, in SharingDictionary, in PettableUserList, in PettableDatabase, in LegacyPettableDatabase, in PetServices, in DirtyListener));
_updatables.Add(new LodestoneQueueHelper(in LodestoneNetworker, in ImageDatabase));
}

Expand Down
Loading

0 comments on commit 9293620

Please sign in to comment.