From 9ef900f80f50fd9ce69d8848a9c1f40efcabfd1a Mon Sep 17 00:00:00 2001 From: fallenoak Date: Mon, 3 Nov 2025 19:55:08 -0600 Subject: [PATCH] feat(component): implement CCharacterComponent::AddLink --- src/component/CCharacterComponent.cpp | 55 ++++++++++++++++++++++++++- src/component/CCharacterComponent.hpp | 2 +- 2 files changed, 54 insertions(+), 3 deletions(-) diff --git a/src/component/CCharacterComponent.cpp b/src/component/CCharacterComponent.cpp index ccae0eb..1c755ae 100644 --- a/src/component/CCharacterComponent.cpp +++ b/src/component/CCharacterComponent.cpp @@ -6,6 +6,7 @@ #include "gx/Device.hpp" #include "gx/Texture.hpp" #include "model/CM2Model.hpp" +#include "model/CM2Scene.hpp" #include "object/Types.hpp" #include "util/CStatus.hpp" #include "util/Unimplemented.hpp" @@ -160,8 +161,58 @@ int32_t CCharacterComponent::AddHandItem(CM2Model* model, const ItemDisplayInfoR return link; } -void CCharacterComponent::AddLink(CM2Model* model, GEOCOMPONENTLINKS link, char const* modelPath, char const* texturePath, int32_t a5, const ItemDisplayInfoRec* displayRec) { - // TODO +void CCharacterComponent::AddLink(CM2Model* parent, GEOCOMPONENTLINKS link, char const* modelPath, char const* texturePath, int32_t visualID, const ItemDisplayInfoRec* displayRec) { + if (!parent) { + return; + } + + // Create item model + + auto model = parent->m_scene->CreateModel(modelPath, 0); + + if (!model) { + return; + } + + // Create item texture + + auto textureFlags = CGxTexFlags(GxTex_LinearMipNearest, 0, 0, 0, 0, 0, 1); + auto texture = TextureCreate(texturePath, textureFlags, &s_status, 0); + + if (!texture) { + model->Release(); + return; + } + + // Replace item texture + + model->ReplaceTexture(2, texture); + HandleClose(texture); + + // Add item visual + + if (visualID > 0) { + // TODO CCharacterComponent::ComponentUtilAddItemVisual(model, visualID); + } + + // Attach item to parent + + parent->DetachAllChildrenById(link); + model->AttachToParent(parent, link, nullptr, 0); + + // Add link point + + if (link == ATTACH_HANDR) { + // TODO CCharacterComponent::AddLinkpt(parent, 0); + } else if (link == ATTACH_HANDL) { + // TODO CCharacterComponent::AddLinkpt(parent, 1); + } + + // Replace item particle color + + // TODO ReplaceParticleColor(displayRec->m_particleColorID, model); + + model->Release(); } CCharacterComponent* CCharacterComponent::AllocComponent() { diff --git a/src/component/CCharacterComponent.hpp b/src/component/CCharacterComponent.hpp index 3be3eac..51cc780 100644 --- a/src/component/CCharacterComponent.hpp +++ b/src/component/CCharacterComponent.hpp @@ -48,7 +48,7 @@ class CCharacterComponent { // Static functions static int32_t AddHandItem(CM2Model* model, const ItemDisplayInfoRec* displayRec, INVENTORY_SLOTS invSlot, SHEATHE_TYPE sheatheType, bool sheathed, bool shield, bool a7, int32_t a8); - static void AddLink(CM2Model* model, GEOCOMPONENTLINKS link, char const* modelPath, char const* texturePath, int32_t a5, const ItemDisplayInfoRec* displayRec); + static void AddLink(CM2Model* parent, GEOCOMPONENTLINKS link, char const* modelPath, char const* texturePath, int32_t visualID, const ItemDisplayInfoRec* displayRec); static CCharacterComponent* AllocComponent(); static HTEXTURE CreateTexture(const char* fileName, CStatus* status); static GEOCOMPONENTLINKS GetSheatheLink(SHEATHE_TYPE sheatheType, bool a2);