cleanup modules, initial ABR file support

This commit is contained in:
2019-02-07 20:39:02 +01:00
parent 24a6d0bae9
commit cdef5283a6
5 changed files with 462 additions and 7 deletions

224
src/abr.cpp Normal file
View File

@@ -0,0 +1,224 @@
#include "pch.h"
#include "abr.h"
//std::map<std::string, std::function<ABR::Type::Ref()>> ABR::m_parser_table;
//{
// { "VlLs", std::bind(&ABR::parse_vlls, this) },
// { "TEXT", std::bind(&ABR::parse_text, this) },
// { "Objc", std::bind(&ABR::parse_objc, this) },
// { "UntF", std::bind(&ABR::parse_untf, this) },
// { "bool", std::bind(&ABR::parse_bool, this) },
// { "long", std::bind(&ABR::parse_long, this) },
// { "doub", std::bind(&ABR::parse_doub, this) },
// { "enum", std::bind(&ABR::parse_enum, this) },
// //{ "Dmtr", &ABR::parse_prop },
// //{ "Hrdn", &ABR::parse_prop },
// //{ "Angl", &ABR::parse_prop },
// //{ "Rndn", &ABR::parse_prop },
// //{ "Spcn", &ABR::parse_prop },
// //{ "Intr", &ABR::parse_prop },
// //{ "flipX", &ABR::parse_prop },
// //{ "flipY", &ABR::parse_prop },
// //{ "useTipDynamics", &ABR::parse_prop },
// //{ "useScatter", &ABR::parse_prop },
// //{ "dualBrush", &ABR::parse_prop },
// //{ "useDualBrush", &ABR::parse_prop },
// //{ "brushGroup", &ABR::parse_prop },
// //{ "useBrushGroup", &ABR::parse_prop },
// //{ "useTexture", &ABR::parse_prop },
// //{ "usePaintDynamics", &ABR::parse_prop },
// //{ "useColorDynamics", &ABR::parse_prop },
// //{ "Wtdg", &ABR::parse_prop },
// //{ "Nose", &ABR::parse_prop },
// //{ "Rpt ", &ABR::parse_prop },
// //{ "useBrushSize", &ABR::parse_prop },
// //{ "useBrushPose", &ABR::parse_prop },
//};
bool ABR::section_desc()
{
auto sz = align4(ru32());
auto n1 = ri32(); // some integer
auto s = rwstring(); // maybe a string
auto null = rkey_or_string();
auto null_val = ri32(); // integer following the null
auto name = rkey_or_string();
auto list = rstring(4);
auto list_val = call(list);
return true;
}
bool ABR::section_samp()
{
auto sz = align4(ru32());
skip(sz);
return true;
}
bool ABR::section_patt()
{
auto sz = align4(ru32());
skip(sz);
return true;
}
std::shared_ptr<ABR::List> ABR::parse_vlls()
{
auto ret = std::make_shared<List>();
auto count = ru32();
printf("list: %d\n", count);
for (int i = 0; i < count; i++)
{
auto type = rstring(4);
auto item = call(type);
if (!item)
return nullptr;
ret->children.push_back(item);
}
return ret;
}
std::shared_ptr<ABR::String> ABR::parse_text()
{
auto ret = std::make_shared<String>();
ret->value = rwstring();
wprintf(L"text: %s\n", ret->value.c_str());
return ret;
}
//ABR::Type::Ref ABR::parse_prop()
//{
// auto name = rstring(4);
// //printf("prop type %s\n", t.c_str());
// if (!call(name))
// return false;
//}
std::shared_ptr<ABR::Descriptor> ABR::parse_objc()
{
auto ret = std::make_shared<Descriptor>();
ret->name = rwstring();
ret->class_id = rkey_or_string();
auto count = ru32();
printf("objc type %s, %d props\n", ret->class_id.c_str(), count);
for (int i = 0; i < count; i++)
{
auto key = rkey_or_string();
auto type = rstring(4);
//printf("prop %s\n", t.c_str());
auto property = call(type);
if (!property)
return nullptr;
if (ret->props.find(key) != ret->props.end())
printf("DUPLICATE prop %d\n", key.c_str());
ret->props[key] = property;
}
return ret;
}
std::shared_ptr<ABR::UnitFloat> ABR::parse_untf()
{
auto ret = std::make_shared<UnitFloat>();
ret->unit = rstring(4);
ret->value = rdbl();
printf("float %s: %f\n", ret->unit.c_str(), ret->value);
return ret;
}
std::shared_ptr<ABR::Boolean> ABR::parse_bool()
{
auto ret = std::make_shared<Boolean>();
ret->value = ru8();
printf("bool: %s\n", ret->value ? "true" : "false");
return ret;
}
std::shared_ptr<ABR::Integer> ABR::parse_long()
{
auto ret = std::make_shared<Integer>();
ret->value = ru32();
printf("long: %d\n", ret->value);
return ret;
}
std::shared_ptr<ABR::Double> ABR::parse_doub()
{
auto ret = std::make_shared<Double>();
ret->value = rdbl();
printf("double: %d\n", ret->value);
return ret;
}
std::shared_ptr<ABR::Enum> ABR::parse_enum()
{
auto ret = std::make_shared<Enum>();
auto t = rkey_or_string();
auto e = rkey_or_string();
printf("enum: %s %s\n", t.c_str(), e.c_str());
return ret;
}
ABR::ABR()
{
m_parser_table = std::map<std::string, std::function<ABR::Type::Ref()>>
{
{ "VlLs", std::bind(&ABR::parse_vlls, this) },
{ "TEXT", std::bind(&ABR::parse_text, this) },
{ "Objc", std::bind(&ABR::parse_objc, this) },
{ "UntF", std::bind(&ABR::parse_untf, this) },
{ "bool", std::bind(&ABR::parse_bool, this) },
{ "long", std::bind(&ABR::parse_long, this) },
{ "doub", std::bind(&ABR::parse_doub, this) },
{ "enum", std::bind(&ABR::parse_enum, this) },
//{ "Dmtr", &ABR::parse_prop },
//{ "Hrdn", &ABR::parse_prop },
//{ "Angl", &ABR::parse_prop },
//{ "Rndn", &ABR::parse_prop },
//{ "Spcn", &ABR::parse_prop },
//{ "Intr", &ABR::parse_prop },
//{ "flipX", &ABR::parse_prop },
//{ "flipY", &ABR::parse_prop },
//{ "useTipDynamics", &ABR::parse_prop },
//{ "useScatter", &ABR::parse_prop },
//{ "dualBrush", &ABR::parse_prop },
//{ "useDualBrush", &ABR::parse_prop },
//{ "brushGroup", &ABR::parse_prop },
//{ "useBrushGroup", &ABR::parse_prop },
//{ "useTexture", &ABR::parse_prop },
//{ "usePaintDynamics", &ABR::parse_prop },
//{ "useColorDynamics", &ABR::parse_prop },
//{ "Wtdg", &ABR::parse_prop },
//{ "Nose", &ABR::parse_prop },
//{ "Rpt ", &ABR::parse_prop },
//{ "useBrushSize", &ABR::parse_prop },
//{ "useBrushPose", &ABR::parse_prop },
};
}
bool ABR::open(const std::string& path)
{
m_parser_table[""] = std::bind(&ABR::parse_bool, this);
Asset asset;
if (asset.open(path.c_str()))
{
init(asset.read_all(), asset.m_len, BinaryStream::ByteOrder::BigEndian);
auto version_major = ru16();
auto version_minor = ru16();
while (!eof())
{
if (rstring(4) != "8BIM")
return false;
auto t = rstring(4);
if (t == "desc")
{
section_desc();
}
else
{
printf("skip section %s\n", t.c_str());
skip(align4(ru32()));
}
}
}
return false;
}