This commit is contained in:
asrael 2025-11-01 12:39:59 -05:00
parent e862b02019
commit 0ed7fc4496
No known key found for this signature in database
GPG key ID: 2786557804DFAE24
21 changed files with 1267 additions and 148 deletions

View file

@ -270,6 +270,36 @@ u16 pxl8_tilesheet_get_animated_frame(const pxl8_tilesheet* tilesheet, u16 tile_
return anim->frames[anim->current_frame];
}
pxl8_result pxl8_tilesheet_set_tile_pixels(pxl8_tilesheet* tilesheet, u16 tile_id, const u8* pixels) {
if (!tilesheet || !pixels || tile_id == 0 || tile_id > tilesheet->total_tiles) return PXL8_ERROR_INVALID_ARGUMENT;
if (!tilesheet->data) return PXL8_ERROR_NULL_POINTER;
u32 tile_x = (tile_id - 1) % tilesheet->tiles_per_row;
u32 tile_y = (tile_id - 1) / tilesheet->tiles_per_row;
u32 bytes_per_pixel = (tilesheet->color_mode == PXL8_COLOR_MODE_HICOLOR) ? 4 : 1;
for (u32 py = 0; py < tilesheet->tile_size; py++) {
for (u32 px = 0; px < tilesheet->tile_size; px++) {
u32 src_idx = py * tilesheet->tile_size + px;
u32 dst_x = tile_x * tilesheet->tile_size + px;
u32 dst_y = tile_y * tilesheet->tile_size + py;
u32 dst_idx = (dst_y * tilesheet->width + dst_x) * bytes_per_pixel;
if (bytes_per_pixel == 4) {
((u32*)tilesheet->data)[dst_idx / 4] = pixels[src_idx];
} else {
tilesheet->data[dst_idx] = pixels[src_idx];
}
}
}
if (tilesheet->tile_valid) {
tilesheet->tile_valid[tile_id] = true;
}
return PXL8_OK;
}
void pxl8_tilesheet_set_tile_property(pxl8_tilesheet* tilesheet, u16 tile_id,
const pxl8_tile_properties* props) {
if (!tilesheet || !props || tile_id == 0 || tile_id > tilesheet->total_tiles) return;