@@ 32,15 32,19 @@
(define-key sand-mode-map (kbd "u") #'sand/undo))
(defvar sand//board nil "The sand board.")
+(defvaralias sand-board sand//board)
(defvar sand/board-width 20
"How wide the sand board is.")
+(defvaralias sand-board-width sand/board-width)
(defvar sand/board-height 40
"How tall the sand board is.")
+(defvaralias sand-board-height sand/board-height)
(defvar sand//buffer-name "*sand*"
"The name of the sand buffer.")
+(defvaralias sand--buffer-name sand//buffer-name)
(defvar sand//representations
(ht ('sand "o")
@@ 58,66 62,82 @@
('smoke "!")
('feather "~")
('feather-drop "—")))
+(defvaralias sand--representations sand//representations)
(defvar sand//transient-objects
(list 'smoke)
"A list of objects that should go away at the end of each step.")
+(defvaralias sand--transient-objects sand//transient-objects)
(defvar sand//permanent-objects
(seq-difference (ht-keys sand//representations)
sand//transient-objects))
+(defvaralias sand--permanent-objects sand//permanent-objects)
(defun sand//representation (thing)
"Get the representation of THING."
(gethash thing sand//representations " "))
+(defalias sand--representation sand//representation)
(defvar sand//fixed-items
(list 'ledge 'angle-left 'angle-right 'source 'black-hole 'smoke 'feather)
"A list of items that are unaffected by gravity.")
+(defvaralias sand--fixed-items sand//fixed-items)
(defvar sand//loose-items
(seq-difference (hash-table-keys sand//representations) sand//fixed-items))
+(defvaralias sand--loose-items sand//loose-items)
(defvar sand//spawnable-items
sand//loose-items
"The list of items that can be spawned.")
+(defvaralias sand--spawnable-items sand//spawnable-items)
(defvar sand//spawning t
"Whether sources spawn items at all.")
+(defvaralias sand--spawning sand//spawning)
(defun sand//add-spawnable-item (item)
"Make ITEM spawnable."
(push item sand//spawnable-items))
+(defalias sand--add-spawnable-item sand//add-spawnable-item)
(defun sand//remove-spawnable-item (item)
"Make ITEM no longer spawnable."
(setf sand//spawnable-items
(remove item sand//spawnable-items)))
+(defalias sand--remove-spawnable-item sand//remove-spawnable-item)
(defvar sand//blowupable-items
(list 'sand 'rock 'boulder 'glass 'antimatter 'balloon 'feather 'feather-drop nil))
+(defvaralias sand--blowupable-items sand//blowupable-items)
(defun sand//blowupable (item)
"Return whether ITEM can be blown up."
(seq-contains-p sand//blowupable-items item))
+(defalias sand--blowupable sand//blowupable)
(defun sand//is-fixed (thing)
"Return whether the THING is fixed in place."
(seq-contains sand//fixed-items thing))
+(defalias sand--is-fixed sand//is-fixed)
(defun sand//affected-by-gravity (thing)
"Return whether THING is affected by gravity."
(and (seq-contains-p sand//loose-items thing)
(not (eq thing 'balloon))))
+(defalias sand--affected-by-gravity sand//affected-by-gravity)
(defvar sand//consuming-items
(list 'antimatter 'black-hole 'smoke 'smoke1))
+(defvaralias sand--consuming-items sand//consuming-items)
(defun sand/restart ()
"Restart sand mode."
(interactive)
(when (y-or-n-p "Restart sand?")
(sand/start)))
+(defalias sand-restart sand/restart)
(defun sand/start ()
"Start sand mode."
@@ 125,10 145,12 @@
(switch-to-buffer sand//buffer-name)
(sand-mode)
(sand//new-sand))
+(defalias sand-start sand/start)
(defvar sand//timer
nil
"The timer that runs the sand drop.")
+(defvaralias sand--timer sand//timer)
(defun sand/toggle-play ()
"Toggle whether the sand is currently dropping."
@@ 138,10 160,12 @@
(sand//start-timer))
(sand//advance-message)
(sand/redisplay))
+(defalias sand-toggle-play sand/toggle-play)
(defvar sand//timer-delay-seconds
0.5
"The delay between ticks of the timer.")
+(defvaralias sand--timer-delay-seconds sand//timer-delay-seconds)
(defun sand//start-timer ()
"Start the sand!"
@@ 151,18 175,22 @@
(run-with-timer 0
sand//timer-delay-seconds
#'sand//tick)))
+(defalias sand--start-timer sand//start-timer)
(defun sand//stop-timer ()
"Stop playing."
(when sand//timer
(cancel-timer sand//timer))
(setf sand//timer nil))
+(defalias sand--stop-timer sand//stop-timer)
(defvar sand/number-of-starting-sands 40
"The number of sands the game begins with.")
+(defvaralias sand-number-of-starting-sands sand/number-of-starting-sands)
(defvar sand//chance-of-source-dropping 3
"The reciprocal of the chance that source will drop an element.")
+(defvaralias sand--chance-of-source-dropping sand//chance-of-source-dropping)
(defun sand//new-sand ()
"Start playing with sand!"
@@ 173,12 201,14 @@
(sand//add-random (random sand/board-height)
(random sand/board-width)))
(sand//print-board))
+(defalias sand--new-sand sand//new-sand)
(defun sand//at (row column)
"Get sand at the given ROW and COLUMN."
(aref sand//board
(+ (* row sand/board-width)
column)))
+(defalias sand--at sand//at)
;;let us call (setf (sand//at x y) val)
(gv-define-setter sand//at
@@ 195,6 225,7 @@
(setf row (random sand/board-height))
(setf column (random sand/board-width)))
(list row column)))
+(defalias sand--find-open-spot sand//find-open-spot)
(defun sand//add-random (row column)
"Add something to (ROW, COLUMN).
@@ 202,12 233,14 @@
This can be anything -- a loose or fixed element."
(setf (sand//at row column)
(seq-random-elt sand//permanent-objects)))
+(defalias sand--add-random sand//add-random)
(defun sand//spawn-random-element (row column)
"Spawn a random element at (ROW, COLUMN)."
(when sand//spawnable-items
(setf (sand//at row column)
(seq-random-elt sand//spawnable-items))))
+(defalias sand--spawn-random-element sand//spawn-random-element)
(defun sand/add-random-element ()
"Add a random spawnable element somewhere on the board."
@@ 218,17 251,19 @@ This can be anything -- a loose or fixed
(column (elt spot 1)))
(sand//spawn-random-element row column))
(sand//print-board))
-
+(defalias sand-add-random-element sand/add-random-element)
(defun sand//delete (row column)
"Delete the thing at (ROW, COLUMN)."
(setf (sand//at row column)
nil))
+(defalias sand--delete sand//delete)
(defun sand/redisplay ()
"Redisplay the board."
(interactive)
(sand//print-board))
+(defalias sand-redisplay sand/redisplay)
(defun sand//keymap-for-button (row column)
"Make the keymap for the button at (ROW, COLUMN)."
@@ 253,6 288,7 @@ This can be anything -- a loose or fixed
(define-key keymap (kbd "?")
(lambda () (interactive) (message "at (%s, %s): %s" row column (sand//at row column))))
keymap))
+(defalias sand--keymap-for-button sand//keymap-for-button)
(defun sand//insert-toggleable-item-description (item description)
"Insert the description of a toggleable ITEM, with DESCRIPTION."
@@ 267,6 303,7 @@ This can be anything -- a loose or fixed
(sand//add-spawnable-item item))
(sand//print-board))))
(insert "\n"))
+(defalias sand--insert-toggleable-item-description sand//insert-toggleable-item-description)
(defun sand//insert-item-description (item description)
"Insert the description of a toggleable ITEM, with DESCRIPTION."
@@ 275,11 312,13 @@ This can be anything -- a loose or fixed
item
description))
(insert "\n"))
+(defalias sand--insert-item-description sand//insert-item-description)
(defvar sand//message-list nil
"A list of messages to display.
The messages are updated every time the user starts, stops, or advances the board.")
+(defvaralias sand--message-list sand//message-list)
(defun sand//add-message-to-list (&rest message)
"Add MESSAGE to sand//message-list.
@@ 288,10 327,12 @@ Each item in MESSAGES is a different lin
(setq sand//message-list
(append sand//message-list
(list message))))
+(defalias sand--add-message-to-list sand//add-message-to-list)
(defun sand//advance-message ()
"Advance the user-viewable message to the next one."
(pop sand//message-list))
+(defalias sand--advance-message sand//advance-message)
(defun sand//print-board ()
"Print the sandbox in the sand buffer."
@@ 356,12 397,14 @@ Each item in MESSAGES is a different lin
(goto-char (min initial-point
(point-max))))))
+(defalias sand--print-board sand//print-board)
(defun sand/tick ()
"User-facing function to tick a single timestep forward."
(interactive)
(sand//advance-message)
(sand//tick))
+(defalias sand-tick sand/tick)
(defun sand//tick ()
"Tick a single step forward, dropping sand."
@@ 385,6 428,7 @@ Each item in MESSAGES is a different lin
(setf (sand//at row column)
'smoke))))
(sand//print-board))
+(defalias sand--tick sand//tick)
(defun sand//move-sand (from-row from-column to-row to-column)
"Move sand from (FROM-ROW FROM-COLUMN) to (TO-ROW TO-COLUMN)."
@@ 421,6 465,7 @@ Each item in MESSAGES is a different lin
(setf newrow (1- newrow))))))))
(when (equal this-cell 'feather-drop)
(setf (sand//at to-row to-column) 'feather))))
+(defalias sand--move-sand sand//move-sand)
(defun sand//can-drop-to (from-thing to-thing)
"See if FROM-THING can drop into a spot occupied by TO-THING."
@@ 439,6 484,7 @@ Each item in MESSAGES is a different lin
((seq-contains-p sand//consuming-items from-thing) t)
((seq-contains-p '(rock boulder) from-thing)
(seq-contains-p '(sand glass) to-thing))))
+(defalias sand--can-drop-to sand//can-drop-to)
(defun sand//direction-to-drop (row column)
"Figure out the direction that a cell at (ROW, COLUMN) should drop.
@@ 515,6 561,7 @@ Return the vector by which to move the c
(can-drop-right
[1 1])
(t [0 0]))))))
+(defalias sand--direction-to-drop sand//direction-to-drop)
(defun sand//explode (row column)
"Explode the cell at (ROW, COLUMN), and all the cells around it."
@@ 531,6 578,7 @@ Return the vector by which to move the c
(when (sand//blowupable (sand//at explode-row explode-column))
(setf (sand//at explode-row explode-column)
'smoke1)))))
+(defalias sand--explode sand//explode)
(defun sand//tick-cell (row column)
"Make a single tick of the ROW, COLUMN cell."
@@ 630,6 678,7 @@ Return the vector by which to move the c
(second-to-row (+ to-row delta-row))
(second-to-column (+ to-column delta-column)))
(sand//move-sand to-row to-column second-to-row second-to-column)))))))))
+(defalias sand--tick-cell sand//tick-cell)
(defun sand/blank-board ()
"Make the entire board blank."
@@ 640,6 689,7 @@ Return the vector by which to move the c
(setf (sand//at row column)
nil)))
(sand//print-board))
+(defalias sand-blank-board sand/blank-board)
(defun sand/clear-loose-items ()
"Clear all falling items."
@@ 653,6 703,7 @@ Return the vector by which to move the c
(setf (sand//at row column)
nil)))))
(sand//print-board))
+(defalias sand-clear-loose-items sand/clear-loose-items)
(defun sand//shuffle (sequence)
"Shuffle SEQUENCE randomly."
@@ 661,11 712,13 @@ Return the vector by which to move the c
(cl-psetf (elt sequence cur-index) (elt sequence rand-index)
(elt sequence rand-index) (elt sequence cur-index))))
sequence)
+(defalias sand--shuffle sand//shuffle)
(defvar sand//history nil
"The history of sand.
This should never hold the current state, only the past history.")
+(defvaralias sand--history sand//history)
(cl-defun sand//checkpoint (&optional (new-state t))
"Add a checkpoint to sand//history.
@@ 677,9 730,11 @@ If NEW-STATE is t, then reset sand//cons
(if new-state
0
(1+ sand//consecutive-undos))))
+(defalias sand--checkpoint sand//checkpoint)
(defvar sand//consecutive-undos 0
"How many previous times we've undone consecutively.")
+(defvaralias sand-consecutive-undos sand//consecutive-undos)
(defun sand/undo ()
"Undo the last step, or item inserted."
@@ 696,6 751,7 @@ If NEW-STATE is t, then reset sand//cons
(progn (setf sand//board
(elt sand//history target-state))
(sand/redisplay)))))
+(defalias sand-undo sand/undo)
(defun sand/tutorial ()
"Begin a tutorial!"
@@ 740,6 796,7 @@ If NEW-STATE is t, then reset sand//cons
(sand//add-message-to-list "That's the end of the tutorial (for now)" "" "Play around, and have fun!")
(sand/redisplay))
+(defalias sand-tutorial sand/tutorial)
(defun sand//add-diagonal-angles (row column size going-left)
"Add a row of angles, starting at (ROW, COLUMN) and moving upwards SIZE times.
@@ 756,6 813,7 @@ This row is towards the left if GOING-LE
(<= 0 current-column (1- sand/board-width)))
(setf (sand//at current-row current-column)
item-to-place))))))
+(defalias sand--add-diagonal-angles sand//add-diagonal-angles)
(defun sand//add-funnel (row column size)
"Add a funnel at (ROW, COLUMN), where each side is SIZE long."
@@ 772,6 830,7 @@ This row is towards the left if GOING-LE
(min (1- sand/board-width) (1- right-boundary))))
(setf (sand//at new-row new-column)
'sand)))))))
+(defalias sand--add-funnel sand//add-funnel)
(provide 'sand)
;;; sand.el ends here