From 42a13a5667cdb1d1210f3848344bfc4c76807b03 Mon Sep 17 00:00:00 2001
From: Rojikku98 <be.edvin@gmail.com>
Date: Tue, 14 Jul 2020 15:11:14 +0200
Subject: [PATCH] Added support for launching  a replay from python. The
 methods onStep and onGameCreated

---
 python-api-src/library.cpp | 10 +++++++++-
 python-api-src/library.h   | 26 +++++++++++++++++++++++++-
 2 files changed, 34 insertions(+), 2 deletions(-)

diff --git a/python-api-src/library.cpp b/python-api-src/library.cpp
index dd1bc0c..75ff7e3 100644
--- a/python-api-src/library.cpp
+++ b/python-api-src/library.cpp
@@ -26,7 +26,15 @@ PYBIND11_MODULE(library, m)
         .def("launch_starcraft", &sc2::Coordinator::LaunchStarcraft)
         .def("start_game", &sc2::Coordinator::StartGame, "map_path"_a)
         .def("update", &sc2::Coordinator::Update)
-        .def("set_real_time", &sc2::Coordinator::SetRealtime);
+        .def("set_real_time", &sc2::Coordinator::SetRealtime)
+		.def("load_replay_list",&sc2::Coordinator::SetReplayPath, "replay_path"_a)
+		.def("add_replay_observer",&sc2::Coordinator::AddReplayObserver, "replay_observer"_a)
+		;
+	py::class_<sc2::ReplayObserver, PyReplayObserver>(m, "ReplayObserver")
+		.def(py::init())
+		.def("on_game_start", &sc2::ReplayObserver::OnGameStart)
+		.def("on_step",&sc2::ReplayObserver::OnStep)
+		.def("on_game_end",&sc2::ReplayObserver::OnGameEnd);
 
     py::enum_<sc2::Race>(m, "Race")
         .value("Terran", sc2::Race::Terran)
diff --git a/python-api-src/library.h b/python-api-src/library.h
index fb671e1..7c00a3f 100644
--- a/python-api-src/library.h
+++ b/python-api-src/library.h
@@ -21,7 +21,8 @@ public:
     }
 
     Coordinator(std::string path) : sc2::Coordinator()
-    {
+    {	
+		std::cout << path << std::endl;
         std::vector<std::string> arguments = { "pycommandcenter", "-e", path };
         CustomLoadSettings(arguments);
     }
@@ -61,6 +62,29 @@ public:
     }
 };
 
+class PyReplayObserver : public sc2::ReplayObserver
+{
+public:
+	void OnGameStart() override
+	{
+		PYBIND11_OVERLOAD_NAME(
+			void,
+			sc2::ReplayObserver,
+			"on_game_start",
+			OnGameStart
+		);
+	}
+	void OnStep() override
+	{
+		PYBIND11_OVERLOAD_NAME(
+			void,
+			sc2::ReplayObserver,
+			"on_step",
+			OnStep
+		);
+	}
+};
+
 // The functions below are all defined in different .cpp files, in order 
 // to keep compilation snappy
 void define_typeenums(pybind11::module & m);
-- 
GitLab