lib_2daq function library

Dependencies:

Description

Functions in lib_2daq act on in-game 2da files in-place, rather than the read/write paradigm used in lib_2da. They're optimized for speed insofar as I can manage it (the 'q' stands for 'quick').

Public functions

2daq_copy_column(data_read:b, column:s, column_new:s="%column%")=(value:s) patch

Copies a column in the current 2da file to the right-hand side of the table, with new column name 'column_new'. Returns 1 if copy is successful. Stoically silent if it isn't.

2daq_copy_row(rowname_column:i, data_read:b, row:s, row_new:s="%row%")=(value:s) patch

Copies a row in the current 2da file to the bottom of the table, with new row name 'row_new'. Returns 1 if copy is successful. Stoically silent if it isn't.

If 'rowname_column' is set, the row id is looked up in that column, and column 0 is assumed to be numbered sequentially. (This is the convention for kitlist.2da.)

2daq_extract(rowname_column:i, data_read:i, row:s, column:s, case:[m=mixedixed|upper|lower])=(value:s, rownum:s, array:a) patch
2daq_extract(rowname_column:i, data_read:b, resref:s, row:s, column:s, case:s)=(value:s, array:a) action

Given a column header and/or a row header, and a 2da file resref, (or, in patch context, the current 2da file), extract the column or row as k=>v array using the row or column headers, as appropriate, as keys.

If both row and column are set, instead return the element (if any) at (row,column) as 'value', as well as its row as 'rownum'.

2daq_has_column(data_read:b, column:s)=(value:s) patch

Return 1 iff the current 2da file has 'column' as a column id.

2daq_has_row(rowname_column:i, data_read:b, row:s)=(value:s) patch

Return 1 iff the current 2da file has 'row' as a row id. (Check rowname_column).

2daq_inject(reflect:b, rowname_column:i, data_read:b, array:a)=() patch
2daq_inject(reflect:b, rowname_column:i, data_read:b, array:a, resref:s)=() action

Given a 2D struct 'array' and a 2da file resref, (or, in patch context, the current 2da file) insert the elements of the struct into the 2da. (i.e. if the struct contains "array_x_y" and x and y are row and column entries in the 2da, insert the value of array_x_y at (x,y).

If reflect=1, swap rows and columns. If rowname_column is nonzero, look up the row names in that column.

2daq_insert_column(column:s, insert_loc:[l="last"ast|before_last])=() patch

Adds a new column, with header 'column', as the last column, or the second-to-last column if insert_loc is 'before_last'. All entries are filled with the 2da default value.

2daq_insert_row(rowname_column:i, row:s)=() patch

Adds a new row, with header 'row', as the last row. All entries are filled with the 2da default value. If rowname_column>0, we put the header in this column, and assume column 0 should be numbered sequentially from 0.