2014-10-07 18:15:46 +00:00
|
|
|
#include "RezWorld.h"
|
2014-10-08 00:52:34 +00:00
|
|
|
#include "ResourceCompiler.h"
|
2014-10-21 20:37:43 +00:00
|
|
|
#include "ResourceFork.h"
|
2014-10-08 00:52:34 +00:00
|
|
|
|
|
|
|
#include <iostream>
|
2014-10-07 18:15:46 +00:00
|
|
|
|
2014-10-30 01:56:49 +00:00
|
|
|
#include "Diagnostic.h"
|
|
|
|
|
2014-10-07 18:15:46 +00:00
|
|
|
RezWorld::RezWorld()
|
2019-08-18 11:21:00 +00:00
|
|
|
: verboseFlag(false), hadErrors(false)
|
2014-10-07 18:15:46 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void RezWorld::addTypeDefinition(TypeSpec spec, TypeDefinitionPtr type)
|
|
|
|
{
|
2019-08-18 11:21:00 +00:00
|
|
|
if(!type)
|
|
|
|
return;
|
|
|
|
types[spec] = type;
|
2014-10-07 18:15:46 +00:00
|
|
|
}
|
|
|
|
|
2014-10-30 01:56:49 +00:00
|
|
|
TypeDefinitionPtr RezWorld::getTypeDefinition(ResType type, int id, yy::location loc)
|
2014-10-07 18:15:46 +00:00
|
|
|
{
|
2019-08-18 11:21:00 +00:00
|
|
|
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;
|
|
|
|
problem(Diagnostic(Diagnostic::Severity::error, "Can't find type definition for '" + std::string(type) + "'", loc));
|
|
|
|
|
|
|
|
return nullptr;
|
2014-10-07 18:15:46 +00:00
|
|
|
}
|
2014-10-08 00:52:34 +00:00
|
|
|
|
2014-10-30 01:56:49 +00:00
|
|
|
void RezWorld::addResource(ResSpec spec, CompoundExprPtr body, yy::location loc)
|
2014-10-08 00:52:34 +00:00
|
|
|
{
|
2019-08-18 11:21:00 +00:00
|
|
|
if(verboseFlag)
|
|
|
|
std::cout << "RESOURCE " << spec.type() << "(" << spec.id() << ", " << "\"" << spec.name() << "\"" << spec.attr() << ")" << std::endl;
|
|
|
|
TypeDefinitionPtr def = getTypeDefinition(spec.type(), spec.id(), loc);
|
|
|
|
if(!def)
|
|
|
|
return;
|
|
|
|
ResourceCompiler compiler(*this, def, body, verboseFlag);
|
|
|
|
compiler.compile();
|
|
|
|
|
|
|
|
resources.addResource(Resource(spec.type(), spec.id(), compiler.resourceData(), spec.name(), spec.attr()));
|
2014-10-14 00:19:26 +00:00
|
|
|
}
|
|
|
|
|
2014-10-30 01:56:49 +00:00
|
|
|
void RezWorld::addData(ResSpec spec, const std::string &data, yy::location loc)
|
2014-10-14 00:19:26 +00:00
|
|
|
{
|
2019-08-18 11:21:00 +00:00
|
|
|
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
|
|
|
}
|
2014-10-30 01:56:49 +00:00
|
|
|
|
|
|
|
void RezWorld::problem(Diagnostic d)
|
|
|
|
{
|
2019-08-18 11:21:00 +00:00
|
|
|
hadErrors = true;
|
|
|
|
std::cerr << d << std::endl;
|
2014-10-30 01:56:49 +00:00
|
|
|
}
|