Skip to content

Commit aad22fe

Browse files
committed
Add better message notes
1 parent 498be4f commit aad22fe

File tree

2 files changed

+46
-9
lines changed

2 files changed

+46
-9
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ void TraceAseprite(Aseprite aseprite); // Display a
7575
Texture GetAsepriteTexture(Aseprite aseprite); // Retrieve the raylib texture associated with the aseprite
7676
int GetAsepriteWidth(Aseprite aseprite); // Get the width of the sprite
7777
int GetAsepriteHeight(Aseprite aseprite); // Get the height of the sprite
78-
int GetAsepriteTagCount(Aseprite aseprite); // Get the total amount of available tags
78+
int GetAsepriteTagCount(Aseprite aseprite); // Get the total amount of available tags
7979
void DrawAseprite(Aseprite aseprite, int frame, int posX, int posY, Color tint);
8080
void DrawAsepriteV(Aseprite aseprite, int frame, Vector2 position, Color tint);
8181
void DrawAsepriteEx(Aseprite aseprite, int frame, Vector2 position, float rotation, float scale, Color tint);

include/raylib-aseprite.h

Lines changed: 45 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ void TraceAseprite(Aseprite aseprite); // Display a
7777
Texture GetAsepriteTexture(Aseprite aseprite); // Retrieve the raylib texture associated with the aseprite
7878
int GetAsepriteWidth(Aseprite aseprite); // Get the width of the sprite
7979
int GetAsepriteHeight(Aseprite aseprite); // Get the height of the sprite
80-
int GetAsepriteTagCount(Aseprite aseprite); // Get the total amount of available tags
80+
int GetAsepriteTagCount(Aseprite aseprite); // Get the total amount of available tags
8181
void DrawAseprite(Aseprite aseprite, int frame, int posX, int posY, Color tint);
8282
void DrawAsepriteV(Aseprite aseprite, int frame, Vector2 position, Color tint);
8383
void DrawAsepriteEx(Aseprite aseprite, int frame, Vector2 position, float rotation, float scale, Color tint);
@@ -228,6 +228,8 @@ Aseprite LoadAsepriteFromMemory(unsigned char* fileData, unsigned int size) {
228228
texturePointer->width = texture.width;
229229
texturePointer->height = texture.height;
230230
aseprite.ase = ase;
231+
TraceLog(LOG_INFO, "ASEPRITE: Loaded successfully (%ix%i - %i frames)", ase->w, ase->h, ase->frame_count);
232+
231233
return aseprite;
232234
}
233235

@@ -285,6 +287,7 @@ inline Texture GetAsepriteTexture(Aseprite aseprite) {
285287
texture.format = 0;
286288
return texture;
287289
}
290+
288291
Texture2D* texturePointer = (Texture2D*)aseprite.ase->mem_ctx;
289292
return *texturePointer;
290293
}
@@ -301,6 +304,7 @@ int GetAsepriteWidth(Aseprite aseprite) {
301304
TraceLog(LOG_WARNING, "ASEPRITE: Cannot get width from non-existant aseprite");
302305
return 0;
303306
}
307+
304308
return aseprite.ase->w;
305309
}
306310

@@ -316,6 +320,7 @@ int GetAsepriteHeight(Aseprite aseprite) {
316320
TraceLog(LOG_WARNING, "ASEPRITE: Cannot get width from non-existant aseprite");
317321
return 0;
318322
}
323+
319324
return aseprite.ase->h;
320325
}
321326

@@ -331,6 +336,7 @@ int GetAsepriteTagCount(Aseprite aseprite) {
331336
TraceLog(LOG_WARNING, "ASEPRITE: Cannot get tag count non-existant aseprite");
332337
return 0;
333338
}
339+
334340
return aseprite.ase->tag_count;
335341
}
336342

@@ -358,6 +364,8 @@ void UnloadAseprite(Aseprite aseprite) {
358364

359365
// Destory the aseprite data.
360366
cute_aseprite_free(ase);
367+
368+
TraceLog(LOG_INFO, "ASEPRITE: Unloaded Aseprite data successfully");
361369
}
362370

363371
void DrawAseprite(Aseprite aseprite, int frame, int posX, int posY, Color tint) {
@@ -406,14 +414,11 @@ void DrawAsepritePro(Aseprite aseprite, int frame, Rectangle dest, Vector2 origi
406414
void TraceAseprite(Aseprite aseprite) {
407415
ase_t* ase = aseprite.ase;
408416
if (ase == 0) {
409-
TraceLog(LOG_INFO, "ASEPRITE: Empty file information");
417+
TraceLog(LOG_INFO, "ASEPRITE: Empty Aseprite information");
410418
return;
411419
}
412420

413-
TraceLog(LOG_INFO, "ASEPRITE: File information:");
414-
TraceLog(LOG_INFO, " > Size: %ix%i", ase->w, ase->h);
415-
TraceLog(LOG_INFO, " > Frames: %i", ase->frame_count);
416-
TraceLog(LOG_INFO, " > Slices: %i", ase->slice_count);
421+
TraceLog(LOG_INFO, "ASEPRITE: Aseprite information: (%ix%i - %i frames)", ase->w, ase->h, ase->frame_count);
417422
TraceLog(LOG_INFO, " > Colors: %i", ase->number_of_colors);
418423
TraceLog(LOG_INFO, " > Mode: %i", ase->mode);
419424
TraceLog(LOG_INFO, " > Layers: %i", ase->layer_count);
@@ -427,6 +432,12 @@ void TraceAseprite(Aseprite aseprite) {
427432
ase_tag_t* tag = ase->tags + i;
428433
TraceLog(LOG_INFO, " - %s", tag->name);
429434
}
435+
436+
TraceLog(LOG_INFO, " > Slices: %i", ase->slice_count);
437+
for (int i = 0; i < ase->slice_count; i++) {
438+
ase_slice_t* slice = ase->slices + i;
439+
TraceLog(LOG_INFO, " - %s", slice->name);
440+
}
430441
}
431442

432443
/**
@@ -530,6 +541,8 @@ void DrawAsepriteTagPro(AsepriteTag tag, Rectangle dest, Vector2 origin, float r
530541

531542
/**
532543
* Generate an aseprite tag with sane defaults.
544+
*
545+
* @return An AsepriteTag with sane defaults.
533546
*/
534547
AsepriteTag GenAsepriteTagDefault() {
535548
struct AsepriteTag tag;
@@ -543,6 +556,7 @@ AsepriteTag GenAsepriteTagDefault() {
543556
tag.loop = true;
544557
tag.paused = false;
545558
tag.name = 0;
559+
546560
return tag;
547561
}
548562

@@ -559,30 +573,51 @@ AsepriteTag GenAsepriteTagDefault() {
559573
*/
560574
AsepriteTag LoadAsepriteTagFromIndex(Aseprite aseprite, int index) {
561575
AsepriteTag tag = GenAsepriteTagDefault();
576+
577+
// Ensure the Aseprite exists.
562578
ase_t* ase = aseprite.ase;
563579
if (ase == 0) {
564580
TraceLog(LOG_ERROR, "ASEPRITE: Asprite not loaded when attempting to load tag #%i", index);
565581
return tag;
566582
}
567583

584+
// Ensure the tag exists
568585
if (index < 0 || index >= ase->tag_count) {
569586
TraceLog(LOG_ERROR, "ASEPRITE: Tag index %i out of range for %i tags", index, ase->tag_count);
570587
return tag;
571588
}
572589

590+
// Base tag information
573591
tag.aseprite.ase = aseprite.ase;
574592
tag.tag = &ase->tags[index];
575-
tag.currentFrame = tag.tag->from_frame;
593+
594+
// Set up the frame range
576595
tag.direction = 1;
596+
tag.currentFrame = tag.tag->from_frame;
577597
if (tag.tag->loop_animation_direction == ASE_ANIMATION_DIRECTION_BACKWORDS) {
578598
tag.currentFrame = tag.tag->to_frame;
579599
tag.direction = -1;
580600
}
581-
tag.timer = (float)(ase->frames[tag.currentFrame].duration_milliseconds) / 1000.0f; // Timer in seconds.
601+
602+
// Pause the animation if it's a one-frame tag
603+
if (tag.tag->from_frame == tag.tag->to_frame) {
604+
tag.paused = true;
605+
}
606+
607+
// Timer in seconds
608+
tag.timer = (float)(ase->frames[tag.currentFrame].duration_milliseconds) / 1000.0f;
609+
610+
// Color
582611
tag.color.r = (unsigned char)tag.tag->r;
583612
tag.color.g = (unsigned char)tag.tag->g;
584613
tag.color.b = (unsigned char)tag.tag->b;
614+
615+
// Name
585616
tag.name = (char*)tag.tag->name;
617+
618+
// Display a trace log about the aseprite tag
619+
TraceLog(LOG_TRACE, "ASEPRITE: [ID %i] Asprite tag loaded successfully (%s)", index, tag.name);
620+
586621
return tag;
587622
}
588623

@@ -612,7 +647,9 @@ AsepriteTag LoadAsepriteTag(Aseprite aseprite, const char* name) {
612647
}
613648
}
614649

650+
// Display a warning about the missing aseprite
615651
TraceLog(LOG_WARNING, "ASEPRITE: Could not find tag \"%s\"", name);
652+
616653
return tag;
617654
}
618655

0 commit comments

Comments
 (0)