Working on data structures and file formats.
This commit is contained in:
@@ -21,9 +21,6 @@ file(GLOB_RECURSE EDITOR_SRC "src/*.cpp")
|
||||
include_directories("include")
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
CPMAddPackage(NAME jlog
|
||||
URL https://git.redacted.cc/josh/jlog/archive/Prerelease-18.zip)
|
||||
|
||||
@@ -67,9 +64,10 @@ target_include_directories(Editor2D PUBLIC
|
||||
${ReWindow_SOURCE_DIR}/include
|
||||
${JUI_SOURCE_DIR}/include
|
||||
${mcolor_SOURCE_DIR}/include
|
||||
${jjx_SOURCE_DIR}/include
|
||||
)
|
||||
|
||||
target_link_libraries(Editor2D PUBLIC Event J3ML jlog ReWindow JGL JUI mcolor)
|
||||
target_link_libraries(Editor2D PUBLIC Event J3ML jlog ReWindow JGL JUI mcolor jjx)
|
||||
|
||||
|
||||
add_executable(Editor2DApp main.cpp)
|
||||
|
@@ -35,7 +35,7 @@ public:
|
||||
JUI::ColorPicker* bg_color_tool = nullptr;
|
||||
|
||||
bool grid_overlay_enabled = true;
|
||||
Color4 grid_overlay_color = {255, 255, 255, 128};
|
||||
Color4 grid_overlay_color = {255, 255, 255, 64};
|
||||
Color4 bg_color = Colors::Black;
|
||||
|
||||
|
||||
@@ -172,7 +172,7 @@ public:
|
||||
file->SetFont(JGL::Fonts::Jupiteroid);
|
||||
file->AddButton("New");
|
||||
file->AddButton("Open");
|
||||
file->AddButton("Save");
|
||||
file->AddButton("Save", [this]{SaveTestFile();});
|
||||
file->AddButton("Save As");
|
||||
file->AddSeparator(2_px);
|
||||
file->AddButton("About");
|
||||
@@ -359,6 +359,8 @@ public:
|
||||
glRotatef(camera.rotation, 0, 0, 1);
|
||||
glScalef(camera.scale, camera.scale, 1);
|
||||
|
||||
if (grid_overlay_enabled)
|
||||
DrawGrid(grid_overlay_color);
|
||||
//J2D::DrawSprite(test_tilesheet, {32, 32}, 0, Vector2::Zero, Vector2::One, Colors::White);
|
||||
for (int gx = 0; gx < grid_rows; gx++) {
|
||||
for (int gy = 0; gy < grid_cols; gy++) {
|
||||
@@ -374,8 +376,7 @@ public:
|
||||
Vector2(quad.x, quad.y), Vector2(quad.w, quad.h));
|
||||
}
|
||||
}
|
||||
if (grid_overlay_enabled)
|
||||
DrawGrid(grid_overlay_color);
|
||||
|
||||
|
||||
glPopMatrix();
|
||||
J2D::End();
|
||||
@@ -408,9 +409,6 @@ public:
|
||||
auto btn = ToJUIEnum(e.Button);
|
||||
|
||||
if (scene->ObserveMouseInput(btn, true)) return;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
void OnMouseButtonUp(const MouseButtonUpEvent &e) override {
|
||||
|
@@ -1,8 +1,98 @@
|
||||
//
|
||||
// Created by dawsh on 5/12/25.
|
||||
//
|
||||
#pragma once
|
||||
|
||||
#ifndef TILESET_HPP
|
||||
#define TILESET_HPP
|
||||
#include <JJX/JSON.hpp>
|
||||
#include <filesystem>
|
||||
#include <format>
|
||||
#include <vector>
|
||||
#include <J3ML/Math.hpp>
|
||||
#include <J3ML/LinearAlgebra.hpp>
|
||||
#include "JGL/types/Texture.h"
|
||||
|
||||
#endif //TILESET_HPP
|
||||
|
||||
using namespace JJX;
|
||||
|
||||
struct Quad {
|
||||
int x;
|
||||
int y;
|
||||
int w;
|
||||
int h;
|
||||
};
|
||||
|
||||
class Tileset {
|
||||
public:
|
||||
std::string name;
|
||||
std::string author;
|
||||
|
||||
std::string file_path;
|
||||
int tile_width;
|
||||
int tile_height;
|
||||
int tile_spacing;
|
||||
int tile_count;
|
||||
|
||||
int tex_width;
|
||||
int tex_height;
|
||||
|
||||
int tiles_per_row;
|
||||
|
||||
int rows;
|
||||
int cols;
|
||||
|
||||
std::vector<Quad> quads;
|
||||
std::vector<json::value> tile_metadata;
|
||||
|
||||
std::string texture_path;
|
||||
JGL::Texture* texture;
|
||||
|
||||
public:
|
||||
Tileset(const std::string& name, const std::filesystem::path& texture_path, int tile_width, int tile_height, int tile_spacing) {
|
||||
this->name = name;
|
||||
this->file_path = std::format("{}.tileset", name);
|
||||
|
||||
this->texture = new JGL::Texture(texture_path);
|
||||
auto texture_size = this->texture->GetDimensions();
|
||||
this->tex_width = texture_size.x;
|
||||
this->tex_height = texture_size.y;
|
||||
this->texture_path = texture_path.string();
|
||||
|
||||
this->tile_width = tile_width;
|
||||
this->tile_height = tile_height;
|
||||
this->tile_spacing = tile_spacing;
|
||||
|
||||
this->rows;
|
||||
this->cols;
|
||||
|
||||
|
||||
this->rows = J3ML::Math::Floor(this->tex_width / this->tile_width);
|
||||
this->cols = J3ML::Math::Floor(this->tex_height / this->tile_height);
|
||||
|
||||
|
||||
ComputeQuads();
|
||||
|
||||
}
|
||||
explicit Tileset(const json::value& json);
|
||||
explicit Tileset(const std::filesystem::path& filePath);
|
||||
void Deserialize(const json::value& json);
|
||||
json::value Serialize() const;
|
||||
|
||||
|
||||
static Tileset CreateTemplate() {
|
||||
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
Vector2i IndexToCell(int index) {
|
||||
return {index % rows, index / rows};
|
||||
}
|
||||
inline int CellToIndex(int cx, int cy) {
|
||||
return cy*rows + cx;
|
||||
}
|
||||
void ComputeQuads() {
|
||||
quads.reserve(rows*cols);
|
||||
|
||||
for (int i = 0; i < rows*cols; i++) {
|
||||
Vector2i cell = IndexToCell(i);
|
||||
quads[i] = Quad{cell.x*tile_width, cell.y*tile_height, tile_width, tile_height};
|
||||
}
|
||||
}
|
||||
};
|
Reference in New Issue
Block a user