2024-05-04 04:57:22 -04:00
|
|
|
const std = @import("std");
|
|
|
|
const rl = @import("raylib");
|
2024-05-04 06:34:53 -04:00
|
|
|
const Allocator = std.mem.Allocator;
|
2024-05-04 04:57:22 -04:00
|
|
|
const json = std.json;
|
2024-05-04 06:34:53 -04:00
|
|
|
const dbg = std.debug;
|
|
|
|
const fmt = std.fmt;
|
|
|
|
const fs = std.fs;
|
2024-05-04 04:57:22 -04:00
|
|
|
|
|
|
|
pub const Floor = struct {
|
2024-05-04 06:34:53 -04:00
|
|
|
level: i32,
|
|
|
|
x: f32,
|
|
|
|
y: f32,
|
|
|
|
value: i32,
|
2024-05-04 04:57:22 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
pub const Wall = struct {
|
2024-05-04 06:34:53 -04:00
|
|
|
level: i32,
|
|
|
|
x: f32,
|
|
|
|
y: f32,
|
|
|
|
value: i32,
|
|
|
|
tls: i32,
|
|
|
|
trs: i32,
|
|
|
|
tlp: i32,
|
|
|
|
trp: i32,
|
|
|
|
blp: i32,
|
|
|
|
brp: i32,
|
2024-05-04 04:57:22 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
pub const World = struct {
|
|
|
|
floors: []Floor,
|
2024-05-04 06:34:53 -04:00
|
|
|
walls: ?[]Wall,
|
2024-05-04 04:57:22 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
pub const Item = struct {
|
2024-05-04 06:34:53 -04:00
|
|
|
guid: i32,
|
|
|
|
level: i32,
|
|
|
|
x: i32,
|
|
|
|
y: i32,
|
|
|
|
dir: i32,
|
|
|
|
group: i32,
|
2024-05-04 04:57:22 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
pub const House = struct {
|
|
|
|
version: f32,
|
2024-05-04 06:34:53 -04:00
|
|
|
size: i32,
|
|
|
|
category: i32,
|
2024-05-04 04:57:22 -04:00
|
|
|
world: World,
|
|
|
|
items: []Item,
|
|
|
|
};
|
|
|
|
|
2024-05-04 06:34:53 -04:00
|
|
|
pub const Blueprint = struct {
|
|
|
|
house: House,
|
|
|
|
};
|
|
|
|
|
2024-05-04 04:57:22 -04:00
|
|
|
/// Draws floors from JSON Blueprint files
|
2024-05-04 06:34:53 -04:00
|
|
|
pub fn draw_floors(json_file: [:0]const u8) !void {
|
2024-05-04 04:57:22 -04:00
|
|
|
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
|
|
|
|
defer _ = gpa.deinit();
|
|
|
|
const allocator = gpa.allocator();
|
|
|
|
|
2024-05-04 06:34:53 -04:00
|
|
|
// Load file
|
|
|
|
const lot = rl.loadFileText(json_file);
|
|
|
|
defer rl.unloadFileText(lot);
|
2024-05-04 04:57:22 -04:00
|
|
|
|
2024-05-04 06:34:53 -04:00
|
|
|
// Parse JSON
|
|
|
|
const parsed = try json.parseFromSlice(Blueprint, allocator, lot, .{});
|
2024-05-04 04:57:22 -04:00
|
|
|
defer parsed.deinit();
|
|
|
|
|
|
|
|
const blueprint = parsed.value;
|
|
|
|
|
2024-05-04 06:34:53 -04:00
|
|
|
const floorLevel = rl.Vector3.init(0.0, 0.0, 0.0);
|
|
|
|
|
|
|
|
for (blueprint.house.world.floors) |flr| {
|
|
|
|
// Draw grass
|
2024-05-04 04:57:22 -04:00
|
|
|
rl.drawPlane(floorLevel, rl.Vector2.init(flr.x, flr.y), rl.Color.green);
|
|
|
|
}
|
|
|
|
}
|