Skip to content
This repository was archived by the owner on Jan 5, 2024. It is now read-only.

Commit 01f7d08

Browse files
committed
Made SetPresetName reset scriptPresetName on MO so it correctly clears that with CopyOfs in INI. This is necessary for multiple scripts to properly function.
Made entity ini reading call SetPresetName instead of using the >> operator Added some multiscript handling safety to ScriptPath ini property in MO
1 parent d89cc44 commit 01f7d08

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

Entities/MovableObject.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -330,9 +330,10 @@ int MovableObject::ReadProperty(std::string propName, Reader &reader)
330330
}
331331
else if (propName == "ScriptPath")
332332
{
333-
reader >> m_ScriptPath;
334-
// Read in the Lua script function definitions for this preset
335-
LoadScripts(m_ScriptPath);
333+
std::string scriptPath = reader.ReadPropValue();
334+
if (LoadScript(scriptPath) == -2) {
335+
reader.ReportError("Duplicate script path " + scriptPath);
336+
}
336337
}
337338
else if (propName == "ScreenEffect")
338339
{

Entities/MovableObject.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,12 @@ ENTITYALLOCATION(MovableObject)
250250

251251
virtual const Entity::ClassInfo & GetClass() const { return m_sClass; }
252252

253+
/// <summary>
254+
/// Override SetPresetName so it also resets script paths and script preset name. Note that this'll screw up lua that calls SetPresetName but that probably shouldn't be lua accessible anyway.
255+
/// </summary>
256+
/// <param name="newName">A string reference with the instance name of this Entity.</param>
257+
virtual void SetPresetName(const std::string &newName) override { Entity::SetPresetName(newName); m_ScriptPresetName.clear(); }
258+
253259

254260
//////////////////////////////////////////////////////////////////////////////////////////
255261
// Virtual method: GetClassName

System/Entity.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ namespace RTE {
6565
m_DefinedInModule = reader.GetReadModuleID();
6666
}
6767
} else if (propName == "PresetName" || propName == "InstanceName") {
68-
reader >> m_PresetName;
68+
SetPresetName(reader.ReadPropValue());
6969
// Preset name might have "[ModuleName]/" preceding it, detect it here and select proper module!
7070
int slashPos = m_PresetName.find_first_of('/');
7171
if (slashPos != std::string::npos) { m_PresetName = m_PresetName.substr(slashPos + 1); }

0 commit comments

Comments
 (0)