Skip to content

Commit

Permalink
Add back process_assets build step
Browse files Browse the repository at this point in the history
  • Loading branch information
foxnne committed Feb 13, 2025
1 parent 8019c11 commit 93d2c7c
Show file tree
Hide file tree
Showing 12 changed files with 110 additions and 62 deletions.
2 changes: 1 addition & 1 deletion assets/pixi.atlas
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"sprites":[{"source":[0,0,22,22],"origin":[0,22]},{"source":[22,0,22,22],"origin":[0,22]},{"source":[158,0,15,16],"origin":[0,14]},{"source":[110,0,21,21],"origin":[0,21]},{"source":[44,0,22,22],"origin":[-1,23]},{"source":[66,0,22,22],"origin":[-1,23]},{"source":[88,0,22,22],"origin":[-1,23]},{"source":[131,0,27,18],"origin":[3,20]},{"source":[173,0,3,5],"origin":[-10,13]}],"animations":[{"name":"pencil_default","start":0,"length":1,"fps":1},{"name":"eraser_default","start":1,"length":1,"fps":1},{"name":"bucket_default","start":2,"length":1,"fps":1},{"name":"dropper_default","start":3,"length":1,"fps":1},{"name":"selection_default","start":4,"length":1,"fps":1},{"name":"selection_add_default","start":5,"length":1,"fps":1},{"name":"selection_rem_default","start":6,"length":1,"fps":1},{"name":"fox_default","start":7,"length":1,"fps":1},{"name":"logo_default","start":8,"length":1,"fps":1}]}
{"sprites":[{"source":[44,0,22,22],"origin":[0,22]},{"source":[88,0,22,22],"origin":[0,22]},{"source":[239,0,15,16],"origin":[0,14]},{"source":[110,0,21,21],"origin":[0,21]},{"source":[0,0,22,22],"origin":[-1,23]},{"source":[22,0,22,22],"origin":[-1,23]},{"source":[66,0,22,22],"origin":[-1,23]},{"source":[212,18,27,18],"origin":[3,20]},{"source":[131,19,27,18],"origin":[3,20]},{"source":[158,19,27,18],"origin":[6,13]},{"source":[0,22,27,18],"origin":[3,20]},{"source":[27,22,27,18],"origin":[-2,-7]},{"source":[185,18,27,18],"origin":[-2,-7]},{"source":[54,22,27,18],"origin":[-2,-7]},{"source":[81,22,27,18],"origin":[-2,-7]},{"source":[185,0,27,18],"origin":[-2,-7]},{"source":[212,0,27,18],"origin":[-2,-7]},{"source":[158,0,27,19],"origin":[-2,-6]},{"source":[131,0,27,19],"origin":[-2,-6]},{"source":[131,37,27,18],"origin":[-2,-7]},{"source":[158,37,27,18],"origin":[-2,-7]},{"source":[185,36,27,18],"origin":[-2,-7]},{"source":[212,36,27,18],"origin":[-2,-7]},{"source":[239,16,3,5],"origin":[-15,-14]}],"animations":[{"name":"pencil_default","start":0,"length":1,"fps":1},{"name":"eraser_default","start":1,"length":1,"fps":1},{"name":"bucket_default","start":2,"length":1,"fps":1},{"name":"dropper_default","start":3,"length":1,"fps":1},{"name":"selection_default","start":4,"length":1,"fps":1},{"name":"selection_add_default","start":5,"length":1,"fps":1},{"name":"selection_rem_default","start":6,"length":1,"fps":1},{"name":"fox_default","start":7,"length":16,"fps":8},{"name":"logo_default","start":23,"length":1,"fps":1}]}
Binary file modified assets/pixi.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/src/misc.pixi
Binary file not shown.
8 changes: 4 additions & 4 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ pub fn build(b: *std.Build) !void {
exe.linkLibrary(zstbi.artifact("zstbi"));
zip.link(exe);

// const assets = try ProcessAssetsStep.init(b, "assets", "src/assets.zig", "src/animations.zig");
// var process_assets_step = b.step("process-assets", "generates struct for all assets");
// process_assets_step.dependOn(&assets.step);
// exe.step.dependOn(process_assets_step);
const assets = try ProcessAssetsStep.init(b, "assets", "src/assets.zig", "src/animations.zig");
var process_assets_step = b.step("process-assets", "generates struct for all assets");
process_assets_step.dependOn(&assets.step);
exe.step.dependOn(process_assets_step);

const install_content_step = b.addInstallDirectory(.{
.source_dir = .{ .cwd_relative = thisDir() ++ "/" ++ content_dir },
Expand Down
11 changes: 11 additions & 0 deletions src/Atlas.zig
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,17 @@ pub fn loadFromFile(allocator: std.mem.Allocator, file: [:0]const u8) !Atlas {
};
}

pub fn spriteName(atlas: *Atlas, allocator: std.mem.Allocator, index: usize) ![]const u8 {
for (atlas.animations) |animation| {
if (index >= animation.start and index < animation.start + animation.length) {
const frame: usize = index - animation.start;
return std.fmt.allocPrint(allocator, "{s}_{d}", .{ animation.name, frame });
}
}

return std.fmt.allocPrint(allocator, "Sprite_{d}", .{index});
}

pub fn deinit(atlas: *Atlas, allocator: std.mem.Allocator) void {
for (atlas.animations) |*animation| {
allocator.free(animation.name);
Expand Down
33 changes: 24 additions & 9 deletions src/animations.zig
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,44 @@ const std = @import("std");
const assets = @import("assets.zig");

pub var pencil_default = [_]usize {
assets.pixi_atlas.pencil_0_default,
assets.pixi_atlas.pencil_default_0,
};
pub var eraser_default = [_]usize {
assets.pixi_atlas.eraser_0_default,
assets.pixi_atlas.eraser_default_0,
};
pub var bucket_default = [_]usize {
assets.pixi_atlas.bucket_0_default,
assets.pixi_atlas.bucket_default_0,
};
pub var dropper_default = [_]usize {
assets.pixi_atlas.dropper_0_default,
assets.pixi_atlas.dropper_default_0,
};
pub var selection_default = [_]usize {
assets.pixi_atlas.selection_0_default,
assets.pixi_atlas.selection_default_0,
};
pub var selection_add_default = [_]usize {
assets.pixi_atlas.selection_add_0_default,
assets.pixi_atlas.selection_add_default_0,
};
pub var selection_rem_default = [_]usize {
assets.pixi_atlas.selection_rem_0_default,
assets.pixi_atlas.selection_rem_default_0,
};
pub var fox_default = [_]usize {
assets.pixi_atlas.fox_0_default,
assets.pixi_atlas.fox_default_0,
assets.pixi_atlas.fox_default_1,
assets.pixi_atlas.fox_default_2,
assets.pixi_atlas.fox_default_3,
assets.pixi_atlas.fox_default_4,
assets.pixi_atlas.fox_default_5,
assets.pixi_atlas.fox_default_6,
assets.pixi_atlas.fox_default_7,
assets.pixi_atlas.fox_default_8,
assets.pixi_atlas.fox_default_9,
assets.pixi_atlas.fox_default_10,
assets.pixi_atlas.fox_default_11,
assets.pixi_atlas.fox_default_12,
assets.pixi_atlas.fox_default_13,
assets.pixi_atlas.fox_default_14,
assets.pixi_atlas.fox_default_15,
};
pub var logo_default = [_]usize {
assets.pixi_atlas.logo_0_default,
assets.pixi_atlas.logo_default_0,
};
80 changes: 48 additions & 32 deletions src/assets.zig
Original file line number Diff line number Diff line change
Expand Up @@ -7,59 +7,75 @@ pub const palettes = "assets/palettes/";

pub const themes = "assets/themes/";

pub const fox_png = struct {
pub const path = "assets/fox.png";
pub const pixi_atlas = struct {
pub const path = "assets/pixi.atlas";
pub const pencil_default_0 = 0;
pub const eraser_default_0 = 1;
pub const bucket_default_0 = 2;
pub const dropper_default_0 = 3;
pub const selection_default_0 = 4;
pub const selection_add_default_0 = 5;
pub const selection_rem_default_0 = 6;
pub const fox_default_0 = 7;
pub const fox_default_1 = 8;
pub const fox_default_2 = 9;
pub const fox_default_3 = 10;
pub const fox_default_4 = 11;
pub const fox_default_5 = 12;
pub const fox_default_6 = 13;
pub const fox_default_7 = 14;
pub const fox_default_8 = 15;
pub const fox_default_9 = 16;
pub const fox_default_10 = 17;
pub const fox_default_11 = 18;
pub const fox_default_12 = 19;
pub const fox_default_13 = 20;
pub const fox_default_14 = 21;
pub const fox_default_15 = 22;
pub const logo_default_0 = 23;
};

pub const fox_bg_png = struct {
pub const path = "assets/fox_bg.png";
pub const pixi_png = struct {
pub const path = "assets/pixi.png";
};

pub const apollo_hex = struct {
pub const path = "assets/palettes/apollo.hex";
pub const fox_png = struct {
pub const path = "assets/fox.png";
};

pub const endesga_16_hex = struct {
pub const path = "assets/palettes/endesga-16.hex";
pub const fox_bg_png = struct {
pub const path = "assets/fox_bg.png";
};

pub const endesga_32_hex = struct {
pub const path = "assets/palettes/endesga-32.hex";
pub const endesga_16_hex = struct {
pub const path = "assets/palettes/endesga-16.hex";
};

pub const journey_hex = struct {
pub const path = "assets/palettes/journey.hex";
pub const pear36_hex = struct {
pub const path = "assets/palettes/pear36.hex";
};

pub const lospec500_hex = struct {
pub const path = "assets/palettes/lospec500.hex";
pub const pico_8_hex = struct {
pub const path = "assets/palettes/pico-8.hex";
};

pub const pear36_hex = struct {
pub const path = "assets/palettes/pear36.hex";
pub const journey_hex = struct {
pub const path = "assets/palettes/journey.hex";
};

pub const pico_8_hex = struct {
pub const path = "assets/palettes/pico-8.hex";
pub const lospec500_hex = struct {
pub const path = "assets/palettes/lospec500.hex";
};

pub const resurrect_64_hex = struct {
pub const path = "assets/palettes/resurrect-64.hex";
pub const path = "assets/palettes/resurrect-64.hex";
};

pub const pixi_atlas = struct {
pub const path = "assets/pixi.atlas";
pub const pencil_0_default = 0;
pub const eraser_0_default = 1;
pub const bucket_0_default = 2;
pub const dropper_0_default = 3;
pub const selection_0_default = 4;
pub const selection_add_0_default = 5;
pub const selection_rem_0_default = 6;
pub const fox_0_default = 7;
pub const logo_0_default = 8;
pub const endesga_32_hex = struct {
pub const path = "assets/palettes/endesga-32.hex";
};

pub const pixi_png = struct {
pub const path = "assets/pixi.png";
pub const apollo_hex = struct {
pub const path = "assets/palettes/apollo.hex";
};

2 changes: 1 addition & 1 deletion src/editor/artboard/Artboard.zig
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ pub fn drawLogoScreen(app: *App, editor: *Editor, assets: *Assets) !void {
defer imgui.popStyleColorEx(5);
{ // Draw semi-transparent logo

const logo_sprite = atlas.sprites[pixi.atlas.logo_0_default];
const logo_sprite = atlas.sprites[pixi.atlas.logo_default_0];

const src: [4]f32 = .{
@floatFromInt(logo_sprite.source[0]),
Expand Down
10 changes: 9 additions & 1 deletion src/editor/popups/about.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,19 @@ const std = @import("std");
const pixi = @import("../../pixi.zig");
const imgui = @import("zig-imgui");

var timer: f32 = 0.0;
var sprite_index: usize = 0;

pub fn draw(editor: *pixi.Editor, assets: *pixi.Assets) !void {
if (editor.popups.about) {
imgui.openPopup("About", imgui.PopupFlags_None);
} else return;

if (timer <= 1.0)
timer += pixi.app.delta_time
else
timer = 0.0;

if (assets.getTexture(pixi.app.texture_id)) |texture| {
if (assets.getAtlas(pixi.app.atlas_id)) |atlas| {
const popup_width = 450;
Expand Down Expand Up @@ -36,7 +44,7 @@ pub fn draw(editor: *pixi.Editor, assets: *pixi.Assets) !void {
defer imgui.endPopup();
imgui.spacing();

const fox_sprite = atlas.sprites[pixi.atlas.fox_0_default];
const fox_sprite = atlas.sprites[pixi.atlas.fox_default_0];

const src: [4]f32 = .{
@floatFromInt(fox_sprite.source[0]),
Expand Down
10 changes: 5 additions & 5 deletions src/internal/File.zig
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ pub fn processSampleTool(file: *File, canvas: Canvas, options: SampleToolOptions
if (!sample_key and !sample_button) return;

imgui.setMouseCursor(imgui.MouseCursor_None);
file.camera.drawCursor(pixi.atlas.dropper_0_default, 0xFFFFFFFF);
file.camera.drawCursor(pixi.atlas.dropper_default_0, 0xFFFFFFFF);

const mouse_position = pixi.app.mouse.position;
var camera = switch (canvas) {
Expand Down Expand Up @@ -509,11 +509,11 @@ pub fn processStrokeTool(file: *File, canvas: Canvas, options: StrokeToolOptions
switch (pixi.editor.tools.current) {
.pencil, .heightmap => {
imgui.setMouseCursor(imgui.MouseCursor_None);
file.camera.drawCursor(pixi.atlas.pencil_0_default, 0xFFFFFFFF);
file.camera.drawCursor(pixi.atlas.pencil_default_0, 0xFFFFFFFF);
},
.eraser => {
imgui.setMouseCursor(imgui.MouseCursor_None);
file.camera.drawCursor(pixi.atlas.eraser_0_default, 0xFFFFFFFF);
file.camera.drawCursor(pixi.atlas.eraser_default_0, 0xFFFFFFFF);
},
else => {},
}
Expand Down Expand Up @@ -868,7 +868,7 @@ pub fn processSelectionTool(file: *File, canvas: Canvas, options: StrokeToolOpti

if (sample_key or sample_button) return;

const cursor_sprite_index: usize = if (add) pixi.atlas.selection_add_0_default else if (rem) pixi.atlas.selection_rem_0_default else pixi.atlas.selection_0_default;
const cursor_sprite_index: usize = if (add) pixi.atlas.selection_add_default_0 else if (rem) pixi.atlas.selection_rem_default_0 else pixi.atlas.selection_default_0;
imgui.setMouseCursor(imgui.MouseCursor_None);
file.camera.drawCursor(cursor_sprite_index, 0xFFFFFFFF);

Expand Down Expand Up @@ -1063,7 +1063,7 @@ pub fn processFillTool(file: *File, canvas: Canvas, options: FillToolOptions) !v
if (sample_key or sample_button) return;

imgui.setMouseCursor(imgui.MouseCursor_None);
file.camera.drawCursor(pixi.atlas.bucket_0_default, 0xFFFFFFFF);
file.camera.drawCursor(pixi.atlas.bucket_default_0, 0xFFFFFFFF);

var canvas_center_offset = canvasCenterOffset(file, canvas);
canvas_center_offset[0] += options.texture_position_offset[0];
Expand Down
2 changes: 1 addition & 1 deletion src/internal/Reference.zig
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub fn processSampleTool(reference: *Reference) void {
if (!sample_key and !sample_button) return;

imgui.setMouseCursor(imgui.MouseCursor_None);
reference.camera.drawCursor(pixi.atlas.dropper_0_default, 0xFFFFFFFF);
reference.camera.drawCursor(pixi.atlas.dropper_default_0, 0xFFFFFFFF);

const mouse_position = pixi.app.mouse.position;
var camera = reference.camera;
Expand Down
14 changes: 6 additions & 8 deletions src/tools/process_assets.zig
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,12 @@ fn process(step: *Step, options: Step.MakeOptions) anyerror!void {
try assets_writer.print("pub const {s}{s} = struct {{\n", .{ name, "_atlas" });
try assets_writer.print(" pub const path = \"{s}\";\n", .{path_fixed});

const atlas = try Atlas.loadFromFile(self.builder.allocator, file);
var atlas = try Atlas.loadFromFile(self.builder.allocator, file);

for (atlas.sprites, 0..) |sprite, i| {
const sprite_name = try self.builder.allocator.alloc(u8, sprite.name.len);
_ = std.mem.replace(u8, sprite.name, " ", "_", sprite_name);
_ = std.mem.replace(u8, sprite_name, ".", "_", sprite_name);
for (atlas.sprites, 0..) |_, i| {
const sprite_name = try atlas.spriteName(self.builder.allocator, i);
// _ = std.mem.replace(u8, sprite.name, " ", "_", sprite_name);
// _ = std.mem.replace(u8, sprite_name, ".", "_", sprite_name);

try assets_writer.print(" pub const {s} = {d};\n", .{ sprite_name, i });
}
Expand Down Expand Up @@ -120,9 +120,7 @@ fn process(step: *Step, options: Step.MakeOptions) anyerror!void {

var animation_index = animation.start;
while (animation_index < animation.start + animation.length) : (animation_index += 1) {
const sprite_name = try self.builder.allocator.alloc(u8, atlas.sprites[animation_index].name.len);
_ = std.mem.replace(u8, atlas.sprites[animation_index].name, " ", "_", sprite_name);
_ = std.mem.replace(u8, sprite_name, ".", "_", sprite_name);
const sprite_name = try atlas.spriteName(self.builder.allocator, animation_index);

try animations_writer.print(" assets.{s}_atlas.{s},\n", .{ name, sprite_name });
}
Expand Down

0 comments on commit 93d2c7c

Please sign in to comment.