Add objects parsing to SceneParser
This commit is contained in:
parent
43a1e790cb
commit
49e3395a4c
2 changed files with 30 additions and 2 deletions
|
@ -9,6 +9,7 @@
|
|||
#include <cassert>
|
||||
#include <string>
|
||||
|
||||
#include "objectParser.hh"
|
||||
#include "sceneParser.hh"
|
||||
#include "vector_parser.hh"
|
||||
|
||||
|
@ -31,6 +32,7 @@ SceneParser::HandleKeyEvent(const std::string& key)
|
|||
{
|
||||
static const std::map<std::string, Section> sSections = {
|
||||
{"dimensions", DimensionsSection},
|
||||
{"objects", ObjectsSection}
|
||||
};
|
||||
|
||||
if (sSections.count(key) > 0) {
|
||||
|
@ -52,14 +54,13 @@ SceneParser::HandleValueEvent(yaml_event_t& event)
|
|||
HandleDimensionsEvent(event);
|
||||
break;
|
||||
case ObjectsSection:
|
||||
HandleObjectsEvent(event);
|
||||
break;
|
||||
default:
|
||||
/* TODO: WHAT. Fail gracefully. */
|
||||
assert(false);
|
||||
break;
|
||||
}
|
||||
|
||||
SetShouldExpectKey(false);
|
||||
}
|
||||
|
||||
|
||||
|
@ -70,6 +71,7 @@ SceneParser::HandleDimensionsEvent(yaml_event_t& event)
|
|||
if (dimensions.size() < 2) {
|
||||
assert(dimensions.size() < 2);
|
||||
}
|
||||
|
||||
Scene& sc = GetScene();
|
||||
sc.set_width(dimensions.at(0));
|
||||
sc.set_height(dimensions.at(1));
|
||||
|
@ -88,4 +90,29 @@ SceneParser::HandleDimensionsEvent(yaml_event_t& event)
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
SceneParser::HandleObjectsEvent(yaml_event_t& event)
|
||||
{
|
||||
if (event.type == YAML_SEQUENCE_START_EVENT) {
|
||||
/* Ignore sequence-start for now. */
|
||||
printf("start objects\n");
|
||||
return;
|
||||
}
|
||||
else if (event.type == YAML_SEQUENCE_END_EVENT) {
|
||||
printf("end objects\n");
|
||||
mSection = NoSection;
|
||||
SetShouldExpectKey(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.type != YAML_MAPPING_START_EVENT) {
|
||||
assert(event.type != YAML_MAPPING_START_EVENT);
|
||||
return;
|
||||
}
|
||||
|
||||
printf("start object\n");
|
||||
GetParsers().push(new ObjectParser(GetScene(), GetParsers()));
|
||||
}
|
||||
|
||||
} /* namespace yaml */
|
||||
|
|
|
@ -36,6 +36,7 @@ private:
|
|||
};
|
||||
|
||||
void HandleDimensionsEvent(yaml_event_t& event);
|
||||
void HandleObjectsEvent(yaml_event_t& event);
|
||||
|
||||
Section mSection;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue