Sync with pokecrystal up to 8873506b1

This commit is contained in:
xCrystal
2023-07-26 20:50:16 -04:00
parent 193882bc77
commit d6001be90c
30 changed files with 213 additions and 117 deletions

34
tools/dupeframes.py Executable file
View File

@@ -0,0 +1,34 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Usage: python dupeframes.py
Check for duplicate frames in Pokemon sprites (gfx/pokemon/*/front.png).
"""
import sys
import glob
import png
def check_duplicate_frames(filename):
with open(filename, 'rb') as file:
width, height, rows = png.Reader(file).asRGBA8()[:3]
rows = list(rows)
if height % width:
print(f'{filename} is not a vertical strip of square frames!', file=sys.stderr)
return
num_frames = height // width
frames = [rows[i*width:(i+1)*width] for i in range(num_frames)]
for i in range(num_frames):
for j in range(i + 1, num_frames):
if frames[i] == frames[j]:
print(f'{filename}: frame {j} is a duplicate of frame {i}', file=sys.stderr)
def main():
for filename in sorted(glob.glob('gfx/pokemon/*/front.png')):
check_duplicate_frames(filename)
if __name__ == '__main__':
main()

View File

@@ -3,6 +3,8 @@
#include "common.h"
#include <ctype.h>
void parse_args(int argc, char *argv[], bool *strict) {
struct option long_options[] = {
{"strict", no_argument, 0, 's'},
@@ -40,31 +42,47 @@ void scan_file(const char *filename, bool strict) {
fclose(f);
contents[size] = '\0';
for (char *ptr = contents; ptr && ptr - contents < size; ptr++) {
bool is_incbin = false, is_include = false;
for (char *ptr = contents; ptr && ptr < contents + size; ptr++) {
ptr = strpbrk(ptr, ";\"Ii");
if (!ptr) {
break;
}
switch (*ptr) {
case ';':
ptr = strchr(ptr, '\n');
if (!ptr) {
fprintf(stderr, "%s: no newline at end of file\n", filename);
}
break;
case '"':
ptr++;
ptr = strchr(ptr, '"');
if (ptr) {
// Skip comments until the end of the line
ptr += strcspn(ptr + 1, "\r\n");
if (*ptr) {
ptr++;
} else {
fprintf(stderr, "%s: unterminated string\n", filename);
}
break;
case '"':
// Skip string literal until the closing quote
ptr += strcspn(ptr + 1, "\"");
if (*ptr) {
ptr++;
}
break;
case 'I':
case 'i':
is_incbin = !strncmp(ptr, "INCBIN", 6) || !strncmp(ptr, "incbin", 6);
is_include = !strncmp(ptr, "INCLUDE", 7) || !strncmp(ptr, "include", 7);
/* empty statement between the label and the variable declaration */;
// Check that an INCLUDE/INCBIN starts as its own token
char before = ptr > contents ? *(ptr - 1) : '\n';
if (!isspace((unsigned)before) && before != ':') {
break;
}
bool is_incbin = !strncmp(ptr, "INCBIN", 6) || !strncmp(ptr, "incbin", 6);
bool is_include = !strncmp(ptr, "INCLUDE", 7) || !strncmp(ptr, "include", 7);
if (is_incbin || is_include) {
ptr = strchr(ptr, '"');
if (ptr) {
// Check that an INCLUDE/INCBIN ends as its own token
ptr += is_include ? 7 : 6;
if (!isspace((unsigned)*ptr) && *ptr != '"') {
break;
}
ptr += strspn(ptr, " \t");
if (*ptr == '"') {
// Print the file path and recursively scan INCLUDEs
ptr++;
char *include_path = ptr;
size_t length = strcspn(ptr, "\"");
@@ -74,6 +92,12 @@ void scan_file(const char *filename, bool strict) {
if (is_include) {
scan_file(include_path, strict);
}
} else {
fprintf(stderr, "%s: no file path after INC%s\n", filename, is_include ? "LUDE" : "BIN");
// Continue to process a comment
if (*ptr == ';') {
ptr--;
}
}
}
break;