Retro68/Rez/RezWorld.cc

46 lines
1.2 KiB
C++
Raw Normal View History

#include "RezWorld.h"
2014-10-08 00:52:34 +00:00
#include "ResourceCompiler.h"
#include "ResourceFiles.h"
#include <iostream>
RezWorld::RezWorld()
2014-10-09 20:15:13 +00:00
: verboseFlag(false)
{
}
void RezWorld::addTypeDefinition(TypeSpec spec, TypeDefinitionPtr type)
{
types[spec] = type;
}
TypeDefinitionPtr RezWorld::getTypeDefinition(ResType type, int id)
{
auto p = types.find(TypeSpec(type, id));
if(p != types.end())
return p->second;
p = types.find(TypeSpec(type));
if(p != types.end())
return p->second;
return nullptr;
}
2014-10-08 00:52:34 +00:00
2014-10-14 00:19:26 +00:00
void RezWorld::addResource(ResSpec spec, CompoundExprPtr body)
2014-10-08 00:52:34 +00:00
{
2014-10-09 20:15:13 +00:00
if(verboseFlag)
2014-10-14 00:19:26 +00:00
std::cout << "RESOURCE " << spec.type() << "(" << spec.id() << ", " << "\"" << spec.name() << "\"" << spec.attr() << ")" << std::endl;
TypeDefinitionPtr def = getTypeDefinition(spec.type(), spec.id());
2014-10-09 20:15:13 +00:00
ResourceCompiler compiler(def, body, verboseFlag);
2014-10-08 00:52:34 +00:00
compiler.compile();
2014-10-14 00:19:26 +00:00
resources.addResource(Resource(spec.type(), spec.id(), compiler.resourceData(), spec.name(), spec.attr()));
}
void RezWorld::addData(ResSpec spec, const std::string &data)
{
if(verboseFlag)
std::cout << "DATA " << spec.type() << "(" << spec.id() << ", " << "\"" << spec.name() << "\"" << spec.attr() << ")" << std::endl;
resources.addResource(Resource(spec.type(), spec.id(), data, spec.name(), spec.attr()));
2014-10-08 00:52:34 +00:00
}