Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get rid of gItemIconTable #4579

Merged
merged 4 commits into from
May 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions include/item.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ struct Item
u8 type;
u8 battleUsage;
u8 flingPower;
const u32 *iconSprite;
const u32 *iconPalette;
};

struct BagPocket
Expand Down
3 changes: 2 additions & 1 deletion include/item_icon.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ void FreeItemIconTemporaryBuffers(void);
void CopyItemIconPicTo4x4Buffer(const void *src, void *dest);
u8 AddItemIconSprite(u16 tilesTag, u16 paletteTag, u16 itemId);
u8 AddCustomItemIconSprite(const struct SpriteTemplate *customSpriteTemplate, u16 tilesTag, u16 paletteTag, u16 itemId);
const void *GetItemIconPicOrPalette(u16 itemId, u8 which);
const void *GetItemIconSprite(u16 itemId);
const void *GetItemIconPalette(u16 itemId);

#endif //GUARD_ITEM_ICON_H
45 changes: 45 additions & 0 deletions migration_scripts/convert_item_icons.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import glob
import re
import os

if not os.path.exists("Makefile"):
print("Please run this script from your root folder.")
quit()

# Read item_icon_table.h and extract the icon and palette information
for file in glob.glob('./src/data/item_icon_table.h'):
with open(file, 'r') as f:
icon_table_content = f.read()

# Extract item icon and palette data from item_icon_table.h
icon_table_pattern = re.compile(r'\[(ITEM_[A-Z_0-9]+)\]\s*=\s*\{([^,]+),\s*([^}]+)\}', re.MULTILINE)
icon_table_data = {}
for match in icon_table_pattern.findall(icon_table_content):
if len(match) == 3:
item_name, icon_sprite, icon_palette = match
icon_table_data[item_name] = (icon_sprite, icon_palette)

# Read items.h content
for file in glob.glob('./src/data/items.h'):
with open(file, 'r') as f:
items_content = f.read()

# Modify items.h content
def add_icon_data(match):
item_name = match.group(1)
item_content = match.group(2)
if item_name in icon_table_data:
icon_sprite, icon_palette = icon_table_data[item_name]
print(f"Updating {item_name}: adding iconSprite = {icon_sprite}, iconPalette = {icon_palette}")
return f'[{item_name}] =\n {{{item_content} .iconSprite = {icon_sprite},\n .iconPalette = {icon_palette},\n }},'
else:
return match.group(0)

item_pattern = re.compile(r'\[(ITEM_[A-Z_0-9]+)\]\s*=\s*\{([\s\S]*?)\},', re.DOTALL)
modified_items_content = item_pattern.sub(add_icon_data, items_content)

# Write the modified content back to items.h
for file in glob.glob('./src/data/items.h'):
with open(file, 'w') as f:
f.write(modified_items_content)
print("items.h has been updated")
770 changes: 1 addition & 769 deletions src/data/item_icon_table.h

Large diffs are not rendered by default.

Loading
Loading