diff --git a/rwengine/src/loaders/LoaderIPL.cpp b/rwengine/src/loaders/LoaderIPL.cpp index dbb3259a..deaebf9d 100644 --- a/rwengine/src/loaders/LoaderIPL.cpp +++ b/rwengine/src/loaders/LoaderIPL.cpp @@ -13,17 +13,20 @@ #include "data/InstanceData.hpp" #include "data/ZoneData.hpp" +#include "LoaderIPL.hpp" + #include enum SectionTypes { INST, PICK, CULL, ZONE, NONE }; -/// Load the IPL data into memory bool LoaderIPL::load(const std::string& filename) { std::ifstream str(filename); - if (!str.is_open()) return false; + return load(str); +} +bool LoaderIPL::load(std::istream &str) { SectionTypes section = NONE; while (!str.eof()) { std::string line; @@ -134,3 +137,4 @@ bool LoaderIPL::load(const std::string& filename) { return true; } + diff --git a/rwengine/src/loaders/LoaderIPL.hpp b/rwengine/src/loaders/LoaderIPL.hpp index 5b636f36..4e543576 100644 --- a/rwengine/src/loaders/LoaderIPL.hpp +++ b/rwengine/src/loaders/LoaderIPL.hpp @@ -15,9 +15,12 @@ struct InstanceData; */ class LoaderIPL { public: - /// Load the IPL data into memory + /// Load the IPL data from filename bool load(const std::string& filename); + /// Parse IPL data from the stream + bool load(std::istream& stream); + /// The list of instances from the IPL file std::vector> m_instances; diff --git a/tests/test_LoaderIPL.cpp b/tests/test_LoaderIPL.cpp index 78640413..b766720f 100644 --- a/tests/test_LoaderIPL.cpp +++ b/tests/test_LoaderIPL.cpp @@ -4,21 +4,21 @@ struct WithLoaderIPL { LoaderIPL loader; + + std::ifstream test_data_stream {Global::get().getGamePath() + "/data/gta3.zon"}; }; BOOST_FIXTURE_TEST_SUITE(LoaderIPLTests, WithLoaderIPL) #if RW_TEST_WITH_DATA BOOST_AUTO_TEST_CASE(zone_count_is_correct) { - const auto& gdpath = Global::get().getGamePath(); - BOOST_REQUIRE(loader.load(gdpath + "/data/gta3.zon")); + BOOST_REQUIRE(loader.load(test_data_stream)); BOOST_TEST(loader.zones.size() == 42); } BOOST_AUTO_TEST_CASE(zone_data_is_correct) { - const auto& gdpath = Global::get().getGamePath(); - BOOST_REQUIRE(loader.load(gdpath + "/data/gta3.zon")); + BOOST_REQUIRE(loader.load(test_data_stream)); auto& zone1 = loader.zones[1]; BOOST_TEST(zone1.name == "PORT_W");