Skip to content

Commit

Permalink
Get rid of gItemIconTable (#4579)
Browse files Browse the repository at this point in the history
* Get rid of gItemIconTable

* Move the script to the folder
  • Loading branch information
kittenchilly committed May 18, 2024
1 parent b4ece97 commit 4b221b5
Show file tree
Hide file tree
Showing 8 changed files with 1,550 additions and 831 deletions.
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

0 comments on commit 4b221b5

Please sign in to comment.