From 8eb3f8b3d802f0bb612f7c1e082d083c34ca472d Mon Sep 17 00:00:00 2001 From: Rojikku98 <be.edvin@gmail.com> Date: Sat, 25 Jul 2020 15:00:25 +0200 Subject: [PATCH] Det fungerar! --- python-api-src/lib_replay_unit.cpp | 34 +----------------------------- python-api-src/library.cpp | 9 ++------ src/IDAReplayObserver.cpp | 9 +++++++- src/IDAReplayObserver.h | 4 +++- src/UnitInformation.cpp | 6 +----- 5 files changed, 15 insertions(+), 47 deletions(-) diff --git a/python-api-src/lib_replay_unit.cpp b/python-api-src/lib_replay_unit.cpp index 4332916..0266b98 100644 --- a/python-api-src/lib_replay_unit.cpp +++ b/python-api-src/lib_replay_unit.cpp @@ -5,37 +5,5 @@ namespace py = pybind11; void define_replay_unit(py::module & m) { py::class_<UnitInformation>(m, "ReplayUnit") - .def_property_readonly("unit_type", &Unit::getType, "The :class:`library.UnitType` of the unit") - .def_property_readonly("position", &Unit::getPosition, "The :class:`library.Point2D` of the unit") - .def_property_readonly("tile_position", &Unit::getTilePosition, "The :class:`library.Point2DI` of the unit") - .def_property_readonly("hit_points", &Unit::getHitPoints) - .def_property_readonly("shields", &Unit::getShields) - .def_property_readonly("energy", &Unit::getEnergy) - .def_property_readonly("player", &Unit::getPlayer) - .def_property_readonly("id", &Unit::getID) - .def_property_readonly("build_percentage", &Unit::getBuildPercentage) - .def_property_readonly("weapon_cooldown", &Unit::getWeaponCooldown) - .def_property_readonly("is_completed", &Unit::isCompleted) - .def_property_readonly("is_being_constructed", &Unit::isBeingConstructed) - .def_property_readonly("is_cloaked", &Unit::isCloaked) - .def_property_readonly("is_flying", &Unit::isFlying) - .def_property_readonly("buffs", &Unit::buffs) - .def_property_readonly("is_alive", &Unit::isAlive) - .def_property_readonly("is_powered", &Unit::isPowered) - .def_property_readonly("is_idle", &Unit::isIdle) - .def_property_readonly("is_burrowed", &Unit::isBurrowed) - .def_property_readonly("is_valid", &Unit::isValid) - .def_property_readonly("is_training", &Unit::isTraining) - .def_property_readonly("is_blip", &Unit::isBlip) - .def_property_readonly("target", &Unit::getTarget) - .def_property_readonly("has_target", &Unit::hasTarget) - .def_property_readonly("max_hit_points", &Unit::getMaxHitPoints) - .def_property_readonly("progress", &Unit::getProgress) - .def_property_readonly("current_ability_id", &Unit::getCurrentAbilityID, "The AbilityID of currently used ability") - .def_property_readonly("facing", &Unit::getFacing) - .def_property_readonly("radius", &Unit::getRadius) - .def_property_readonly("is_carrying_minerals", &Unit::isCarryingMinerals) - .def("__hash__", [](const Unit & unit) { return std::hash<const sc2::Unit *>{}(unit.getUnitPtr()); }) - .def(py::self == py::self) - .def("__repr__", [](const Unit & unit) { return "<Unit of type: '" + unit.getType().getName() + "'>"; }); + .def_property_readonly("id", &Unit::getID); } diff --git a/python-api-src/library.cpp b/python-api-src/library.cpp index 4e53cd5..5e157b7 100644 --- a/python-api-src/library.cpp +++ b/python-api-src/library.cpp @@ -89,14 +89,9 @@ PYBIND11_MODULE(library, m) .def_property_readonly("current_frame", &IDABot::GetCurrentFrame, "Which frame we are currently on"); - py::class_<sc2::ReplayObserver>(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::class_<sc2::ReplayObserver>(m, "ReplayObserver") - //.def(py::init()); + py::class_<sc2::ReplayObserver>(m, "ReplayObserver") + .def(py::init()); py::class_<IDAReplayObserver, PyReplayObserver, sc2::ReplayObserver>(m, "IDAReplayObserver") .def(py::init()) diff --git a/src/IDAReplayObserver.cpp b/src/IDAReplayObserver.cpp index 336f998..75cfa06 100644 --- a/src/IDAReplayObserver.cpp +++ b/src/IDAReplayObserver.cpp @@ -3,13 +3,15 @@ void IDAReplayObserver::setUnits() { - std::cout << "setunits" << std::endl; + m_allUnits.clear(); Control()->GetObservation(); for (auto & unit : Observation()->GetUnits()) { m_allUnits.push_back(UnitInformation(unit, *this)); } + + } IDAReplayObserver::IDAReplayObserver(): @@ -19,18 +21,23 @@ IDAReplayObserver::IDAReplayObserver(): void IDAReplayObserver::OnGameStart() { + + setUnits(); } void IDAReplayObserver::OnStep() { + setUnits(); + } const std::vector<UnitInformation>& IDAReplayObserver::GetAllUnits() const { + return m_allUnits; } diff --git a/src/IDAReplayObserver.h b/src/IDAReplayObserver.h index fda4798..88ca4e0 100644 --- a/src/IDAReplayObserver.h +++ b/src/IDAReplayObserver.h @@ -11,7 +11,7 @@ class UnitInformation; class IDAReplayObserver : public sc2::ReplayObserver { - std::vector<UnitInformation> m_allUnits; + void setUnits(); @@ -19,6 +19,8 @@ class IDAReplayObserver : public sc2::ReplayObserver public: IDAReplayObserver(); + std::vector<UnitInformation> m_allUnits; + void OnGameStart() override; void OnStep() override; diff --git a/src/UnitInformation.cpp b/src/UnitInformation.cpp index ab768b3..438682a 100644 --- a/src/UnitInformation.cpp +++ b/src/UnitInformation.cpp @@ -8,8 +8,4 @@ UnitInformation::UnitInformation(const sc2::Unit * unit, IDAReplayObserver & rep } -const UnitType & UnitInformation::getType() const -{ - //m_replayObserver->Observation() - // TODO: insert return statement here1 -} + -- GitLab