##// END OF EJS Templates
MENU
naryl -
r30:3c634d0a default
parent child Browse files
Show More
@@ -1,13 +1,22 b''
1
2 # start
3 act 'Показать меню':
4 gs 'menu'
5 end
6 -
1
7
2 # menu
8 # menu
9 killvar 'usr_menu'
3 ! нет иконки
10 ! нет иконки
4 $usr_menu[0] = 'Взять предмет:take_item'
11 $usr_menu[] = 'Взять предмет:take_item'
5 ! иконка задана gif-файлом
12 ! иконка задана gif-файлом
6 $usr_menu[1] = 'Положить предмет:put_item:images/put_item.gif'
13 $usr_menu[] = 'Положить предмет:put_item:images/put_item.gif'
7 ! иконка задана значением $icon_file
14 ! иконка задана значением $icon_file
8 $usr_menu[2] = 'Осмотреть предмет:look_item:<<$icon_file>>'
15 $usr_menu[] = 'Осмотреть предмет:look_item:<<$icon_file>>'
16 ! Разделитель
17 $usr_menu[] = '-:-'
9 ! пункт меню задан 3-мя переменными
18 ! пункт меню задан 3-мя переменными
10 $usr_menu[3] = '<<$name>>:<<$loc>>:<<$file>>'
19 $usr_menu[] = '<<$name>>:<<$locname>>:<<$file>>'
11
20
12 menu 'usr_menu' &! покажет меню из 4-х пунктов
21 menu 'usr_menu' &! покажет меню из 4-х пунктов
13 -
22 -
@@ -18,6 +18,6 b''
18 <div id="qsp-dropdown">
18 <div id="qsp-dropdown">
19 </div>
19 </div>
20
20
21 <div id="qsp-image-container">
21 <div id="qsp-image-container" class="center-on-screen">
22 <img id="qsp-image">
22 <img id="qsp-image">
23 </div>
23 </div>
@@ -73,7 +73,6 b''
73 box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
73 box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
74 z-index: 1;
74 z-index: 1;
75 margin: auto;
75 margin: auto;
76 top: 200;
77 }
76 }
78
77
79 #qsp-dropdown a {
78 #qsp-dropdown a {
@@ -102,17 +101,26 b''
102 background: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAYAAAAeP4ixAAAABmJLR0QA/wD/AP+gva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j7GsrkEFpXWyrwwbaf15nXWqv6SqK1abuHDmPjV0EMobhBWIZt8cZVu0j2ZDNHF7gblRozdiO49g1zqDOEzmKJ7gcGVQTzmLDSgZ1Eunh2dD9aewpsXtctH3cwzn5ALysoVWlXZvhleMV5ovfU8J363mciAliRLsRg0Q244vfT3A/zgT2cQHbImIY1S4ldPk9Ii+NH8V9H08DfbfiY6BtiHYpoYmMBr4bbwN9YzfVoEELnew9+blpwBv5u0oI9wPtQrUbkWFaXqOzsZ01IFg7pLQOyp/A58igmhCsHZJInYndNsHa/0wiVWTy9/a5NjprQGvag0Qmwd462iGltdQ8lihqlVVIIn/9/CAvrajDWgTRB8VhMt1/aSljVr4RToc6hJTWioe1jujJD4rfQx2qRvuTyX1JuTIh3UQikUgkEhPnF+1xZ9hHnLjAAAAAAElFTkSuQmCC');
103 }
102 }
104
103
105 #qsp-image-container {
104 .center-on-screen {
106 position: absolute;
105 position: absolute;
107 top: 0;
106 top: 0;
108 left: 0;
107 left: 0;
109 height: 100%;
108 height: 100%;
110 width: 100%;
109 width: 100%;
111 display: none;
110 pointer-events: none;
111 display: flex;
112 justify-content: center;
112 justify-content: center;
113 align-items: center;
113 align-items: center;
114 }
114 }
115
115
116 .center-on-screen > * {
117 pointer-events: auto;
118 }
119
120 #qsp-image-container {
121 display: none;
122 }
123
116 /* misc */
124 /* misc */
117
125
118 .disable a {
126 .disable a {
@@ -13,3 +13,22 b''
13 (unwind-protect
13 (unwind-protect
14 ,@body
14 ,@body
15 (pop-local-frame))))
15 (pop-local-frame))))
16
17 (defpsmacro inline-call (func &rest args)
18 `(+ (ps-inline ,func)
19 "(\""
20 ,(first args)
21 ,@(loop :for arg :in (cdr args)
22 :collect "\", \""
23 :collect arg)
24 "\");"))
25
26 (defpsmacro with-sleep ((resume-func) &body body)
27 `(new (*promise
28 (lambda (resolve)
29 (start-sleeping)
30 (let ((,resume-func (lambda ()
31 (finish-sleeping)
32 (resolve)))))
33 ,@body))))
34
@@ -9,36 +9,32 b''
9 ;;; Utils
9 ;;; Utils
10
10
11 (defun make-act-html (title img)
11 (defun make-act-html (title img)
12 (+ "<a class='qsp-act' href='" (ps-inline call-act) "(\"" title "\");'>"
12 (+ "<a class='qsp-act' href='" (inline-call call-act title) "'>"
13 (if img (+ "<img src='" img "'>") "")
13 title
14 title
14 "</a>"))
15 "</a>"))
15
16
16 (defun make-menu-item-html (num title img loc)
17 (defun make-menu-item-html (num title img loc)
17 (+ "<a href='" (ps-inline run-menu) "(" num ", \"" loc "\")();'>"
18 (+ "<a href='" (inline-call finish-menu loc) "'>"
18 "<img src='" img "'>"
19 (if img (+ "<img src='" img "'>") "")
19 title
20 title
20 "</a>"))
21 "</a>"))
21
22
23 (defun make-menu-delimiter ()
24 "<hr>")
25
22 (defun report-error (text)
26 (defun report-error (text)
23 (alert text))
27 (alert text))
24
28
25 (defun start-sleeping ()
29 (defun start-sleeping ()
26 (chain (by-id "qsp") class-list (add "disable"))
30 (chain (by-id "qsp") class-list (add "disable")))
27 (setf (root sleeping) t))
28
31
29 (defun finish-sleeping ()
32 (defun finish-sleeping ()
30 (chain (by-id "qsp") class-list (remove "disable"))
33 (chain (by-id "qsp") class-list (remove "disable")))
31 (setf (root sleeping) nil))
32
34
33 (defun sleep (msec)
35 (defun sleep (msec)
34 (start-sleeping)
36 (with-sleep (resume)
35 (new (*promise
37 (set-timeout resume msec)))
36 (lambda (resolve)
37 (set-timeout
38 (lambda ()
39 (finish-sleeping)
40 (resolve))
41 msec)))))
42
38
43 (defun init-dom ()
39 (defun init-dom ()
44 ;; Save/load buttons
40 ;; Save/load buttons
@@ -54,7 +50,10 b''
54 ;; Close the dropdown on any click
50 ;; Close the dropdown on any click
55 (setf (@ window onclick)
51 (setf (@ window onclick)
56 (lambda (event)
52 (lambda (event)
57 (setf (@ (get-frame :dropdown) style display) "none"))))
53 (setf (@ window mouse)
54 (list (@ event page-x)
55 (@ event page-y)))
56 (finish-menu nil))))
58
57
59 (defun call-serv-loc (var-name &rest args)
58 (defun call-serv-loc (var-name &rest args)
60 (let ((loc-name (get-var var-name 0 :str)))
59 (let ((loc-name (get-var var-name 0 :str)))
@@ -105,14 +104,14 b''
105 (get-var "RESULT" 0 :num)))
104 (get-var "RESULT" 0 :num)))
106
105
107 (defun call-loc (name args)
106 (defun call-loc (name args)
107 (setf name (chain name (to-upper-case)))
108 (with-frame
108 (with-frame
109 (with-call-args args
109 (with-call-args args
110 (funcall (getprop (root locs) name) args))))
110 (funcall (getprop (root locs) name) args))))
111
111
112 (defun call-act (title)
112 (defun call-act (title)
113 (unless (root sleeping)
113 (with-frame
114 (with-frame
114 (funcall (getprop (root acts) title 'act))))
115 (funcall (getprop (root acts) title 'act)))))
116
115
117 ;;; Text windows
116 ;;; Text windows
118
117
@@ -123,6 +122,7 b''
123 (:objs "qsp-objs")
122 (:objs "qsp-objs")
124 (:acts "qsp-acts")
123 (:acts "qsp-acts")
125 (:input "qsp-input")
124 (:input "qsp-input")
125 (:image "qsp-image")
126 (:dropdown "qsp-dropdown")
126 (:dropdown "qsp-dropdown")
127 (t (report-error "Internal error!"))))
127 (t (report-error "Internal error!"))))
128
128
@@ -234,6 +234,7 b''
234 (values name :num)))
234 (values name :num)))
235
235
236 (defun ensure-var (name)
236 (defun ensure-var (name)
237 (setf name (chain name (to-upper-case)))
237 (let ((store (var-ref name)))
238 (let ((store (var-ref name)))
238 (unless store
239 (unless store
239 (setf store (new (*var name)))
240 (setf store (new (*var name)))
@@ -256,22 +257,25 b''
256 (void))
257 (void))
257
258
258 (defun get-array (name)
259 (defun get-array (name)
260 (setf name (chain name (to-upper-case)))
259 (var-ref name))
261 (var-ref name))
260
262
261 (defun set-array (name value)
263 (defun set-array (name value)
264 (setf name (chain name (to-upper-case)))
262 (let ((store (var-ref name)))
265 (let ((store (var-ref name)))
263 (setf (@ store values) (@ value values))
266 (setf (@ store values) (@ value values))
264 (setf (@ store indexes) (@ value indexes)))
267 (setf (@ store indexes) (@ value indexes)))
265 (void))
268 (void))
266
269
267 (defun kill-var (name &optional index)
270 (defun kill-var (name &optional index)
271 (setf name (chain name (to-upper-case)))
268 (if (and index (not (= 0 index)))
272 (if (and index (not (= 0 index)))
269 (chain (getprop (root vars) name) (kill index))
273 (chain (getprop (root vars) name) (kill index))
270 (delete (getprop (root vars) name)))
274 (delete (getprop (root vars) name)))
271 (void))
275 (void))
272
276
273 (defun array-size (name)
277 (defun array-size (name)
274 (getprop (var-ref name) 'length))
278 (@ (var-ref name) values length))
275
279
276 ;;; Locals
280 ;;; Locals
277
281
@@ -303,18 +307,47 b''
303
307
304 ;;; Menu
308 ;;; Menu
305
309
306 (defun menu (menu-data)
310 (defun open-menu (menu-data)
307 (let ((elt (by-id "qsp-dropdown"))
311 (let ((elt (get-frame :dropdown))
308 (i 0))
312 (i 0))
309 (setf (inner-html elt) "")
310 (loop :for item :in menu-data
313 (loop :for item :in menu-data
311 :do (incf i)
314 :do (incf i)
312 :do (incf (inner-html elt) (make-menu-item-html i
315 :do (incf (inner-html elt)
313 (@ item text)
316 (if (eq item :delimiter)
314 (@ item icon)
317 (make-menu-delimiter i)
315 (@ item loc))))
318 (make-menu-item-html i
319 (@ item :text)
320 (@ item :icon)
321 (@ item :loc)))))
322 (let ((mouse (@ window mouse)))
323 (setf (@ elt style left) (+ (elt mouse 0) "px"))
324 (setf (@ elt style top) (+ (elt mouse 1) "px"))
325 ;; Make sure it's inside the viewport
326 (when (> (@ document body inner-width)
327 (+ (elt mouse 0) (@ elt inner-width)))
328 (incf (@ elt style left) (@ elt inner-width)))
329 (when (> (@ document body inner-height)
330 (+ (elt mouse 0) (@ elt inner-height)))
331 (incf (@ elt style top) (@ elt inner-height))))
316 (setf (@ elt style display) "block")))
332 (setf (@ elt style display) "block")))
317
333
334 (defun finish-menu (loc)
335 (when (root menu-resume)
336 (let ((elt (get-frame :dropdown)))
337 (setf (inner-html elt) "")
338 (setf (@ elt style display) "none")
339 (funcall (root menu-resume))
340 (setf (root menu-resume) nil))
341 (when loc
342 (call-loc loc)))
343 (void))
344
345 (defun menu (menu-data)
346 (with-sleep (resume)
347 (open-menu menu-data)
348 (setf (root menu-resume) resume))
349 (void))
350
318 ;;; Content
351 ;;; Content
319
352
320 (defun clean-audio ()
353 (defun clean-audio ()
@@ -324,7 +357,7 b''
324 (delete (@ (root playing) k)))))
357 (delete (@ (root playing) k)))))
325
358
326 (defun show-image (path)
359 (defun show-image (path)
327 (let ((img (by-id "qsp-image")))
360 (let ((img (get-frame :image)))
328 (cond (path
361 (cond (path
329 (setf (@ img src) path)
362 (setf (@ img src) path)
330 (setf (@ img style display) "flex"))
363 (setf (@ img style display) "flex"))
@@ -379,9 +412,9 b''
379 :msecs (- (chain *date (now)) (root started-at))
412 :msecs (- (chain *date (now)) (root started-at))
380 :timer-interval (root timer-interval)
413 :timer-interval (root timer-interval)
381 :main-html (inner-html
414 :main-html (inner-html
382 (by-id :qsp-main))
415 (get-frame :main))
383 :stat-html (inner-html
416 :stat-html (inner-html
384 (by-id :qsp-stat))
417 (get-frame :stat))
385 :next-location (root current-location)))))
418 :next-location (root current-location)))))
386 (void))
419 (void))
387
420
@@ -395,9 +428,9 b''
395 (setf (root started-at) (- (chain *date (now)) (@ data :msecs)))
428 (setf (root started-at) (- (chain *date (now)) (@ data :msecs)))
396 (setf (root objs) (@ data :objs))
429 (setf (root objs) (@ data :objs))
397 (setf (root current-location) (@ data :next-location))
430 (setf (root current-location) (@ data :next-location))
398 (setf (inner-html (by-id :qsp-main))
431 (setf (inner-html (get-frame :main))
399 (@ data :main-html))
432 (@ data :main-html))
400 (setf (inner-html (by-id :qsp-stat))
433 (setf (inner-html (get-frame :stat))
401 (@ data :stat-html))
434 (@ data :stat-html))
402 (update-objs)
435 (update-objs)
403 (set-timer (@ data :timer-interval))
436 (set-timer (@ data :timer-interval))
@@ -9,7 +9,7 b''
9 ;;; 2var
9 ;;; 2var
10
10
11 (defpsmacro killvar (varname &optional index)
11 (defpsmacro killvar (varname &optional index)
12 `(kill-var ,varname ,index))
12 `(api-call kill-var ,varname ,index))
13
13
14 (defpsmacro killall ()
14 (defpsmacro killall ()
15 `(api-call kill-all))
15 `(api-call kill-all))
@@ -9,15 +9,14 b''
9
9
10 (defun goto (target args)
10 (defun goto (target args)
11 (api:clear-text :main)
11 (api:clear-text :main)
12 (funcall xgoto target (or args (list)))
12 (funcall xgoto target args)
13 (void))
13 (void))
14
14
15 (defun xgoto (target args)
15 (defun xgoto (target args)
16 (api:clear-act)
16 (api:clear-act)
17 (setf (root current-location) (chain target (to-upper-case)))
17 (setf (root current-location) (chain target (to-upper-case)))
18 (api:stash-state args)
18 (api:stash-state args)
19 (funcall (getprop (root locs) (root current-location))
19 (api:call-loc (root current-location) (or args (list)))
20 (or args (list)))
21 (void))
20 (void))
22
21
23 ;;; 2var
22 ;;; 2var
@@ -99,11 +98,11 b''
99 ;;; 8sub
98 ;;; 8sub
100
99
101 (defun gosub (target &rest args)
100 (defun gosub (target &rest args)
102 (funcall (getprop (root locs) target) args)
101 (api:call-loc target args)
103 (void))
102 (void))
104
103
105 (defun func (target &rest args)
104 (defun func (target &rest args)
106 (funcall (getprop (root locs) target) args))
105 (api:call-loc target args))
107
106
108 ;;; 9loops
107 ;;; 9loops
109
108
@@ -215,7 +214,8 b''
215
214
216 (defun menu (menu-name)
215 (defun menu (menu-name)
217 (let ((menu-data (list)))
216 (let ((menu-data (list)))
218 (loop :for item :in (api:get-array (api:var-real-name menu-name))
217 (loop :for item-obj :in (@ (api:get-array (api:var-real-name menu-name)) values)
218 :for item := (@ item-obj :str)
219 :do (cond ((string= item "")
219 :do (cond ((string= item "")
220 (break))
220 (break))
221 ((string= item "-:-")
221 ((string= item "-:-")
@@ -228,9 +228,9 b''
228 (loc (getprop tokens (- (length tokens) 2)))
228 (loc (getprop tokens (- (length tokens) 2)))
229 (icon (getprop tokens (- (length tokens) 1))))
229 (icon (getprop tokens (- (length tokens) 1))))
230 (chain menu-data
230 (chain menu-data
231 (push (create text text
231 (push (create :text text
232 loc loc
232 :loc loc
233 icon icon))))))))
233 :icon icon))))))))
234 (api:menu menu-data)
234 (api:menu menu-data)
235 (void)))
235 (void)))
236
236
@@ -20,7 +20,7 b''
20 ;; api
20 ;; api
21 document get-element-by-id
21 document get-element-by-id
22 onclick onchange
22 onclick onchange
23 atob btoa
23 atob btoa split
24 alert prompt
24 alert prompt
25 set-timeout set-interval clear-interval
25 set-timeout set-interval clear-interval
26 *promise *j-s-o-n
26 *promise *j-s-o-n
@@ -31,9 +31,11 b''
31 create-element set-attribute class-list
31 create-element set-attribute class-list
32 *file-reader read-as-text
32 *file-reader read-as-text
33 style display src
33 style display src
34 page-x page-y
35 top left
34 ;; lib
36 ;; lib
35 *number parse-int
37 *number parse-int
36 to-upper-case concat
38 to-string to-upper-case concat
37 click target current-target files index-of result
39 click target current-target files index-of result
38 decode-u-r-i-component splice
40 decode-u-r-i-component splice
39 )
41 )
@@ -36,6 +36,7 b''
36 ;; For $COUNTER and SETTIMER
36 ;; For $COUNTER and SETTIMER
37 (#.(intern "SET-TIMER" "SUGAR-QSP.API")
37 (#.(intern "SET-TIMER" "SUGAR-QSP.API")
38 (root timer-interval))
38 (root timer-interval))
39 ;; Start the first location
39 (funcall (getprop (root locs)
40 (funcall (getprop (root locs)
40 (chain *object (keys (root locs)) 0))
41 (chain *object (keys (root locs)) 0))
41 (list))
42 (list))
@@ -582,12 +582,17 b''
582
582
583 (p:defrule variable (and identifier (p:? array-index))
583 (p:defrule variable (and identifier (p:? array-index))
584 (:destructure (id idx)
584 (:destructure (id idx)
585 (if (char= #\$ (elt (string id) 0))
585 (let ((idx (case idx
586 (list 'lib:qspvar (intern (subseq (string-upcase id) 1) :lib) (or idx 0) :str)
586 (nil 0)
587 (list 'lib:qspvar id (or idx 0) :num))))
587 (:last nil)
588 (t idx))))
589 (if (char= #\$ (elt (string id) 0))
590 (list 'lib:qspvar (intern (subseq (string-upcase id) 1) :lib) idx :str)
591 (list 'lib:qspvar id idx :num)))))
588
592
589 (p:defrule array-index (and #\[ spaces? (p:? expression) spaces? #\])
593 (p:defrule array-index (and #\[ spaces? (p:? expression) spaces? #\])
590 (:function third))
594 (:lambda (list)
595 (or (third list) :last)))
591
596
592 (p:defrule assignment (or kw-assignment plain-assignment op-assignment)
597 (p:defrule assignment (or kw-assignment plain-assignment op-assignment)
593 (:destructure (qspvar eq expr)
598 (:destructure (qspvar eq expr)
General Comments 0
You need to be logged in to leave comments. Login now