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

Use a row macro to ensure each row of a table goes with its corresponding index #612

Open
Rangi42 opened this issue Mar 28, 2021 · 2 comments

Comments

@Rangi42
Copy link
Owner

Rangi42 commented Mar 28, 2021

Something like this:

 table_width: MACRO
 CURRENT_TABLE_WIDTH = \1
 if _NARG == 2
 REDEF CURRENT_TABLE_START EQUS "\2"
 else
 REDEF CURRENT_TABLE_START EQUS "._table_width\@"
 {CURRENT_TABLE_START}:
+if _NARG == 3
+row_value = \3
+elif _NARG == 2 && ISCONST(\2)
+row_value = \2
+else
+row_value = 0
+endc
 endc
 ENDM
 
+row: MACRO
+x = \1
+	assert row_value == x, \
+		"{CURRENT_TABLE_START}: expected row for \1 to be at value {d:x}, got {d:row_value}"
+	shift
+	if _NARG
+		\#
+	endc
+row_value = row_value + 1
+ENDM
 list_start: MACRO
 list_index = 0
 if _NARG == 1
 REDEF CURRENT_LIST_START EQUS "\1"
 else
 REDEF CURRENT_LIST_START EQUS "._list_start\@"
 {CURRENT_LIST_START}:
+if _NARG == 2
+row_value = \2
+elif _NARG == 1 && ISCONST(\1)
+row_value = \1
+else
+row_value = 0
+endc
 endc
 ENDM
 
 li: MACRO
 	assert !STRIN(\1, "@"), STRCAT("String terminator \"@\" in list entry: ", \1)
+x = \1
+	assert row_value == x, \
+		"{CURRENT_LIST_START}: expected li for \1 to be at value {d:x}, got {d:row_value}"
+	shift
+	if _NARG
+		\#
+	endc
+row_value = row_value + 1
 	db \1, "@"
 list_index = list_index + 1
 ENDM

Example usage:

ItemDescriptions:
	table_width 2, ItemDescriptions, 1
	row POKE_BALL,  dw PokeBallDesc
	row GREAT_BALL, dw GreatBallDesc
	row ULTRA_BALL, dw UltraBallDesc
	...
item_attribute: MACRO
; constant, price, held effect, parameter, pocket, field menu, battle menu
	row \1
	dw \2
	db \3, \4, \5
	dn \6, \7
ENDM

ItemAttributes:
	table_width ITEMATTR_STRUCT_LENGTH, ItemAttributes, 1
	item_attribute POKE_BALL,  200, 0, 0, BALL, ITEMMENU_PARTY, ITEMMENU_CLOSE
	item_attribute GREAT_BALL, 600, 0, 0, BALL, ITEMMENU_PARTY, ITEMMENU_CLOSE
	item_attribute ULTRA_BALL, 800, 0, 0, BALL, ITEMMENU_PARTY, ITEMMENU_CLOSE
	...
ItemNames::
	list_start ItemNames   ; defaults like `list_start ItemNames, 0`
	li PARK_BALL,  "Park Ball"
	li POKE_BALL,  "Poké Ball"
	li GREAT_BALL, "Great Ball"
	...
@Rangi42
Copy link
Owner Author

Rangi42 commented Mar 28, 2021

Also consider base_data_for BULBASAUR and end_base_data macros to ensure the size of each base data entry file as well as its corresponding constant.

@Rangi42
Copy link
Owner Author

Rangi42 commented Mar 28, 2021

Following discussion in pret #pokecrystal with dannye, I think we should avoid doing row CONSTANT, db ...; it's potentially confusing. Let's try adding macros db_for, dw_for, dba_for, and then a row_for to be used within the already-existing table entry macros. If some tables have more complex entries like dbbw, then instead of defining dbbw_for, that's probably a cue to give that table its own entry macro with individual row_for, db, db, dw within it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants