Make basic Script class abstract, require implementation of GetName function.
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
5f891cd4ed
commit
a606fbbc7b
|
@ -15,16 +15,14 @@ namespace CreatureLib::Battling {
|
||||||
class Creature;
|
class Creature;
|
||||||
|
|
||||||
class Script {
|
class Script {
|
||||||
const std::string _name;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit Script(std::string name) : _name(std::move(name)) {}
|
explicit Script() {}
|
||||||
virtual ~Script() = default;
|
virtual ~Script() = default;
|
||||||
|
|
||||||
virtual void Stack(){};
|
virtual void Stack(){};
|
||||||
virtual void OnRemove(){};
|
virtual void OnRemove(){};
|
||||||
|
|
||||||
const std::string& GetName() { return _name; }
|
virtual const std::string& GetName() const = 0;
|
||||||
|
|
||||||
virtual void OnBeforeTurn(const BaseTurnChoice* choice){};
|
virtual void OnBeforeTurn(const BaseTurnChoice* choice){};
|
||||||
|
|
||||||
|
|
|
@ -8,8 +8,12 @@ using namespace CreatureLib;
|
||||||
using namespace CreatureLib::Battling;
|
using namespace CreatureLib::Battling;
|
||||||
|
|
||||||
class TestScript : public Script {
|
class TestScript : public Script {
|
||||||
|
private:
|
||||||
|
std::string _name;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit TestScript(std::string name) : Script(std::move(name)){};
|
explicit TestScript(std::string name) : _name(std::move(name)){};
|
||||||
|
const std::string& GetName() const override { return _name; }
|
||||||
|
|
||||||
void TestMethod(int& runCount) { runCount++; }
|
void TestMethod(int& runCount) { runCount++; }
|
||||||
};
|
};
|
||||||
|
|
|
@ -7,6 +7,15 @@
|
||||||
using namespace CreatureLib;
|
using namespace CreatureLib;
|
||||||
using namespace CreatureLib::Battling;
|
using namespace CreatureLib::Battling;
|
||||||
|
|
||||||
|
class TestScript : public Script {
|
||||||
|
private:
|
||||||
|
std::string _name;
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit TestScript(std::string name) : _name(std::move(name)){};
|
||||||
|
const std::string& GetName() const override { return _name; }
|
||||||
|
};
|
||||||
|
|
||||||
TEST_CASE("Empty script set count == 0", "[Battling, Scripting]") {
|
TEST_CASE("Empty script set count == 0", "[Battling, Scripting]") {
|
||||||
auto set = ScriptSet();
|
auto set = ScriptSet();
|
||||||
REQUIRE(set.Count() == 0);
|
REQUIRE(set.Count() == 0);
|
||||||
|
@ -14,14 +23,14 @@ TEST_CASE("Empty script set count == 0", "[Battling, Scripting]") {
|
||||||
|
|
||||||
TEST_CASE("Add script to script set", "[Battling, Scripting]") {
|
TEST_CASE("Add script to script set", "[Battling, Scripting]") {
|
||||||
auto set = ScriptSet();
|
auto set = ScriptSet();
|
||||||
auto s = new Script("foobar");
|
auto s = new TestScript("foobar");
|
||||||
set.Add(s);
|
set.Add(s);
|
||||||
REQUIRE(set.Count() == 1);
|
REQUIRE(set.Count() == 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Add script to script set, then retrieve it", "[Battling, Scripting]") {
|
TEST_CASE("Add script to script set, then retrieve it", "[Battling, Scripting]") {
|
||||||
auto set = ScriptSet();
|
auto set = ScriptSet();
|
||||||
auto s = new Script("foobar");
|
auto s = new TestScript("foobar");
|
||||||
set.Add(s);
|
set.Add(s);
|
||||||
REQUIRE(set.Count() == 1);
|
REQUIRE(set.Count() == 1);
|
||||||
auto get = set.GetIterator()->at(0);
|
auto get = set.GetIterator()->at(0);
|
||||||
|
@ -30,8 +39,8 @@ TEST_CASE("Add script to script set, then retrieve it", "[Battling, Scripting]")
|
||||||
|
|
||||||
TEST_CASE("Add two scripts to script set", "[Battling, Scripting]") {
|
TEST_CASE("Add two scripts to script set", "[Battling, Scripting]") {
|
||||||
auto set = ScriptSet();
|
auto set = ScriptSet();
|
||||||
auto s = new Script("foobar");
|
auto s = new TestScript("foobar");
|
||||||
auto s2 = new Script("foobar2");
|
auto s2 = new TestScript("foobar2");
|
||||||
set.Add(s);
|
set.Add(s);
|
||||||
set.Add(s2);
|
set.Add(s2);
|
||||||
REQUIRE(set.Count() == 2);
|
REQUIRE(set.Count() == 2);
|
||||||
|
@ -39,8 +48,8 @@ TEST_CASE("Add two scripts to script set", "[Battling, Scripting]") {
|
||||||
|
|
||||||
TEST_CASE("Add two scripts to script set, then retrieve them", "[Battling, Scripting]") {
|
TEST_CASE("Add two scripts to script set, then retrieve them", "[Battling, Scripting]") {
|
||||||
auto set = ScriptSet();
|
auto set = ScriptSet();
|
||||||
auto s = new Script("foobar");
|
auto s = new TestScript("foobar");
|
||||||
auto s2 = new Script("foobar2");
|
auto s2 = new TestScript("foobar2");
|
||||||
set.Add(s);
|
set.Add(s);
|
||||||
set.Add(s2);
|
set.Add(s2);
|
||||||
REQUIRE(set.Count() == 2);
|
REQUIRE(set.Count() == 2);
|
||||||
|
@ -52,7 +61,7 @@ TEST_CASE("Add two scripts to script set, then retrieve them", "[Battling, Scrip
|
||||||
|
|
||||||
TEST_CASE("Add script to script set, then remove it", "[Battling, Scripting]") {
|
TEST_CASE("Add script to script set, then remove it", "[Battling, Scripting]") {
|
||||||
auto set = ScriptSet();
|
auto set = ScriptSet();
|
||||||
auto s = new Script("foobar");
|
auto s = new TestScript("foobar");
|
||||||
set.Add(s);
|
set.Add(s);
|
||||||
REQUIRE(set.Count() == 1);
|
REQUIRE(set.Count() == 1);
|
||||||
set.Remove("foobar");
|
set.Remove("foobar");
|
||||||
|
@ -63,8 +72,8 @@ TEST_CASE("Add script to script set, then remove it", "[Battling, Scripting]") {
|
||||||
|
|
||||||
TEST_CASE("Add two scripts to script set, then remove them", "[Battling, Scripting]") {
|
TEST_CASE("Add two scripts to script set, then remove them", "[Battling, Scripting]") {
|
||||||
auto set = ScriptSet();
|
auto set = ScriptSet();
|
||||||
auto s = new Script("foobar");
|
auto s = new TestScript("foobar");
|
||||||
auto s2 = new Script("foobar2");
|
auto s2 = new TestScript("foobar2");
|
||||||
set.Add(s);
|
set.Add(s);
|
||||||
set.Add(s2);
|
set.Add(s2);
|
||||||
REQUIRE(set.Count() == 2);
|
REQUIRE(set.Count() == 2);
|
||||||
|
|
|
@ -9,8 +9,12 @@ using namespace CreatureLib;
|
||||||
using namespace CreatureLib::Battling;
|
using namespace CreatureLib::Battling;
|
||||||
|
|
||||||
class TestScript : public Script {
|
class TestScript : public Script {
|
||||||
|
private:
|
||||||
|
std::string _name;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit TestScript(std::string name) : Script(std::move(name)){};
|
explicit TestScript(std::string name) : _name(std::move(name)){};
|
||||||
|
const std::string& GetName() const override { return _name; }
|
||||||
|
|
||||||
void TestMethod(int& runCount) { runCount++; }
|
void TestMethod(int& runCount) { runCount++; }
|
||||||
};
|
};
|
||||||
|
@ -40,7 +44,7 @@ TEST_CASE("Script source with unset script ptr.", "[Battling, Scripting]") {
|
||||||
|
|
||||||
TEST_CASE("Script source with script ptr being set.", "[Battling, Scripting]") {
|
TEST_CASE("Script source with script ptr being set.", "[Battling, Scripting]") {
|
||||||
auto source = ScriptSourceWithScriptPtr();
|
auto source = ScriptSourceWithScriptPtr();
|
||||||
source.ScriptPtr = new Script("foobar");
|
source.ScriptPtr = new TestScript("foobar");
|
||||||
auto scripts = source.GetScriptIterator();
|
auto scripts = source.GetScriptIterator();
|
||||||
auto first = scripts.GetNext();
|
auto first = scripts.GetNext();
|
||||||
CHECK(first != nullptr);
|
CHECK(first != nullptr);
|
||||||
|
@ -52,7 +56,7 @@ TEST_CASE("Script source with script ptr being set after first iteration.", "[Ba
|
||||||
auto scripts = source.GetScriptIterator();
|
auto scripts = source.GetScriptIterator();
|
||||||
auto first = scripts.GetNext();
|
auto first = scripts.GetNext();
|
||||||
CHECK(first == nullptr);
|
CHECK(first == nullptr);
|
||||||
source.ScriptPtr = new Script("foobar");
|
source.ScriptPtr = new TestScript("foobar");
|
||||||
scripts = source.GetScriptIterator();
|
scripts = source.GetScriptIterator();
|
||||||
first = scripts.GetNext();
|
first = scripts.GetNext();
|
||||||
CHECK(first != nullptr);
|
CHECK(first != nullptr);
|
||||||
|
@ -68,7 +72,7 @@ TEST_CASE("Script source with empty script set.", "[Battling, Scripting]") {
|
||||||
|
|
||||||
TEST_CASE("Script source with single item script set.", "[Battling, Scripting]") {
|
TEST_CASE("Script source with single item script set.", "[Battling, Scripting]") {
|
||||||
auto source = ScriptSourceWithScriptSet();
|
auto source = ScriptSourceWithScriptSet();
|
||||||
auto s = new Script("foobar");
|
auto s = new TestScript("foobar");
|
||||||
source.Set.Add(s);
|
source.Set.Add(s);
|
||||||
auto scripts = source.GetScriptIterator();
|
auto scripts = source.GetScriptIterator();
|
||||||
auto first = scripts.GetNext();
|
auto first = scripts.GetNext();
|
||||||
|
@ -78,8 +82,8 @@ TEST_CASE("Script source with single item script set.", "[Battling, Scripting]")
|
||||||
|
|
||||||
TEST_CASE("Script source with multiple item script set.", "[Battling, Scripting]") {
|
TEST_CASE("Script source with multiple item script set.", "[Battling, Scripting]") {
|
||||||
auto source = ScriptSourceWithScriptSet();
|
auto source = ScriptSourceWithScriptSet();
|
||||||
auto s = new Script("foobar");
|
auto s = new TestScript("foobar");
|
||||||
auto s2 = new Script("foobar2");
|
auto s2 = new TestScript("foobar2");
|
||||||
source.Set.Add(s);
|
source.Set.Add(s);
|
||||||
source.Set.Add(s2);
|
source.Set.Add(s2);
|
||||||
auto scripts = source.GetScriptIterator();
|
auto scripts = source.GetScriptIterator();
|
||||||
|
|
Loading…
Reference in New Issue