import { Item } from "../../items/types/Item" ; import { layout } from "../layout" ; import { PlugyStash } from "../../plugy-stash/types" ; import { makeIndex } from "../../plugy-stash/makeIndex" ; import { RUNEWORDS } from "../../../game-data" ; import { getBase } from "../../items/getBase" ; import { EQUIPMENT_TYPES } from "../list/uniquesOrder" ; import { addPage } from "../../plugy-stash/addPage" ; import { moveItem } from "../../items/moving/safeMove" ; function runewordsOrder ( a , b ) { return RUNEWORDS [ a . runewordId ! ] . levelReq - RUNEWORDS [ b . runewordId ! ] . levelReq ; } function basesOrder ( a , b ) { const baseA = getBase ( a ) ; const baseB = getBase ( b ) ; return ( EQUIPMENT_TYPES . indexOf ( baseA . type ) - EQUIPMENT_TYPES . indexOf ( baseB . type ) || baseB . qlevel - baseA . qlevel || ( b . sockets ?? 0 ) - ( a . sockets ?? 0 ) || ( b . quality ?? 0 ) - ( a . quality ?? 0 ) ) ; } export function organizeRunewords ( stash , both ) { if ( both . length === 0 ) return ; const runewords = [ ] ; const bases = [ ] ; for ( const item of both ) { if ( item . runeword ) { runewords . push ( item ) ; } else { bases . push ( item ) ; } } runewords . sort ( runewordsOrder ) ; bases . sort ( basesOrder ) ; let offset = stash . pages . length ; [ [ "Runewords" , runewords ] as const , [ "Bases" , bases ] as const ] . forEach ( ( [ name , items ] , i ) => { const { nbPages , positions } = layout ( "lines" , [ items ] ) ; for ( let j = 0 ; j < nbPages ; j ++ ) { const page = addPage ( stash , name ) ; if ( j === 0 ) { makeIndex ( page , i === 0 ) ; } } for ( const [ item , { page , rows , cols } ] of positions . entries ( ) ) { moveItem ( stash , item , offset + page , rows [ 0 ] , cols [ 0 ] ) ; } offset += nbPages ; } ) ; }