Putting together JSON format next?
This commit is contained in:
@@ -26,7 +26,8 @@ EditorApp::EditorApp(): OpenGLWindow("Editor App", 1776, 1000, GL_VER_MAJOR, GL_
|
||||
camera.DefaultState();
|
||||
}
|
||||
|
||||
void EditorApp::LoadTestFile()
|
||||
|
||||
std::string read_file_contents(const std::filesystem::path& file_path)
|
||||
{
|
||||
std::ifstream input;
|
||||
input.open("test.lvl", std::ios::binary | std::ios::in);
|
||||
@@ -38,16 +39,67 @@ void EditorApp::LoadTestFile()
|
||||
input.read(buffer, data_length);
|
||||
input.close();
|
||||
|
||||
std::string result = std::string(buffer);
|
||||
delete[] buffer;
|
||||
return result;
|
||||
}
|
||||
|
||||
void EditorApp::LoadTestFile()
|
||||
{
|
||||
if (!std::filesystem::exists("test_level"))
|
||||
std::filesystem::create_directory("test_level");
|
||||
|
||||
|
||||
//if (!std::filesystem::exists("test_level/metadata.json"))
|
||||
|
||||
|
||||
//std::string level_metadata_text = read_file_contents("test_level/metadata.json");
|
||||
|
||||
std::ifstream input;
|
||||
input.open("test.lvl", std::ios::binary | std::ios::in);
|
||||
input.seekg(0, std::ios::end);
|
||||
int data_length = input.tellg();
|
||||
input.seekg(0, std::ios::beg);
|
||||
|
||||
char* buffer = new char[data_length];
|
||||
input.read(buffer, data_length);
|
||||
input.close();
|
||||
|
||||
auto* data = reinterpret_cast<int*>(buffer);
|
||||
memcpy(grid, data, grid_rows * grid_cols * sizeof(int));
|
||||
|
||||
for (int x = 0; x < grid_rows; x++)
|
||||
{
|
||||
for (int y = 0; y < grid_cols; y++)
|
||||
{
|
||||
int index = (x*grid_cols + y);
|
||||
grid[x][y] = data[index];
|
||||
}
|
||||
}
|
||||
|
||||
//memcpy(grid, data, grid_rows * grid_cols * sizeof(int));
|
||||
|
||||
delete[] buffer;
|
||||
}
|
||||
|
||||
void EditorApp::SaveTestFile()
|
||||
{
|
||||
|
||||
int* buffer = new int[grid_rows*grid_cols];
|
||||
for (int x = 0; x < grid_rows; x++)
|
||||
{
|
||||
for (int y = 0; y < grid_cols; y++)
|
||||
{
|
||||
int index = (x*grid_cols + y);
|
||||
buffer[index] = grid[x][y];
|
||||
}
|
||||
}
|
||||
|
||||
std::ofstream output;
|
||||
output.open("test.lvl", std::ios::out | std::ios::binary);
|
||||
output.write(reinterpret_cast<const char*>(&grid[0][0]), grid_rows * grid_cols * sizeof(int));
|
||||
output.write(reinterpret_cast<const char*>(buffer), grid_rows * grid_cols * sizeof(int));
|
||||
output.close();
|
||||
|
||||
delete[] buffer;
|
||||
}
|
||||
|
||||
void EditorApp::LoadMisc()
|
||||
@@ -60,11 +112,9 @@ void EditorApp::LoadMisc()
|
||||
|
||||
PopulateQuads();
|
||||
|
||||
for (int x = 0; x < grid_rows; x++) {
|
||||
for (int y = 0; y < grid_cols; y++) {
|
||||
grid[x][y] = -1;
|
||||
}
|
||||
}
|
||||
InitGrid();
|
||||
|
||||
|
||||
|
||||
if (std::filesystem::exists("test.lvl"))
|
||||
LoadTestFile();
|
||||
|
Reference in New Issue
Block a user