diff --git a/TODO b/TODO index 447bed4..5d3f975 100644 --- a/TODO +++ b/TODO @@ -8,7 +8,11 @@ GAME -* set up an ASDF system, define packages +* split `naledi-ya-africa` package into `naledi-server` and `naledi-client`? + +* implement players and player list + +* implement client/server communication * (I am legion...) diff --git a/TODO b/TODO index 447bed4..5d3f975 100644 --- a/TODO +++ b/TODO @@ -8,7 +8,11 @@ GAME -* set up an ASDF system, define packages +* split `naledi-ya-africa` package into `naledi-server` and `naledi-client`? + +* implement players and player list + +* implement client/server communication * (I am legion...) diff --git a/naledi.lisp b/naledi.lisp index 0a3bc4f..872e192 100644 --- a/naledi.lisp +++ b/naledi.lisp @@ -7,6 +7,8 @@ ;;;; (c) 2018 Daniel Vedder, MIT license ;;;; +;;XXX move this file to src/ncurses.lisp? + (in-package :naledi-ya-africa) ;(use-package :croatoan) @@ -69,11 +71,45 @@ (connect-server)) ((equalp (croatoan:current-item mw) "Connect to a remote server") - (connect-server (enter-server-address)))) + (connect-server (enter-server-address scr)))) (return-from croatoan:event-case))))) +;;TODO (choose-world-size) -(defun enter-server-address ()) +(defun enter-server-address (scr) + "Enter the IP and port of the server to connect to" + ;;TODO rewrite this with individual, successive forms? + (croatoan:clear scr) + (croatoan:refresh scr) + (let* ((x0 (- (halve (croatoan:.width scr)) 25)) + (y0 (- (halve (croatoan:.height scr)) 5)) + (ip-field (make-instance 'croatoan:field :width 20 + :position '(4 8))) + (port-field (make-instance 'croatoan:field :width 20 + :position '(5 10))) + (form (make-instance 'croatoan:form + :fields (list ip-field port-field))) + (inputwin (make-instance 'croatoan:window :position (list y0 x0) + :width 50 :height 10))) + (setf (croatoan:.visible inputwin) t) + (croatoan:add-string inputwin + "Enter the servers IP address and port." :y 2 :x 4) + (croatoan:add-string inputwin "IP:" :y 4 :x 4) + (croatoan:add-string inputwin "Port:" :y 5 :x 4) + (croatoan:add-string inputwin + "(Jump with Tab, confirm with control-A)" :y 7 :x 4) + (setf (croatoan:.buffer ip-field) + (reverse (to-list "127.0.0.1"))) + (setf (croatoan:.buffer port-field) + (reverse (to-list (to-string *port*)))) + (croatoan:box inputwin) + (croatoan:edit inputwin form) + (croatoan:move inputwin 5 8) + (croatoan:refresh inputwin) + ;;FIXME The keymap doesn't work and throws an error + (setf (croatoan:.event-handlers scr) + (croatoan:get-keymap :form-default-keymap)))) + (defun user-interface (scr) "Create the screen on the ncurses interface and hand over to window functions" diff --git a/TODO b/TODO index 447bed4..5d3f975 100644 --- a/TODO +++ b/TODO @@ -8,7 +8,11 @@ GAME -* set up an ASDF system, define packages +* split `naledi-ya-africa` package into `naledi-server` and `naledi-client`? + +* implement players and player list + +* implement client/server communication * (I am legion...) diff --git a/naledi.lisp b/naledi.lisp index 0a3bc4f..872e192 100644 --- a/naledi.lisp +++ b/naledi.lisp @@ -7,6 +7,8 @@ ;;;; (c) 2018 Daniel Vedder, MIT license ;;;; +;;XXX move this file to src/ncurses.lisp? + (in-package :naledi-ya-africa) ;(use-package :croatoan) @@ -69,11 +71,45 @@ (connect-server)) ((equalp (croatoan:current-item mw) "Connect to a remote server") - (connect-server (enter-server-address)))) + (connect-server (enter-server-address scr)))) (return-from croatoan:event-case))))) +;;TODO (choose-world-size) -(defun enter-server-address ()) +(defun enter-server-address (scr) + "Enter the IP and port of the server to connect to" + ;;TODO rewrite this with individual, successive forms? + (croatoan:clear scr) + (croatoan:refresh scr) + (let* ((x0 (- (halve (croatoan:.width scr)) 25)) + (y0 (- (halve (croatoan:.height scr)) 5)) + (ip-field (make-instance 'croatoan:field :width 20 + :position '(4 8))) + (port-field (make-instance 'croatoan:field :width 20 + :position '(5 10))) + (form (make-instance 'croatoan:form + :fields (list ip-field port-field))) + (inputwin (make-instance 'croatoan:window :position (list y0 x0) + :width 50 :height 10))) + (setf (croatoan:.visible inputwin) t) + (croatoan:add-string inputwin + "Enter the servers IP address and port." :y 2 :x 4) + (croatoan:add-string inputwin "IP:" :y 4 :x 4) + (croatoan:add-string inputwin "Port:" :y 5 :x 4) + (croatoan:add-string inputwin + "(Jump with Tab, confirm with control-A)" :y 7 :x 4) + (setf (croatoan:.buffer ip-field) + (reverse (to-list "127.0.0.1"))) + (setf (croatoan:.buffer port-field) + (reverse (to-list (to-string *port*)))) + (croatoan:box inputwin) + (croatoan:edit inputwin form) + (croatoan:move inputwin 5 8) + (croatoan:refresh inputwin) + ;;FIXME The keymap doesn't work and throws an error + (setf (croatoan:.event-handlers scr) + (croatoan:get-keymap :form-default-keymap)))) + (defun user-interface (scr) "Create the screen on the ncurses interface and hand over to window functions" diff --git a/src/util.lisp b/src/util.lisp index 341e15c..b3ceb5e 100644 --- a/src/util.lisp +++ b/src/util.lisp @@ -224,7 +224,7 @@ (defun to-list (vector &optional (next-elt 0)) "Turn the vector into a list" - (if (= next-elt (1- (length vector))) NIL + (if (= next-elt (length vector)) NIL (cons (aref vector next-elt) (to-list vector (1+ next-elt))))) (defun cut-list (l i)