mirror of
https://github.com/rive-app/rive-cpp.git
synced 2026-01-18 21:21:17 +01:00
clang-format updates
- Put braces on their own line - Turn off single-line case labels Diffs= 32e79999a clang-format updates
This commit is contained in:
@@ -9,44 +9,57 @@
|
||||
#include "rive/animation/state_machine_input_instance.hpp"
|
||||
#include "utils/no_op_factory.hpp"
|
||||
|
||||
class JSoner {
|
||||
class JSoner
|
||||
{
|
||||
std::vector<bool> m_IsArray;
|
||||
|
||||
void tab() {
|
||||
for (int i = 0; i < m_IsArray.size(); ++i) {
|
||||
void tab()
|
||||
{
|
||||
for (int i = 0; i < m_IsArray.size(); ++i)
|
||||
{
|
||||
printf("\t");
|
||||
}
|
||||
}
|
||||
void add_c(const char key[], char c) {
|
||||
void add_c(const char key[], char c)
|
||||
{
|
||||
this->tab();
|
||||
if (key) {
|
||||
if (key)
|
||||
{
|
||||
printf("\"%s\": %c\n", key, c);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("%c\n", c);
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
JSoner() {}
|
||||
~JSoner() {
|
||||
while (!m_IsArray.empty()) {
|
||||
~JSoner()
|
||||
{
|
||||
while (!m_IsArray.empty())
|
||||
{
|
||||
this->pop();
|
||||
}
|
||||
}
|
||||
|
||||
void add(const char key[], const char value[]) {
|
||||
void add(const char key[], const char value[])
|
||||
{
|
||||
this->tab();
|
||||
printf("\"%s\": \"%s\"\n", key, value);
|
||||
}
|
||||
void pushArray(const char key[] = nullptr) {
|
||||
void pushArray(const char key[] = nullptr)
|
||||
{
|
||||
this->add_c(key, '[');
|
||||
m_IsArray.push_back(true);
|
||||
}
|
||||
void pushStruct(const char key[] = nullptr) {
|
||||
void pushStruct(const char key[] = nullptr)
|
||||
{
|
||||
this->add_c(key, '{');
|
||||
m_IsArray.push_back(false);
|
||||
}
|
||||
void pop() {
|
||||
void pop()
|
||||
{
|
||||
assert(!m_IsArray.empty());
|
||||
char c = m_IsArray.front() ? ']' : '}';
|
||||
m_IsArray.pop_back();
|
||||
@@ -60,7 +73,8 @@ public:
|
||||
|
||||
//////////////////////////////////////////////////
|
||||
|
||||
static void dump(JSoner& js, rive::LinearAnimationInstance* anim) {
|
||||
static void dump(JSoner& js, rive::LinearAnimationInstance* anim)
|
||||
{
|
||||
js.pushStruct();
|
||||
js.add("name", anim->name().c_str());
|
||||
js.add("duration", std::to_string(anim->durationSeconds()).c_str());
|
||||
@@ -68,12 +82,15 @@ static void dump(JSoner& js, rive::LinearAnimationInstance* anim) {
|
||||
js.pop();
|
||||
}
|
||||
|
||||
static void dump(JSoner& js, rive::StateMachineInstance* smi) {
|
||||
static void dump(JSoner& js, rive::StateMachineInstance* smi)
|
||||
{
|
||||
js.pushStruct();
|
||||
js.add("name", smi->name().c_str());
|
||||
if (auto count = smi->inputCount()) {
|
||||
if (auto count = smi->inputCount())
|
||||
{
|
||||
js.pushArray("inputs");
|
||||
for (auto i = 0; i < count; ++i) {
|
||||
for (auto i = 0; i < count; ++i)
|
||||
{
|
||||
auto inp = smi->input(i);
|
||||
js.add("name", inp->name().c_str());
|
||||
}
|
||||
@@ -82,19 +99,24 @@ static void dump(JSoner& js, rive::StateMachineInstance* smi) {
|
||||
js.pop();
|
||||
}
|
||||
|
||||
static void dump(JSoner& js, rive::ArtboardInstance* abi) {
|
||||
static void dump(JSoner& js, rive::ArtboardInstance* abi)
|
||||
{
|
||||
js.pushStruct();
|
||||
js.add("name", abi->name().c_str());
|
||||
if (auto count = abi->animationCount()) {
|
||||
if (auto count = abi->animationCount())
|
||||
{
|
||||
js.pushArray("animations");
|
||||
for (size_t i = 0; i < count; ++i) {
|
||||
for (size_t i = 0; i < count; ++i)
|
||||
{
|
||||
dump(js, abi->animationAt(i).get());
|
||||
}
|
||||
js.pop();
|
||||
}
|
||||
if (auto count = abi->stateMachineCount()) {
|
||||
if (auto count = abi->stateMachineCount())
|
||||
{
|
||||
js.pushArray("machines");
|
||||
for (size_t i = 0; i < count; ++i) {
|
||||
for (size_t i = 0; i < count; ++i)
|
||||
{
|
||||
dump(js, abi->stateMachineAt(i).get());
|
||||
}
|
||||
js.pop();
|
||||
@@ -102,18 +124,22 @@ static void dump(JSoner& js, rive::ArtboardInstance* abi) {
|
||||
js.pop();
|
||||
}
|
||||
|
||||
static void dump(JSoner& js, rive::File* file) {
|
||||
static void dump(JSoner& js, rive::File* file)
|
||||
{
|
||||
auto count = file->artboardCount();
|
||||
js.pushArray("artboards");
|
||||
for (size_t i = 0; i < count; ++i) {
|
||||
for (size_t i = 0; i < count; ++i)
|
||||
{
|
||||
dump(js, file->artboardAt(i).get());
|
||||
}
|
||||
js.pop();
|
||||
}
|
||||
|
||||
static std::unique_ptr<rive::File> open_file(const char name[]) {
|
||||
static std::unique_ptr<rive::File> open_file(const char name[])
|
||||
{
|
||||
FILE* f = fopen(name, "rb");
|
||||
if (!f) {
|
||||
if (!f)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -123,7 +149,8 @@ static std::unique_ptr<rive::File> open_file(const char name[]) {
|
||||
|
||||
std::vector<uint8_t> bytes(length);
|
||||
|
||||
if (fread(bytes.data(), 1, length, f) != length) {
|
||||
if (fread(bytes.data(), 1, length, f) != length)
|
||||
{
|
||||
printf("Failed to read file into bytes array\n");
|
||||
return nullptr;
|
||||
}
|
||||
@@ -132,15 +159,19 @@ static std::unique_ptr<rive::File> open_file(const char name[]) {
|
||||
return rive::File::import(bytes, &gFactory);
|
||||
}
|
||||
|
||||
static bool is_arg(const char arg[], const char target[], const char alt[] = nullptr) {
|
||||
static bool is_arg(const char arg[], const char target[], const char alt[] = nullptr)
|
||||
{
|
||||
return !strcmp(arg, target) || (arg && !strcmp(arg, alt));
|
||||
}
|
||||
|
||||
int main(int argc, const char* argv[]) {
|
||||
int main(int argc, const char* argv[])
|
||||
{
|
||||
const char* filename = nullptr;
|
||||
|
||||
for (int i = 1; i < argc; ++i) {
|
||||
if (is_arg(argv[i], "--file", "-f")) {
|
||||
for (int i = 1; i < argc; ++i)
|
||||
{
|
||||
if (is_arg(argv[i], "--file", "-f"))
|
||||
{
|
||||
filename = argv[++i];
|
||||
continue;
|
||||
}
|
||||
@@ -148,13 +179,15 @@ int main(int argc, const char* argv[]) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!filename) {
|
||||
if (!filename)
|
||||
{
|
||||
printf("Need --file filename\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
auto file = open_file(filename);
|
||||
if (!file) {
|
||||
if (!file)
|
||||
{
|
||||
printf("Can't open %s\n", filename);
|
||||
return 1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user