forked from Mirrors/openclonk
Allow C4ScriptHost to load a script from memory
This will allow mape to feed the Map.c that is being edited directly to the map generator.issue1247
parent
62f8b75d25
commit
92720cf490
|
@ -550,6 +550,12 @@ bool C4MapScriptHost::Load(C4Group & g, const char * f, const char * l, C4LangSt
|
|||
return C4ScriptHost::Load(g, f, l, t);
|
||||
}
|
||||
|
||||
bool C4MapScriptHost::LoadData(const char * f, const char * d, C4LangStringTable * t)
|
||||
{
|
||||
assert(LayerPrototype && MapPrototype);
|
||||
return C4ScriptHost::LoadData(f, d, t);
|
||||
}
|
||||
|
||||
void C4MapScriptHost::Clear()
|
||||
{
|
||||
delete LayerPrototype; delete MapPrototype;
|
||||
|
|
|
@ -328,6 +328,7 @@ public:
|
|||
void InitFunctionMap(C4AulScriptEngine *pEngine);
|
||||
virtual void AddEngineFunctions();
|
||||
virtual bool Load(C4Group &, const char *, const char *, C4LangStringTable *);
|
||||
virtual bool LoadData(const char *, const char *, C4LangStringTable *);
|
||||
void Clear();
|
||||
virtual C4PropListStatic * GetPropList();
|
||||
bool InitializeMap(C4Group &group, CSurface8 **pmap_surface);
|
||||
|
@ -336,4 +337,4 @@ public:
|
|||
|
||||
extern C4MapScriptHost MapScript;
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
|
|
@ -205,4 +205,5 @@ C4MapScriptHost::~C4MapScriptHost() {}
|
|||
void C4MapScriptHost::Clear() {}
|
||||
C4PropListStatic *C4MapScriptHost::GetPropList() {return NULL;}
|
||||
bool C4MapScriptHost::Load(C4Group &, const char *, const char *, C4LangStringTable *) { return false; }
|
||||
bool C4MapScriptHost::LoadData(const char *, const char *, C4LangStringTable *) { return false; }
|
||||
void C4MapScriptHost::AddEngineFunctions() {}
|
||||
|
|
|
@ -71,6 +71,23 @@ bool C4ScriptHost::Load(C4Group &hGroup, const char *szFilename,
|
|||
return fSuccess;
|
||||
}
|
||||
|
||||
bool C4ScriptHost::LoadData(const char *szFilename, const char *szData, class C4LangStringTable *pLocalTable)
|
||||
{
|
||||
stringTable = pLocalTable;
|
||||
ScriptName.Copy(szFilename);
|
||||
|
||||
StdStrBuf tempScript;
|
||||
tempScript.Copy(szData);
|
||||
|
||||
Script.Clear();
|
||||
if(stringTable)
|
||||
stringTable->ReplaceStrings(tempScript, Script);
|
||||
else
|
||||
Script.Take(tempScript);
|
||||
|
||||
Preparse();
|
||||
return true;
|
||||
}
|
||||
|
||||
void C4ScriptHost::MakeScript()
|
||||
{
|
||||
|
@ -218,6 +235,17 @@ bool C4GameScriptHost::Load(C4Group & g, const char * f, const char * l, C4LangS
|
|||
return C4ScriptHost::Load(g, f, l, t);
|
||||
}
|
||||
|
||||
bool C4GameScriptHost::LoadData(const char * f, const char * d, C4LangStringTable * t)
|
||||
{
|
||||
assert(ScriptEngine.GetPropList());
|
||||
C4PropListStatic * pScen = new C4PropListScen(NULL, &::Strings.P[P_Scenario]);
|
||||
ScenPropList.SetPropList(pScen);
|
||||
::ScriptEngine.RegisterGlobalConstant("Scenario", ScenPropList);
|
||||
ScenPrototype.SetPropList(pScen->GetPrototype());
|
||||
Reg2List(&ScriptEngine);
|
||||
return C4ScriptHost::LoadData(f, d, t);
|
||||
}
|
||||
|
||||
void C4GameScriptHost::Clear()
|
||||
{
|
||||
C4ScriptHost::Clear();
|
||||
|
|
|
@ -33,6 +33,7 @@ public:
|
|||
void Clear();
|
||||
virtual bool Load(C4Group &hGroup, const char *szFilename,
|
||||
const char *szLanguage, C4LangStringTable *pLocalTable);
|
||||
virtual bool LoadData(const char *szFilename, const char *szData, class C4LangStringTable *pLocalTable);
|
||||
const char *GetScript() const { return Script.getData(); }
|
||||
virtual C4ScriptHost * GetScriptHost() { return this; }
|
||||
std::list<C4ScriptHost *> SourceScripts;
|
||||
|
@ -106,6 +107,7 @@ public:
|
|||
C4GameScriptHost();
|
||||
~C4GameScriptHost();
|
||||
virtual bool Load(C4Group &, const char *, const char *, C4LangStringTable *);
|
||||
virtual bool LoadData(const char *, const char *, C4LangStringTable *);
|
||||
void Clear();
|
||||
virtual C4PropListStatic * GetPropList();
|
||||
C4Value Call(const char *szFunction, C4AulParSet *pPars=0, bool fPassError=false);
|
||||
|
|
|
@ -104,6 +104,7 @@ C4MapScriptHost::~C4MapScriptHost() {}
|
|||
void C4MapScriptHost::Clear() {}
|
||||
C4PropListStatic *C4MapScriptHost::GetPropList() {return NULL;}
|
||||
bool C4MapScriptHost::Load(C4Group &, const char *, const char *, C4LangStringTable *) { return false; }
|
||||
bool C4MapScriptHost::LoadData(const char *, const char *, C4LangStringTable *) { return false; }
|
||||
void C4MapScriptHost::AddEngineFunctions() {}
|
||||
|
||||
int c4s_runscript(const char * filename)
|
||||
|
|
Loading…
Reference in New Issue