root.assetFrames & assets.frames
This commit is contained in:
parent
764751a825
commit
ca48a137ec
@ -76,7 +76,9 @@ Returns the asset source path of an asset, or nil if the asset doesn't exist. If
|
|||||||
Without metadata: Returns an array with all the asset source paths.
|
Without metadata: Returns an array with all the asset source paths.
|
||||||
With metadata: Returns a table, key/value being source path/metadata.
|
With metadata: Returns a table, key/value being source path/metadata.
|
||||||
|
|
||||||
#### `?` root.assetImage(`String` image)
|
#### `Image` root.assetImage(`String` image)
|
||||||
|
|
||||||
|
#### `Json` root.assetFrames(`String` path)
|
||||||
|
|
||||||
*TODO*
|
*TODO*
|
||||||
|
|
||||||
|
@ -102,6 +102,14 @@ Maybe<RectU> FramesSpecification::getRect(String const& frame) const {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Json FramesSpecification::toJson() const {
|
||||||
|
return JsonObject{
|
||||||
|
{"aliases", jsonFromMap(aliases)},
|
||||||
|
{"frames", jsonFromMapV(frames, jsonFromRectU)},
|
||||||
|
{"file", framesFile}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
Assets::Assets(Settings settings, StringList assetSources) {
|
Assets::Assets(Settings settings, StringList assetSources) {
|
||||||
const char* AssetsPatchSuffix = ".patch";
|
const char* AssetsPatchSuffix = ".patch";
|
||||||
const char* AssetsPatchListSuffix = ".patchlist";
|
const char* AssetsPatchListSuffix = ".patchlist";
|
||||||
@ -139,6 +147,12 @@ Assets::Assets(Settings settings, StringList assetSources) {
|
|||||||
return *assetImage;
|
return *assetImage;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
callbacks.registerCallback("frames", [this](String const& path) -> Json {
|
||||||
|
if (auto frames = imageFrames(path))
|
||||||
|
return frames->toJson();
|
||||||
|
return Json();
|
||||||
|
});
|
||||||
|
|
||||||
callbacks.registerCallback("scan", [this](Maybe<String> const& a, Maybe<String> const& b) -> StringList {
|
callbacks.registerCallback("scan", [this](Maybe<String> const& a, Maybe<String> const& b) -> StringList {
|
||||||
return b ? scan(a.value(), *b) : scan(a.value());
|
return b ? scan(a.value(), *b) : scan(a.value());
|
||||||
});
|
});
|
||||||
|
@ -27,7 +27,8 @@ struct FramesSpecification {
|
|||||||
// Get the target sub-rect of a given frame name (which can be an alias).
|
// Get the target sub-rect of a given frame name (which can be an alias).
|
||||||
// Returns nothing if the frame name is not found.
|
// Returns nothing if the frame name is not found.
|
||||||
Maybe<RectU> getRect(String const& frame) const;
|
Maybe<RectU> getRect(String const& frame) const;
|
||||||
|
// Converts to Json.
|
||||||
|
Json toJson() const;
|
||||||
// The full path to the .frames file from which this was loaded.
|
// The full path to the .frames file from which this was loaded.
|
||||||
String framesFile;
|
String framesFile;
|
||||||
// Named sub-frames
|
// Named sub-frames
|
||||||
|
@ -33,6 +33,7 @@ LuaCallbacks LuaBindings::makeRootCallbacks() {
|
|||||||
|
|
||||||
callbacks.registerCallbackWithSignature<String, String>("assetData", bind(RootCallbacks::assetData, root, _1));
|
callbacks.registerCallbackWithSignature<String, String>("assetData", bind(RootCallbacks::assetData, root, _1));
|
||||||
callbacks.registerCallbackWithSignature<Image, String>("assetImage", bind(RootCallbacks::assetImage, root, _1));
|
callbacks.registerCallbackWithSignature<Image, String>("assetImage", bind(RootCallbacks::assetImage, root, _1));
|
||||||
|
callbacks.registerCallbackWithSignature<Json, String>("assetFrames", bind(RootCallbacks::assetFrames, root, _1));
|
||||||
callbacks.registerCallbackWithSignature<Json, String>("assetJson", bind(RootCallbacks::assetJson, root, _1));
|
callbacks.registerCallbackWithSignature<Json, String>("assetJson", bind(RootCallbacks::assetJson, root, _1));
|
||||||
callbacks.registerCallbackWithSignature<Json, String, Json>("makeCurrentVersionedJson", bind(RootCallbacks::makeCurrentVersionedJson, root, _1, _2));
|
callbacks.registerCallbackWithSignature<Json, String, Json>("makeCurrentVersionedJson", bind(RootCallbacks::makeCurrentVersionedJson, root, _1, _2));
|
||||||
callbacks.registerCallbackWithSignature<Json, Json, String>("loadVersionedJson", bind(RootCallbacks::loadVersionedJson, root, _1, _2));
|
callbacks.registerCallbackWithSignature<Json, Json, String>("loadVersionedJson", bind(RootCallbacks::loadVersionedJson, root, _1, _2));
|
||||||
@ -262,6 +263,12 @@ Image LuaBindings::RootCallbacks::assetImage(Root* root, String const& path) {
|
|||||||
return *root->assets()->image(path);
|
return *root->assets()->image(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Json LuaBindings::RootCallbacks::assetFrames(Root* root, String const& path) {
|
||||||
|
if (auto frames = root->assets()->imageFrames(path))
|
||||||
|
return frames->toJson();
|
||||||
|
return Json();
|
||||||
|
}
|
||||||
|
|
||||||
Json LuaBindings::RootCallbacks::assetJson(Root* root, String const& path) {
|
Json LuaBindings::RootCallbacks::assetJson(Root* root, String const& path) {
|
||||||
return root->assets()->json(path);
|
return root->assets()->json(path);
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,7 @@ namespace LuaBindings {
|
|||||||
namespace RootCallbacks {
|
namespace RootCallbacks {
|
||||||
String assetData(Root* root, String const& path);
|
String assetData(Root* root, String const& path);
|
||||||
Image assetImage(Root* root, String const& path);
|
Image assetImage(Root* root, String const& path);
|
||||||
|
Json assetFrames(Root* root, String const& path);
|
||||||
Json assetJson(Root* root, String const& path);
|
Json assetJson(Root* root, String const& path);
|
||||||
Json makeCurrentVersionedJson(Root* root, String const& identifier, Json const& content);
|
Json makeCurrentVersionedJson(Root* root, String const& identifier, Json const& content);
|
||||||
Json loadVersionedJson(Root* root, Json const& versionedJson, String const& expectedIdentifier);
|
Json loadVersionedJson(Root* root, Json const& versionedJson, String const& expectedIdentifier);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user