Skip to content

Commit

Permalink
Merge pull request #391 from Daztek/object-deprecate-portrait-functions
Browse files Browse the repository at this point in the history
Object: deprecate {Set/Get}Portrait
  • Loading branch information
mtijanic authored Feb 25, 2019
2 parents 6bd2625 + 9cf0f5c commit 554612b
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 51 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ The following plugins were added:
- Events: Changed `NUM_LEVELS` to `AMOUNT` for DMActionEvent GiveLevel

### Deprecated
- Player: {Get/Set}VisibilityOverride are deprecated, please use the new Visibility plugin!
- Player: {Get/Set}VisibilityOverride() are deprecated, please use the new Visibility plugin!
- Object: {Get/Set}Portrait() are deprecated, please use the native {Get/Set}PortraitResRef() functions instead!

### Removed
- The following plugins were removed: Names, BehaviourTree
Expand Down
19 changes: 7 additions & 12 deletions Plugins/Object/NWScript/nwnx_object.nss
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,12 @@ void NWNX_Object_SetCurrentHitPoints(object obj, int hp);
void NWNX_Object_SetMaxHitPoints(object obj, int hp);

// Get the name of the portrait object is using.
// DEPRECATED - Use GetPortraitResRef() built-in function instead
string NWNX_Object_GetPortrait(object obj);

// Set the portrait object is using. The portrait string must be no more
// than 15 characters long.
// DEPRECATED - Use SetPortraitResRef() built-in function instead
void NWNX_Object_SetPortrait(object obj, string portrait);

// Serialize the full object (including locals, inventory, etc) to base64 string
Expand Down Expand Up @@ -247,27 +249,21 @@ void NWNX_Object_SetMaxHitPoints(object creature, int hp)

NWNX_CallFunction(NWNX_Object, sFunc);
}

string NWNX_Object_GetPortrait(object creature)
{
string sFunc = "GetPortrait";

NWNX_PushArgumentObject(NWNX_Object, sFunc, creature);
WriteTimestampedLogEntry("NWNX_Object: GetPortrait() is deprecated. Use native GetPortraitResRef() instead");

NWNX_CallFunction(NWNX_Object, sFunc);
return NWNX_GetReturnValueString(NWNX_Object, sFunc);
return GetPortraitResRef(creature);
}

void NWNX_Object_SetPortrait(object creature, string portrait)
{
string sFunc = "SetPortrait";
WriteTimestampedLogEntry("NWNX_Object: SetPortrait() is deprecated. Use native SetPortraitResRef() instead");

NWNX_PushArgumentString(NWNX_Object, sFunc, portrait);
NWNX_PushArgumentObject(NWNX_Object, sFunc, creature);

NWNX_CallFunction(NWNX_Object, sFunc);
SetPortraitResRef(creature, portrait);
}


string NWNX_Object_Serialize(object obj)
{
string sFunc = "Serialize";
Expand All @@ -288,7 +284,6 @@ object NWNX_Object_Deserialize(string serialized)
return NWNX_GetReturnValueObject(NWNX_Object, sFunc);
}


string NWNX_Object_GetDialogResref(object obj)
{
string sFunc = "GetDialogResref";
Expand Down
38 changes: 2 additions & 36 deletions Plugins/Object/Object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ Object::Object(const Plugin::CreateParams& params)
REGISTER(SetPosition);
REGISTER(SetCurrentHitPoints);
REGISTER(SetMaxHitPoints);
REGISTER(GetPortrait);
REGISTER(SetPortrait);
REGISTER(Serialize);
REGISTER(Deserialize);
REGISTER(GetDialogResref);
Expand Down Expand Up @@ -184,38 +182,6 @@ ArgumentStack Object::SetMaxHitPoints(ArgumentStack&& args)
return stack;
}

ArgumentStack Object::GetPortrait(ArgumentStack&& args)
{
ArgumentStack stack;
std::string retval = "";
if (auto *pObject = object(args))
{
if (pObject->m_nObjectType == Constants::ObjectType::Creature)
retval = static_cast<CNWSCreature*>(pObject)->GetPortrait().GetResRefStr();
else
retval = pObject->GetPortrait().GetResRefStr();
}
Services::Events::InsertArgument(stack, retval);
return stack;
}

ArgumentStack Object::SetPortrait(ArgumentStack&& args)
{
ArgumentStack stack;

if (auto *pObject = object(args))
{
const auto portrait = Services::Events::ExtractArgument<std::string>(args);

CResRef resref = CResRef(portrait.c_str());
if (auto *pCreature = Utils::AsNWSCreature(pObject))
pCreature->SetPortrait(resref);
else
pObject->SetPortrait(resref);
}
return stack;
}

ArgumentStack Object::Serialize(ArgumentStack&& args)
{
ArgumentStack stack;
Expand Down Expand Up @@ -315,7 +281,7 @@ ArgumentStack Object::GetHasVisualEffect(ArgumentStack&& args)
{
ArgumentStack stack;
int32_t retVal=0;

if (auto *pObject = object(args))
{
const auto nVfx = Services::Events::ExtractArgument<int32_t>(args);
Expand All @@ -330,7 +296,7 @@ ArgumentStack Object::GetHasVisualEffect(ArgumentStack&& args)
}
}
}

Services::Events::InsertArgument(stack, retVal);
return stack;
}
Expand Down
2 changes: 0 additions & 2 deletions Plugins/Object/Object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ class Object : public NWNXLib::Plugin
ArgumentStack SetPosition (ArgumentStack&& args);
ArgumentStack SetCurrentHitPoints (ArgumentStack&& args);
ArgumentStack SetMaxHitPoints (ArgumentStack&& args);
ArgumentStack GetPortrait (ArgumentStack&& args);
ArgumentStack SetPortrait (ArgumentStack&& args);
ArgumentStack Serialize (ArgumentStack&& args);
ArgumentStack Deserialize (ArgumentStack&& args);
ArgumentStack GetDialogResref (ArgumentStack&& args);
Expand Down

0 comments on commit 554612b

Please sign in to comment.