1
0
mirror of https://github.com/OpenTTD/OpenTTD synced 2026-01-23 12:14:11 +01:00

Add: [Script] Framework for loading/saving selected ScriptObject

This commit is contained in:
glx22
2025-02-14 02:19:36 +01:00
committed by Loïc Guilloux
parent 8d63aea929
commit d6a261439b
7 changed files with 86 additions and 6 deletions

View File

@@ -9,7 +9,17 @@
${SQUIRREL_INCLUDES}
static SQInteger ${APIUC}ObjectConstructor(HSQUIRRELVM vm)
{
return sq_throwerror(vm, "${APIUC}Object is not instantiable");
}
void SQ${APIUC}_RegisterAll(Squirrel *engine)
{
DefSQClass<ScriptObject, ScriptType::${APIUC}> SQ${APIUC}Object("${APIUC}Object");
SQ${APIUC}Object.PreRegister(engine);
SQ${APIUC}Object.DefSQAdvancedStaticMethod(engine, &${APIUC}ObjectConstructor, "constructor");
SQ${APIUC}Object.PostRegister(engine);
${SQUIRREL_REGISTER}
}

View File

@@ -84,6 +84,22 @@ protected:
static ScriptInstance *active; ///< The global current active instance.
};
/**
* Save this object.
* Must push 2 elements on the stack:
* - the name (classname without "Script") of the object (OT_STRING)
* - the data for the object (any supported types)
* @return True iff saving this type is supported.
*/
virtual bool SaveObject(HSQUIRRELVM) { return false; }
/**
* Load this object.
* The data for the object must be pushed on the stack before the call.
* @return True iff loading this type is supported.
*/
virtual bool LoadObject(HSQUIRRELVM) { return false; }
public:
/**
* Store the latest result of a DoCommand per company.