import { Item } from "../types/Item" ; import { BinaryStream } from "../../save-file/binary" ; import { getBase } from "../getBase" ; import { FIRST_D2R } from "../../character/parsing/versions" ; import { decodeHuffman } from "./huffman" ; import { ItemsOwner } from "../../save-file/ownership" ; export function parseSimple ( stream , owner ) { const { read , readBool , readInt , skip } = stream ; const item = { raw : "" , owner , identified : skip ( 4 ) || readBool ( ) , socketed : skip ( 6 ) || readBool ( ) , simple : skip ( 9 ) || readBool ( ) , ethereal : readBool ( ) , personalized : skip ( 1 ) || readBool ( ) , runeword : skip ( 1 ) || readBool ( ) , version : skip ( 5 ) || ( owner . version >= FIRST_D2R ? read ( 3 ) : readInt ( 10 ) . toString ( ) ) , location : readInt ( 3 ) , equippedInSlot : readInt ( 4 ) , column : readInt ( 4 ) , row : readInt ( 4 ) , stored : readInt ( 3 ) , code : "" , search : "" , } ; if ( owner . version >= FIRST_D2R ) { item . code = decodeHuffman ( stream , 4 ) . trim ( ) ; } else { item . code = String . fromCharCode ( readInt ( 8 ) , readInt ( 8 ) , readInt ( 8 ) , readInt ( 8 ) ) . trim ( ) ; } const base = getBase ( item ) ; if ( base . type === "ques" && base . trackQuestDifficulty ) { read ( 2 ) ; } item . nbFilledSockets = readInt ( item . simple ? 1 : 3 ) ; if ( item . socketed && item . nbFilledSockets > 0 ) { item . filledSockets = [ ] ; } if ( item . simple ) { item . name = base . name ; } return item ; }