this repo has no description
1#include "RezWorld.h"
2#include "ResourceCompiler.h"
3#include "ResourceFork.h"
4
5#include <iostream>
6
7#include "Diagnostic.h"
8
9RezWorld::RezWorld()
10 : verboseFlag(false), hadErrors(false)
11{
12}
13
14void RezWorld::addTypeDefinition(TypeSpec spec, TypeDefinitionPtr type)
15{
16 if(!type)
17 return;
18 types[spec] = type;
19}
20
21TypeDefinitionPtr RezWorld::getTypeDefinition(ResType type, int id, yy::location loc)
22{
23 auto p = types.find(TypeSpec(type, id));
24 if(p != types.end())
25 return p->second;
26 p = types.find(TypeSpec(type));
27 if(p != types.end())
28 return p->second;
29 problem(Diagnostic(Diagnostic::Severity::error, "Can't find type definition for '" + std::string(type) + "'", loc));
30
31 return nullptr;
32}
33
34void RezWorld::addResource(ResSpec spec, CompoundExprPtr body, yy::location loc)
35{
36 if(verboseFlag)
37 std::cout << "RESOURCE " << spec.type() << "(" << spec.id() << ", " << "\"" << spec.name() << "\"" << spec.attr() << ")" << std::endl;
38 TypeDefinitionPtr def = getTypeDefinition(spec.type(), spec.id(), loc);
39 if(!def)
40 return;
41 ResourceCompiler compiler(*this, def, body, verboseFlag);
42 compiler.compile();
43
44 resources.addResource(Resource(spec.type(), spec.id(), compiler.resourceData(), spec.name(), spec.attr()));
45}
46
47void RezWorld::addData(ResSpec spec, const std::string &data, yy::location loc)
48{
49 if(verboseFlag)
50 std::cout << "DATA " << spec.type() << "(" << spec.id() << ", " << "\"" << spec.name() << "\"" << spec.attr() << ")" << std::endl;
51 resources.addResource(Resource(spec.type(), spec.id(), data, spec.name(), spec.attr()));
52}
53
54void RezWorld::problem(Diagnostic d)
55{
56 hadErrors = true;
57 std::cerr << d << std::endl;
58}