ff_u_area_reload
Reload an area when its .git file is modified in a watched resource folder.
When an area’s .git file is modified in a watched resource folder (such as
development), for example by saving the area in the toolset, the area is
reloaded one second later: it is destroyed and, if that succeeds, recreated
from the same resref. The tag of the area must be its resref. It is not
reloaded if players are in it, or if it holds the module’s starting location.
An area that is not loaded is created, unless a player is changing areas at
that moment.
Other resources are ignored, as refreshing them could disrupt testing or cause
confusing temporary bugs; ff_u_log_reload logs them.
Variables
ENABLE__FF_U_AREA_RELOAD: (string) (opt-out) Set to "N" on module to disable the unit.
Source code
// @code
#include "ff_i_core"
const string ENABLE__FF_U_AREA_RELOAD = "ENABLE__FF_U_AREA_RELOAD";
//! @brief Seconds between the area modification and its reload.
const float RELOAD_AREA_DELAY = 1.0;
// -----------------------------------------------------------------------------
//! @brief Schedule the reload of the area whose .git resource changed.
//! Other resource types are ignored.
//! @param sAction Human-readable action verb ("modified in"). Unused.
//! @param bModified TRUE if the resource was modified. Unused.
void OnResourceChange(string sAction, int bModified);
void OnResourceChange(string sAction, int bModified)
{
/*
Event Data Tag | Type | Notes
---------------|--------|-------
ALIAS | string | NWNX for /nwnx, DEVELOPMENT for /development. Also supports valid aliases from the Custom Resman Definition File
RESREF | string | The ResRef of the file
TYPE | int | The type of the file, see NWNX_UTIL_RESREF_TYPE_*
*/
string sAlias = NWNX_Events_GetEventData("ALIAS");
string sResRef = NWNX_Events_GetEventData("RESREF");
int nType = StringToInt(NWNX_Events_GetEventData("TYPE"));
switch (nType)
{
case NWNX_UTIL_RESREF_TYPE_AREA_GIT:
{
object oModule = GetModule();
AssignCommand(oModule, DelayCommand(RELOAD_AREA_DELAY, RecreateAreaByResRefVoid(sResRef)));
}
break;
default:
return;
}
}
// -----------------------------------------------------------------------------
void main()
{
string sEvent = NWNX_Events_GetCurrentEvent();
if (sEvent == ON_REGISTER)
{
if (!GetModuleFlag(ENABLE__FF_U_AREA_RELOAD, TRUE))
return;
SubscribeToEvent(ON_RESOURCE_MODIFIED, __FILE__);
}
else if (sEvent == ON_RESOURCE_MODIFIED)
OnResourceChange("modified in", TRUE);
}