|
14 | 14 | #include "MovableObject.h"
|
15 | 15 | #include "PresetMan.h"
|
16 | 16 | #include "SceneMan.h"
|
| 17 | +#include "ConsoleMan.h" |
17 | 18 | #include "SettingsMan.h"
|
18 | 19 | #include "LuaMan.h"
|
19 | 20 | #include "Atom.h"
|
@@ -556,11 +557,79 @@ int MovableObject::ReloadScripts() {
|
556 | 557 |
|
557 | 558 | return status;
|
558 | 559 | }
|
| 560 | + |
| 561 | +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 562 | + |
| 563 | +bool MovableObject::AddScript(std::string const &scriptPath) { |
| 564 | + switch (LoadScript(scriptPath)) { |
| 565 | + case 0: |
| 566 | + // If we have a ScriptObjectName that means Create has already been run for pre-existing scripts. Run it right away for this one. |
| 567 | + if (!m_ScriptObjectName.empty() &&g_LuaMan.RunFunctionInPresetScript("Create", scriptPath, m_ScriptPresetName, m_ScriptObjectName) < 0) { |
| 568 | + g_ConsoleMan.PrintString("ERROR: Failed to run Create function for newly added script with path " + scriptPath); |
| 569 | + return false; |
| 570 | + } |
| 571 | + return true; |
| 572 | + case -1: |
| 573 | + g_ConsoleMan.PrintString("ERROR: The script path was empty."); |
| 574 | + break; |
| 575 | + case -2: |
| 576 | + g_ConsoleMan.PrintString("ERROR: The script path " + scriptPath + " is already loaded onto this object."); |
| 577 | + break; |
| 578 | + case -3: |
| 579 | + g_ConsoleMan.PrintString("ERROR: Failed to do necessary setup to add scripts while attempting to add the script with path " + scriptPath + ". This has nothing to do with your script, please report it to a developer."); |
| 580 | + break; |
| 581 | + default: |
| 582 | + RTEAbort("Reached default case while adding script. This should never happen!"); |
| 583 | + break; |
| 584 | + } |
| 585 | + return false; |
| 586 | +} |
| 587 | + |
| 588 | +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 589 | + |
| 590 | +bool MovableObject::RemoveScript(std::string const &scriptPath) { |
| 591 | + auto scriptEntryIterator = FindScript(scriptPath); |
| 592 | + if (scriptEntryIterator != m_LoadedScripts.end()) { |
| 593 | + m_LoadedScripts.erase(scriptEntryIterator); |
| 594 | + return true; |
| 595 | + } |
| 596 | + return false; |
| 597 | +} |
| 598 | + |
| 599 | +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 600 | + |
| 601 | +bool MovableObject::EnableScript(std::string const &scriptPath) { |
| 602 | + auto scriptEntryIterator = FindScript(scriptPath); |
| 603 | + if (scriptEntryIterator != m_LoadedScripts.end() && scriptEntryIterator->second == false) { |
| 604 | + scriptEntryIterator->second = true; |
| 605 | + |
| 606 | + if (g_LuaMan.RunFunctionInPresetScript("OnEnableScript", scriptPath, m_ScriptPresetName, m_ScriptObjectName) < 0) { |
| 607 | + g_ConsoleMan.PrintString("ERROR: Failed to run OnEnableScript function for newly enabled script with path " + scriptPath); |
| 608 | + return false; |
| 609 | + } |
| 610 | + return true; |
559 | 611 | }
|
| 612 | + return false; |
| 613 | +} |
| 614 | + |
| 615 | +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 616 | + |
| 617 | +bool MovableObject::DisableScript(std::string const &scriptPath) { |
| 618 | + auto scriptEntryIterator = FindScript(scriptPath); |
| 619 | + if (scriptEntryIterator != m_LoadedScripts.end() && scriptEntryIterator->second == true) { |
| 620 | + scriptEntryIterator->second = false; |
560 | 621 |
|
561 |
| - return error; |
| 622 | + if (g_LuaMan.RunFunctionInPresetScript("OnDisableScript", scriptPath, m_ScriptPresetName, m_ScriptObjectName) < 0) { |
| 623 | + g_ConsoleMan.PrintString("ERROR: Failed to run OnDisableScript function for newly disabled script with path " + scriptPath); |
| 624 | + return false; |
| 625 | + } |
| 626 | + return true; |
| 627 | + } |
| 628 | + return false; |
562 | 629 | }
|
563 | 630 |
|
| 631 | +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 632 | + |
564 | 633 | /*
|
565 | 634 | //////////////////////////////////////////////////////////////////////////////////////////
|
566 | 635 | // Constructor: MovableObject
|
|
0 commit comments