-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayModeObjectLoader.cpp
More file actions
34 lines (29 loc) · 1.04 KB
/
Copy pathPlayModeObjectLoader.cpp
File metadata and controls
34 lines (29 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include "PlayModeObjectLoader.h"
#include "ObjectTags.h"
#include <iostream>
#include <fstream>
#include <stdexcept>
using namespace std;
using namespace sf;
void PlayModeObjectLoader::loadGameObjectsForPlayMode(string pathToFile, vector<GameObject>& gameObjects)
{
ifstream reader(pathToFile);
// The stream state used to go unchecked. A missing or unreadable level
// file then produced zero game objects, and the first thing that happens
// next is a search for the object tagged "Player" -- which read off the end
// of the empty vector.
if (!reader.is_open())
{
throw std::runtime_error("PlayModeObjectLoader - could not open level file \"" + pathToFile + "\"");
}
string lineFromFile;
while (getline(reader, lineFromFile))
{
if (lineFromFile.find(ObjectTags::START_OF_OBJECT) != string::npos)
{
GameObjectBlueprint bp;
m_BOP.parseNextObjectForBlueprint(reader, bp);
m_GameObjectFactoryPlayMode.buildGameObject(bp, gameObjects);
}
}
}