;;; -*- lexical-binding: t -*- ;; ;; -------------------------------------------------------------------------- (require 'cl-lib) (cl-pushnew "." load-path :test #'string=) (require 'luki-lisp) ;; -------------------------------------------------------------------------- (-> 'bad-elem) ;; -------------------------------------------------------------------------- (defconst bad-solid ?\s) (defconst bad-nonsolid ?\{) ;; -------------------------------------------------------------------------- (cl-defmethod bad-write-replace ((dst elem) (src elem) &optional read) (~ (data w h) dst (~ ((src-data data) (src-len len) (src-w w) (src-h h) (src-x x) (src-y y) (src-visible visible)) src (when (& data src-data src-visible) (cl-loop with read-data with loop-data = (take (* src-h src-w) src-data) for i from 0 to (1- src-len) for s in loop-data do (let* ((pos-x (+ src-x (m i src-w))) (pos-y (* (+ src-y (/ i src-w)))) (pos (+ pos-x (* pos-y w)))) (when (& (< pos-x (1- w)) (< pos-y (1- h))) (if read (when (= s bad-nonsolid) (push (nth pos data) read-data)) (unless (= s bad-nonsolid) (setf (nth pos data) s))))) finally return (when read (nreverse read-data))))))) ;; -------------------------------------------------------------------------- (<- 'bad-write)