#pragma once #include "ScriptAssert.h" #include #include template using callbackSetName = std::function; using callbackRemoveName = std::function; // Use the "curiously recurring template pattern" to allow classes to inherit static members and functions. // T is the class that will both derive and instantiate this base class. S is the type used inside GameScriptWhateverInfo // to actually reference the underlying TombEngine struct. template class GameScriptNamedBase { public: static void SetNameCallbacks(callbackSetName cbs, callbackRemoveName cbr) { s_callbackSetName = cbs; s_callbackRemoveName = cbr; } protected: static callbackSetName s_callbackSetName; static callbackRemoveName s_callbackRemoveName; }; // default callbacks template callbackSetName GameScriptNamedBase::s_callbackSetName = [](std::string const& n, S identifier) { std::string err = "\"Set Name\" callback is not set."; throw TENScriptException(err); return false; }; template callbackRemoveName GameScriptNamedBase::s_callbackRemoveName = [](std::string const& n) { std::string err = "\"Remove Name\" callback is not set."; throw TENScriptException(err); return false; };