Skip to content

Commit

Permalink
feat(engine): import from ~/old in bridge samples
Browse files Browse the repository at this point in the history
  • Loading branch information
Dacops committed Dec 17, 2023
1 parent b91adfd commit 3070643
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 17 deletions.
14 changes: 2 additions & 12 deletions engine/include/cubos/engine/assets/bridges/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,6 @@ namespace cubos::engine
// Deserialize the asset and store it in the asset manager.
T data{};
deserializer.read(data);
if (deserializer.failed())
{
CUBOS_ERROR("Could not deserialize asset from JSON file");
return false;
}

assets.store(handle, std::move(data));
return true;
Expand All @@ -63,16 +58,11 @@ namespace cubos::engine

// Read the asset from the asset manager and serialize it to the file stream.
auto data = assets.read<T>(handle);
serializer.write(*data, nullptr); // JSON serializer does not use names.
if (serializer.failed())
{
CUBOS_ERROR("Could not serialize asset to JSON file");
return false;
}
serializer.write(*data);

// new JSONSerializer() does not receive a stream to write to, need to write to it manually
auto jsonStr = serializer.output().dump();
stream.write(jsonStr.begin(), jsonStr.size());
stream.print(jsonStr);
return true;
}
};
Expand Down
6 changes: 3 additions & 3 deletions engine/samples/assets/json/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <cubos/core/reflection/traits/fields.hpp>
#include <cubos/core/reflection/type.hpp>

#include <cubos/engine/assets/bridges/json.hpp>
#include <cubos/engine/assets/bridges/old/json.hpp>
#include <cubos/engine/assets/plugin.hpp>
#include <cubos/engine/settings/settings.hpp>

Expand Down Expand Up @@ -60,7 +60,7 @@ static void configSystem(Write<Settings> settings)
/// [Register bridge]
static void bridgeSystem(Write<Assets> assets)
{
assets->registerBridge(".strings", std::make_unique<JSONBridge<Strings>>());
assets->registerBridge(".strings", std::make_unique<old::JSONBridge<Strings>>());
}
/// [Register bridge]

Expand Down Expand Up @@ -89,4 +89,4 @@ int main()

cubos.startupSystem(configSystem).tagged("cubos.settings");
cubos.run();
}
}
4 changes: 2 additions & 2 deletions engine/samples/assets/saving/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <cubos/core/reflection/traits/fields.hpp>
#include <cubos/core/reflection/type.hpp>

#include <cubos/engine/assets/bridges/json.hpp>
#include <cubos/engine/assets/bridges/old/json.hpp>
#include <cubos/engine/assets/plugin.hpp>
#include <cubos/engine/settings/settings.hpp>

Expand Down Expand Up @@ -58,7 +58,7 @@ static void configSystem(Write<Settings> settings)

static void bridgeSystem(Write<Assets> assets)
{
assets->registerBridge(".int", std::make_unique<JSONBridge<IntegerAsset>>());
assets->registerBridge(".int", std::make_unique<old::JSONBridge<IntegerAsset>>());
}

/// [Create a new asset]
Expand Down

0 comments on commit 3070643

Please sign in to comment.