Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;;; can be run in-game with: soron.lisp{run:"/bin/sort-inv", upg:#s.sys.upgrades}
- ;;; can be viewed in-game with: soron.lisp{ev:"(prn ($js-str (slurp '/bin/sort-inv)))"}
- (do
- (def! get-inv-data (fn* ()
- (let*
- (
- num-list (map (fn* (a b) b) ($scr 'upg))
- )
- (map (fn* (a i) (do ($js-set a '_index i) a)) ($scr 'upg (list->hash (list 'info num-list))))
- )
- ))
- (def! inv-loaded-str (fn* (data)
- ($js-call (map (fn* (a) (if ($js a 'loaded) '+ '-)) data) 'join "")
- ))
- (def! last-char (fn* (str char anchor)
- ($js-call str 'lastIndexOf char anchor)
- ))
- (def! first-char (fn* (str char anchor)
- ($js-call str 'indexOf char anchor)
- ))
- (let*
- (
- data (get-inv-data),
- loaded-str (inv-loaded-str data),
- rev-swaps (list)
- )
- (do
- (def! move-uneq-first (fn* (ind)
- (let*
- (uneq-last (last-char loaded-str '- ind))
- (if (> uneq-last (first-char loaded-str '+))
- (do
- ($js-call rev-swaps 'push (list->hash (list 'from uneq-last, 'to 0)))
- (move-uneq-first (- uneq-last 1))
- )
- )
- )
- ))
- (move-uneq-first (last-char loaded-str '+))
- (let* (swaps ($js-call rev-swaps 'reverse)) (do
- (prn (->json swaps))
- ($scr 'upg (list->hash (list 'reorder swaps)))
- ))
- )
- )
- (let*
- (
- full_data (get-inv-data),
- loaded-str (inv-loaded-str full_data),
- data ($js-call full_data 'slice 0 (+ 1 (last-char loaded-str '+))),
- )
- (do
- ($js-call data 'sort
- (fn* (a b)
- (if
- (and
- ($js a 'loaded)
- (and
- ($js b 'loaded)
- (and
- ($eq ($js a 'type) 'lock)
- ($eq ($js b 'type) 'lock)
- )
- )
- )
- ; DO NOT CHANGE ORDER OF EQUIPPED LOCKS
- (- ($js a '_index) ($js b '_index))
- ; but sort everything else
- ($js-call
- (list
- (if ($js a 'loaded)
- (+
- 10000
- (if ($eq ($js a 'type) 'lock)
- -100000
- 0
- )
- )
- 0
- )
- (if ($js b 'loaded)
- (+
- -10000
- (if ($eq ($js b 'type) 'lock)
- 100000
- 0
- )
- )
- 0
- )
- ; ASCIIbetical sort on name, first
- (if (< ($js b 'name) ($js a 'name))
- 10
- (if (> ($js b 'name) ($js a 'name))
- -10
- 0
- )
- ),
- ; rare things LAST (because of tier-based ASCII sort)
- (- ($js a 'rarity) ($js b 'rarity)),
- )
- 'reduce
- +
- )
- )
- )
- )
- (let*
- (
- nums (map (fn* (v i) i) data)
- swaps ($js-call
- (map
- (fn* (v i)
- (let*
- (
- orig ($js v '_index)
- from ($js-call nums 'indexOf orig),
- oper (list->hash (list
- 'name ($js v 'name),
- 'from from,
- 'to i,
- )),
- )
- (do
- ($js-call nums 'splice i 0 ($js ($js-call nums 'splice from 1) 0))
- oper
- )
- )
- )
- data
- )
- 'filter
- (fn* (a) (not ($eq ($js a 'from) ($js a 'to))))
- )
- )
- (do
- (prn (->json swaps))
- ($scr 'upg (list->hash (list 'reorder swaps)))
- )
- )
- )
- )
- )
Add Comment
Please, Sign In to add comment