Skip to content

Commit

Permalink
Remove useless Sprite.index
Browse files Browse the repository at this point in the history
  • Loading branch information
foxnne committed Jan 31, 2025
1 parent 2429919 commit 882c27d
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 20 deletions.
7 changes: 3 additions & 4 deletions src/editor/Editor.zig
Original file line number Diff line number Diff line change
Expand Up @@ -325,12 +325,11 @@ pub fn newFile(editor: *Editor, path: [:0]const u8, import_path: ?[:0]const u8)
// Create sprites for all tiles.
{
const tiles = @as(usize, @intCast(editor.popups.file_setup_tiles[0] * editor.popups.file_setup_tiles[1]));
try internal.sprites.setCapacity(pixi.app.allocator, tiles);

var i: usize = 0;
while (i < tiles) : (i += 1) {
const sprite: pixi.Internal.Sprite = .{
.index = i,
};
try internal.sprites.append(pixi.app.allocator, sprite);
internal.sprites.appendAssumeCapacity(.{});
}
}

Expand Down
9 changes: 4 additions & 5 deletions src/editor/explorer/animations.zig
Original file line number Diff line number Diff line change
Expand Up @@ -88,18 +88,17 @@ pub fn draw(editor: *Editor) !void {
while (i < animation.start + animation.length) : (i += 1) {
var sprite_index: usize = 0;
while (sprite_index < file.sprites.slice().len) : (sprite_index += 1) {
const sprite = file.sprites.slice().get(sprite_index);
if (i == sprite.index) {
const color = if (file.selected_sprite_index == sprite.index) editor.theme.text.toImguiVec4() else editor.theme.text_secondary.toImguiVec4();
if (i == sprite_index) {
const color = if (file.selected_sprite_index == sprite_index) editor.theme.text.toImguiVec4() else editor.theme.text_secondary.toImguiVec4();
imgui.pushStyleColorImVec4(imgui.Col_Text, color);
defer imgui.popStyleColor();

const sprite_name = try file.calculateSpriteName(editor.arena.allocator(), sprite.index);
const sprite_name = try file.calculateSpriteName(editor.arena.allocator(), sprite_index);

if (imgui.selectable(sprite_name)) {
file.flipbook_scroll_request = .{
.from = file.flipbook_scroll,
.to = file.flipbookScrollFromSpriteIndex(sprite.index),
.to = file.flipbookScrollFromSpriteIndex(sprite_index),
.state = file.selected_animation_state,
};
}
Expand Down
7 changes: 3 additions & 4 deletions src/editor/explorer/keyframe_animations.zig
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ pub fn draw(editor: *Editor) !void {
const frame = keyframe.frames.items[i];

const color = animation.getFrameNodeColor(frame.id);
const sprite = file.sprites.slice().get(frame.sprite_index);

const sprite_name = try std.fmt.allocPrintZ(editor.arena.allocator(), "{s}##{d}{d}{d}", .{
try file.calculateSpriteName(editor.arena.allocator(), frame.sprite_index),
Expand All @@ -129,10 +128,10 @@ pub fn draw(editor: *Editor) !void {
imgui.sameLine();

if (imgui.selectable(sprite_name)) {
for (file.selected_sprites.items) |selected_sprite| {
if (selected_sprite != sprite.index or file.selected_sprites.items.len > 1) {
for (file.selected_sprites.items, 0..) |selected_sprite, sprite_index| {
if (selected_sprite != sprite_index or file.selected_sprites.items.len > 1) {
file.selected_sprites.clearAndFree();
try file.selected_sprites.append(sprite.index);
try file.selected_sprites.append(sprite_index);
}
}
file.selected_keyframe_animation_index = animation_index;
Expand Down
7 changes: 3 additions & 4 deletions src/editor/explorer/sprites.zig
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,16 @@ pub fn draw(editor: *Editor) !void {

var sprite_index: usize = 0;
while (sprite_index < file.sprites.slice().len) : (sprite_index += 1) {
const sprite = file.sprites.slice().get(sprite_index);
const selected_sprite_index = file.spriteSelectionIndex(sprite.index);
const selected_sprite_index = file.spriteSelectionIndex(sprite_index);
const contains = selected_sprite_index != null;
const color = if (contains) editor.theme.text.toImguiVec4() else editor.theme.text_secondary.toImguiVec4();
imgui.pushStyleColorImVec4(imgui.Col_Text, color);
defer imgui.popStyleColor();

const name = try file.calculateSpriteName(editor.arena.allocator(), sprite.index);
const name = try file.calculateSpriteName(editor.arena.allocator(), sprite_index);

if (imgui.selectableEx(name, contains, imgui.SelectableFlags_None, .{ .x = 0.0, .y = 0.0 })) {
try file.makeSpriteSelection(sprite.index);
try file.makeSpriteSelection(sprite_index);
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/internal/File.zig
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,8 @@ pub fn load(path: [:0]const u8) !?pixi.Internal.File {
}
_ = zip.zip_entry_close(pixi_file);

for (ext.sprites, 0..) |sprite, i| {
for (ext.sprites) |sprite| {
try internal.sprites.append(pixi.app.allocator, .{
.index = i,
.origin = .{ @floatFromInt(sprite.origin[0]), @floatFromInt(sprite.origin[1]) },
});
}
Expand Down
1 change: 0 additions & 1 deletion src/internal/Sprite.zig
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
index: usize,
origin: [2]f32 = .{ 0.0, 0.0 },

0 comments on commit 882c27d

Please sign in to comment.