Putting together JSON format next?
This commit is contained in:
@@ -87,7 +87,29 @@ public:
|
||||
int grid_rows = 128;
|
||||
int grid_cols = 128;
|
||||
|
||||
int grid[128][128];
|
||||
int** grid;
|
||||
|
||||
void InitGrid()
|
||||
{
|
||||
grid = new int*[grid_rows];
|
||||
|
||||
for (int i = 0; i < grid_rows; i++)
|
||||
grid[i] = new int[grid_cols];
|
||||
|
||||
for (int x = 0; x < grid_rows; x++) {
|
||||
for (int y = 0; y < grid_cols; y++) {
|
||||
grid[x][y] = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DeleteGrid()
|
||||
{
|
||||
for (int i = 0; i < grid_rows; i++)
|
||||
delete[] grid[i];
|
||||
|
||||
delete[] grid;
|
||||
}
|
||||
|
||||
int selected_quad = 0;
|
||||
|
||||
@@ -112,6 +134,10 @@ public:
|
||||
int CellToIndex(Vector2i cell, int width);
|
||||
|
||||
EditorApp();
|
||||
~EditorApp() override
|
||||
{
|
||||
DeleteGrid();
|
||||
}
|
||||
|
||||
/// Loads the test.lvl file into the editor.
|
||||
/// @note Placeholder until FileDialogs are added.
|
||||
|
@@ -1,8 +1,7 @@
|
||||
//
|
||||
// Created by dawsh on 5/12/25.
|
||||
//
|
||||
#pragma once
|
||||
|
||||
#ifndef LAYER_HPP
|
||||
#define LAYER_HPP
|
||||
|
||||
#endif //LAYER_HPP
|
||||
class Layer {
|
||||
public:
|
||||
|
||||
};
|
@@ -12,8 +12,12 @@ public:
|
||||
int cols;
|
||||
int cell_width;
|
||||
int cell_height;
|
||||
TileCell cells[][];
|
||||
TileCell** cells;
|
||||
|
||||
TileLayer(int rows, int cols, int cell_width, int cell_height)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected:
|
||||
private:
|
||||
|
@@ -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