Skip to content

Commit

Permalink
Add stuff to save and exit and reset.
Browse files Browse the repository at this point in the history
  • Loading branch information
Shinmera committed Apr 10, 2021
1 parent 47c2b67 commit 0c95e18
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 10 deletions.
18 changes: 13 additions & 5 deletions main.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@
(setf +main+ NIL))

(defmethod save-state ((main main) (state (eql T)) &rest args)
(apply #'save-state main (make-instance 'save-state) args))
(unless (state main)
(setf (state main) (make-instance 'save-state :filename "1")))
(apply #'save-state main (state main) args))

(defmethod save-state ((main main) (state (eql :quick)) &rest args)
(apply #'save-state main (quicksave main) args))
Expand All @@ -53,9 +55,15 @@
(setf (state main) state))))

(defmethod load-state ((state (eql T)) (main main))
(if (< (save-time (state main)) (save-time (quicksave main)))
(load-state (quicksave main) (scene main))
(load-state (state main) (scene main))))
(cond ((state main)
(if (< (save-time (state main)) (save-time (quicksave main)))
(load-state (quicksave main) (scene main))
(load-state (state main) (scene main))))
((list-saves)
(load-state (first (list-saves)) main))
(T
(load-state (initial-state (scene main)) (scene main))
(save-state (scene main) (make-instance 'save-state :filename "0")))))

(defmethod load-state ((state (eql :quick)) (main main))
(load-state (quicksave main) (scene main)))
Expand Down Expand Up @@ -126,7 +134,7 @@
(show (make-instance 'status-lines))
(when (deploy:deployed-p)
(show (make-instance 'report-button-panel)))
(load-state (or (state main) (initial-state scene)) main)
(load-state T main)
(save-state main (quicksave main))
(save-state main T)
(enter (make-instance 'fade) scene))
Expand Down
9 changes: 6 additions & 3 deletions save-state.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,14 @@

(defmethod print-object ((save-state save-state) stream)
(print-unreadable-object (save-state stream :type T)
(format stream "~s ~a" (author save-state) (format-absolute-time (save-time save-state)))))
(format stream "~s ~s" (author save-state) (file save-state))))

(defun list-saves ()
(loop for file in (directory (make-pathname :name :wild :type "save" :defaults (config-directory)))
collect (minimal-load-state file)))
(sort
(loop for file in (directory (make-pathname :name :wild :type "zip" :defaults (config-directory)))
unless (string= "quicksave" (pathname-name file))
collect (minimal-load-state file))
#'string< :key (lambda (f) (pathname-name (file f)))))

(defun minimal-load-state (file)
(with-packet (packet file)
Expand Down
1 change: 0 additions & 1 deletion spawn.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
(+ (vy (location chunk)) (vy (bsize chunk)) 8)))
(when (typep entity 'chunk)
(push entity adjacent))))
(print adjacent)
(setf (adjacent spawner) adjacent)))

(defmethod handle ((ev switch-chunk) (spawner spawner))
Expand Down
18 changes: 17 additions & 1 deletion ui/menu.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,23 @@

#++
(with-tab (tab (@ load-game-menu) 'org.shirakumo.alloy.layouts.constraint:layout)
))
)

(with-tab (tab (@ save-and-exit-game) 'org.shirakumo.alloy.layouts.constraint:layout)
(let ((save (with-button save-and-exit-game
(save-state +main+ T)
(quit *context*)))
(exit (with-button exit-game
(quit *context*)))
(reset (with-button reset-game
(load-state (make-instance 'save-state :filename "0") +world+)
(hide panel))))
(alloy:enter save tab :constraints `((:bottom 10) (:left 10) (:width 200) (:height 40)))
(alloy:enter exit tab :constraints `((:bottom 10) (:right-of ,save 10) (:width 200) (:height 40)))
(alloy:enter reset tab :constraints `((:bottom 10) (:right-of ,exit 10) (:width 200) (:height 40)))
(alloy:enter save focus :layer layer)
(alloy:enter exit focus :layer layer)
(alloy:enter reset focus :layer layer))))
(alloy:finish-structure panel layout focus)))

(defun overview-text ()
Expand Down
3 changes: 3 additions & 0 deletions world/lang/eng.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ walkie-talkie "walkie-talkie"
;; UI
go-backwards-in-ui "Back"
resume-game "Resume"
exit-game "Exit Game"
reset-game "Reset Game"
save-and-exit-game "Save & Exit"
create-quick-save "Quicksave"
load-last-quick-save "Quickload"
open-options-menu "Options"
Expand Down

0 comments on commit 0c95e18

Please sign in to comment.