mirror of
https://github.com/AxioDL/metaforce.git
synced 2025-12-16 03:37:01 +00:00
lots of dataspec implementation
This commit is contained in:
@@ -3,17 +3,59 @@
|
||||
|
||||
#include "ToolBase.hpp"
|
||||
#include <stdio.h>
|
||||
#include <map>
|
||||
|
||||
class ToolSpec final : public ToolBase
|
||||
{
|
||||
enum Mode
|
||||
{
|
||||
MLIST = 0,
|
||||
MENABLE,
|
||||
MDISABLE
|
||||
} mode = MLIST;
|
||||
public:
|
||||
ToolSpec(const ToolPassInfo& info)
|
||||
: ToolBase(info)
|
||||
{
|
||||
}
|
||||
if (info.args.empty())
|
||||
return;
|
||||
|
||||
~ToolSpec()
|
||||
{
|
||||
if (!info.project)
|
||||
throw HECL::Exception(_S("hecl spec must be ran within a project directory"));
|
||||
|
||||
const auto& specs = info.project->getDataSpecs();
|
||||
HECL::SystemString firstArg = info.args[0];
|
||||
HECL::ToLower(firstArg);
|
||||
|
||||
static const HECL::SystemString enable(_S("enable"));
|
||||
static const HECL::SystemString disable(_S("disable"));
|
||||
if (!firstArg.compare(enable))
|
||||
mode = MENABLE;
|
||||
else if (!firstArg.compare(disable))
|
||||
mode = MDISABLE;
|
||||
else
|
||||
return;
|
||||
|
||||
if (info.args.size() < 2)
|
||||
throw HECL::Exception(_S("Speclist argument required"));
|
||||
|
||||
for (auto it = info.args.begin()+1;
|
||||
it != info.args.end();
|
||||
++it)
|
||||
{
|
||||
|
||||
bool found = false;
|
||||
for (auto& spec : specs)
|
||||
{
|
||||
if (!spec.first.name.compare(*it))
|
||||
{
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found)
|
||||
throw HECL::Exception(_S("'") + *it + _S("' is not found in the dataspec registry"));
|
||||
}
|
||||
}
|
||||
|
||||
static void Help(HelpOutput& help)
|
||||
@@ -46,6 +88,67 @@ public:
|
||||
|
||||
int run()
|
||||
{
|
||||
if (!m_info.project)
|
||||
{
|
||||
for (const HECL::Database::DataSpecEntry* spec = HECL::Database::DATA_SPEC_REGISTRY;
|
||||
spec->name.size();
|
||||
++spec)
|
||||
{
|
||||
if (XTERM_COLOR)
|
||||
HECL::Printf(_S("" BOLD CYAN "%s" NORMAL "\n"), spec->name.c_str());
|
||||
else
|
||||
HECL::Printf(_S("%s\n"), spec->name.c_str());
|
||||
HECL::Printf(_S(" %s\n"), spec->desc.c_str());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
const auto& specs = m_info.project->getDataSpecs();
|
||||
if (mode == MLIST)
|
||||
{
|
||||
for (auto& spec : specs)
|
||||
{
|
||||
if (XTERM_COLOR)
|
||||
HECL::Printf(_S("" BOLD CYAN "%s" NORMAL ""), spec.first.name.c_str());
|
||||
else
|
||||
HECL::Printf(_S("%s"), spec.first.name.c_str());
|
||||
if (spec.second)
|
||||
{
|
||||
if (XTERM_COLOR)
|
||||
HECL::Printf(_S(" " BOLD GREEN "[ENABLED]" NORMAL ""));
|
||||
else
|
||||
HECL::Printf(_S(" [ENABLED]"));
|
||||
}
|
||||
HECL::Printf(_S("\n %s\n"), spec.first.desc.c_str());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::vector<HECL::SystemString> opSpecs;
|
||||
for (auto it = m_info.args.begin()+1;
|
||||
it != m_info.args.end();
|
||||
++it)
|
||||
{
|
||||
HECL::SystemString itName = *it;
|
||||
HECL::ToLower(itName);
|
||||
for (auto& spec : specs)
|
||||
{
|
||||
if (!spec.first.name.compare(itName))
|
||||
{
|
||||
opSpecs.push_back(spec.first.name);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (opSpecs.size())
|
||||
{
|
||||
if (mode == MENABLE)
|
||||
m_info.project->enableDataSpecs(opSpecs);
|
||||
else if (mode == MDISABLE)
|
||||
m_info.project->disableDataSpecs(opSpecs);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user