Skip to content

Commit

Permalink
Merge pull request #24 from GraionDilach/handle-2da-coloumns
Browse files Browse the repository at this point in the history
Handle 2da coloumns
  • Loading branch information
DaerosTrollkiller authored May 3, 2023
2 parents f2d04f5 + 31bb801 commit 2b40d58
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 19 deletions.
44 changes: 43 additions & 1 deletion sod2bg2_iu/lib/functions.tpa
Original file line number Diff line number Diff line change
Expand Up @@ -423,4 +423,46 @@ END

////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////

// Ensure all table rows have valid number of columns.
// Missing headers are padded by column indices. Missing content is padded by default value.
DEFINE_PATCH_FUNCTION a7#normalize_table
BEGIN
SET num_added = 0
COUNT_2DA_COLS num_cols
READ_2DA_ENTRIES_NOW table 1
READ_2DA_ENTRY_FORMER table 1 0 default
FOR (row = 0; row < table; ++row) BEGIN
READ_2DA_ENTRY_FORMER table row 0 line
FOR (col = 1; col < num_cols && VARIABLE_IS_SET $table(~%row%~ ~%col%~); ++col) BEGIN
READ_2DA_ENTRY_FORMER table row col v
TEXT_SPRINT line ~%line% %v%~
END
// fill in missing data
PATCH_IF (row = 2) BEGIN // header
FOR (; col < num_cols - 1; ++col) BEGIN
TEXT_SPRINT line ~%line% %col%~
SET num_added += 1
END
END ELSE PATCH_IF (row > 2) BEGIN // content
FOR (; col < num_cols; ++col) BEGIN
TEXT_SPRINT line ~%line% %default%~
SET num_added += 1
END
END
TEXT_SPRINT $lines(~%row%~) ~%line%%LNL%~
SET $lines(~%row%~ ~size~) = STRING_LENGTH $lines(~%row%~)
END

// write normalized table to buffer
PATCH_IF (num_added > 0) BEGIN
DELETE_BYTES 0 BUFFER_LENGTH
FOR (row = 0 pos = 0; row < table; ++row) BEGIN
SET size = $lines(~%row%~ ~size~)
INSERT_BYTES pos size
WRITE_ASCIIE pos $lines(~%row%~) (size)
SET pos += size
END
END
END
35 changes: 17 additions & 18 deletions sod2bg2_iu/sod2bg2_iu.tp2
Original file line number Diff line number Diff line change
Expand Up @@ -388,8 +388,8 @@ COPY ~sod2bg2_iu/cre/dtkshdel.cre~ ~override~ //Shadow Elemental - Berserk
ACTION_IF FILE_EXISTS_IN_GAME ~lichtoo.bcs~ BEGIN // check if already present first
COMPILE ~sod2bg2_iu/scripts/dtklicht.baf~ ~override~ //new script for Diedrex's Tower to not take tooth.
COPY_EXISTING ~ar2200.are~ ~override~
WRITE_ASCII 0x59c0 ~dtklicht~
WRITE_ASCII 0x5a84 ~dtklicht~
LPF ALTER_AREA_REGION STR_VAR region_name = ~LichTooth1~ region_script = ~dtklicht~ END
LPF ALTER_AREA_REGION STR_VAR region_name = ~LichTooth2~ region_script = ~dtklicht~ END
END


Expand Down Expand Up @@ -6233,10 +6233,6 @@ COPY_EXISTING ~wmart2.sto~ ~override~ //Diedre

COPY - ~sod2bg2_iu/2da/tooltip.2da~ ~sod2bg2_iu/2da/tooltip.2da~
READ_2DA_ENTRIES_NOW r2en_tooltip 1

COPY_EXISTING ~tooltip.2da~ ~override~
COUNT_2DA_COLS num_cols
COUNT_2DA_ROWS num_cols num_rows
FOR (row = 0; row < r2en_tooltip; row += 1) BEGIN
READ_2DA_ENTRY_FORMER r2en_tooltip row 0 item
READ_2DA_ENTRY_FORMER r2en_tooltip row 1 ability1
Expand All @@ -6245,11 +6241,15 @@ COPY_EXISTING ~tooltip.2da~ ~override~
LPF RESOLVE_REF STR_VAR ref = EVAL ~%ability1%~ RET ability1 = strref END
LPF RESOLVE_REF STR_VAR ref = EVAL ~%ability2%~ RET ability2 = strref END
LPF RESOLVE_REF STR_VAR ref = EVAL ~%ability3%~ RET ability3 = strref END
INSERT_2DA_ROW num_rows num_cols ~%item% %ability1% %ability2% %ability3%~
SET num_rows += 1
PRETTY_PRINT_2DA
INNER_ACTION BEGIN
APPEND ~tooltip.2da~ ~%item% %ability1% %ability2% %ability3%~
END
END
BUT_ONLY

COPY_EXISTING ~tooltip.2da~ ~override~
LPF a7#normalize_table END
BUT_ONLY

//////////////////////////////////////////////////
//Updating Reflection Shield for new projectiles//
Expand Down Expand Up @@ -7867,10 +7867,6 @@ COPY ~sod2bg2_iu/itm/scrolls/dtkascrl.itm~ ~override~

COPY - ~sod2bg2_iu/2da/rndtres.2da~ ~sod2bg2_iu/2da/rndtres.2da~
READ_2DA_ENTRIES_NOW r2en_rndtres 1

COPY_EXISTING ~rndtres.2da~ ~override~
COUNT_2DA_COLS num_cols
COUNT_2DA_ROWS num_cols num_rows
FOR (row = 0; row < r2en_rndtres; row += 1) BEGIN
READ_2DA_ENTRY_FORMER r2en_rndtres row 0 item
READ_2DA_ENTRY_FORMER r2en_rndtres row 1 tres1
Expand Down Expand Up @@ -7913,12 +7909,15 @@ COPY_EXISTING ~rndtres.2da~ ~override~
READ_2DA_ENTRY_FORMER r2en_rndtres row 38 tres38
READ_2DA_ENTRY_FORMER r2en_rndtres row 39 tres39
READ_2DA_ENTRY_FORMER r2en_rndtres row 40 tres40
INSERT_2DA_ROW num_rows num_cols ~%item% %tres1% %tres2% %tres3% %tres4% %tres5% %tres6% %tres7% %tres8% %tres9% %tres10% %tres11% %tres12% %tres13% %tres14% %tres15% %tres16% %tres17% %tres18% %tres19% %tres20% %tres21% %tres22% %tres23% %tres24% %tres25% %tres26% %tres27% %tres28% %tres29% %tres30% %tres31% %tres32% %tres33% %tres34% %tres35% %tres36% %tres37% %tres38% %tres39% %tres40%~
SET num_rows += 1
PRETTY_PRINT_2DA
END
BUT_ONLY
INNER_ACTION BEGIN
APPEND ~rndtres.2da~ ~%item% %tres1% %tres2% %tres3% %tres4% %tres5% %tres6% %tres7% %tres8% %tres9% %tres10% %tres11% %tres12% %tres13% %tres14% %tres15% %tres16% %tres17% %tres18% %tres19% %tres20% %tres21% %tres22% %tres23% %tres24% %tres25% %tres26% %tres27% %tres28% %tres29% %tres30% %tres31% %tres32% %tres33% %tres34% %tres35% %tres36% %tres37% %tres38% %tres39% %tres40%~
END
END
BUT_ONLY

COPY_EXISTING ~rndtres.2da~ ~override~
LPF a7#normalize_table END
BUT_ONLY


////////////////////////////////////////////////////////////////////////
Expand Down

0 comments on commit 2b40d58

Please sign in to comment.