revision of QML "sokoban"; add function QML-SET-ALL;
This commit is contained in:
parent
a85aaa41ff
commit
cd0227b66b
8 changed files with 108 additions and 9 deletions
|
|
@ -16,6 +16,7 @@
|
|||
#:js
|
||||
#:qml-get
|
||||
#:qml-set
|
||||
#:qml-set-all
|
||||
#:paint
|
||||
#:reload
|
||||
#:root-context
|
||||
|
|
@ -135,6 +136,12 @@
|
|||
(|update| item))))
|
||||
(eql::%error-msg "QML-SET" (list item/name property-name value))))))
|
||||
|
||||
(defun qml-set-all (name property-name value &optional update)
|
||||
"Sets QQmlProperty of all objects matching NAME."
|
||||
(assert (stringp name))
|
||||
(dolist (item (qfind-children (root-item) name))
|
||||
(qml-set item property-name value update)))
|
||||
|
||||
;;; JS
|
||||
|
||||
(defun js (item/name js-format-string &rest arguments)
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
#:js
|
||||
#:qml-get
|
||||
#:qml-set
|
||||
#:qml-set-all
|
||||
#:paint
|
||||
#:reload
|
||||
#:root-context
|
||||
|
|
@ -135,6 +136,12 @@
|
|||
(|update| item))))
|
||||
(eql::%error-msg "QML-SET" (list item/name property-name value))))))
|
||||
|
||||
(defun qml-set-all (name property-name value &optional update)
|
||||
"Sets QQmlProperty of all objects matching NAME."
|
||||
(assert (stringp name))
|
||||
(dolist (item (qfind-children (root-item) name))
|
||||
(qml-set item property-name value update)))
|
||||
|
||||
;;; JS
|
||||
|
||||
(defun js (item/name js-format-string &rest arguments)
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
#:js
|
||||
#:qml-get
|
||||
#:qml-set
|
||||
#:qml-set-all
|
||||
#:paint
|
||||
#:reload
|
||||
#:root-context
|
||||
|
|
@ -135,6 +136,12 @@
|
|||
(|update| item))))
|
||||
(eql::%error-msg "QML-SET" (list item/name property-name value))))))
|
||||
|
||||
(defun qml-set-all (name property-name value &optional update)
|
||||
"Sets QQmlProperty of all objects matching NAME."
|
||||
(assert (stringp name))
|
||||
(dolist (item (qfind-children (root-item) name))
|
||||
(qml-set item property-name value update)))
|
||||
|
||||
;;; JS
|
||||
|
||||
(defun js (item/name js-format-string &rest arguments)
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
#:js
|
||||
#:qml-get
|
||||
#:qml-set
|
||||
#:qml-set-all
|
||||
#:paint
|
||||
#:reload
|
||||
#:root-context
|
||||
|
|
@ -135,6 +136,12 @@
|
|||
(|update| item))))
|
||||
(eql::%error-msg "QML-SET" (list item/name property-name value))))))
|
||||
|
||||
(defun qml-set-all (name property-name value &optional update)
|
||||
"Sets QQmlProperty of all objects matching NAME."
|
||||
(assert (stringp name))
|
||||
(dolist (item (qfind-children (root-item) name))
|
||||
(qml-set item property-name value update)))
|
||||
|
||||
;;; JS
|
||||
|
||||
(defun js (item/name js-format-string &rest arguments)
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
#:js
|
||||
#:qml-get
|
||||
#:qml-set
|
||||
#:qml-set-all
|
||||
#:paint
|
||||
#:reload
|
||||
#:root-context
|
||||
|
|
@ -135,6 +136,12 @@
|
|||
(|update| item))))
|
||||
(eql::%error-msg "QML-SET" (list item/name property-name value))))))
|
||||
|
||||
(defun qml-set-all (name property-name value &optional update)
|
||||
"Sets QQmlProperty of all objects matching NAME."
|
||||
(assert (stringp name))
|
||||
(dolist (item (qfind-children (root-item) name))
|
||||
(qml-set item property-name value update)))
|
||||
|
||||
;;; JS
|
||||
|
||||
(defun js (item/name js-format-string &rest arguments)
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
#:js
|
||||
#:qml-get
|
||||
#:qml-set
|
||||
#:qml-set-all
|
||||
#:paint
|
||||
#:reload
|
||||
#:root-context
|
||||
|
|
@ -135,6 +136,12 @@
|
|||
(|update| item))))
|
||||
(eql::%error-msg "QML-SET" (list item/name property-name value))))))
|
||||
|
||||
(defun qml-set-all (name property-name value &optional update)
|
||||
"Sets QQmlProperty of all objects matching NAME."
|
||||
(assert (stringp name))
|
||||
(dolist (item (qfind-children (root-item) name))
|
||||
(qml-set item property-name value update)))
|
||||
|
||||
;;; JS
|
||||
|
||||
(defun js (item/name js-format-string &rest arguments)
|
||||
|
|
|
|||
42
examples/M-modules/quick/sokoban/qml/items/box2.qml
Normal file
42
examples/M-modules/quick/sokoban/qml/items/box2.qml
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
import QtQuick 2.0
|
||||
import EQL5 1.0
|
||||
|
||||
Image {
|
||||
id: box2
|
||||
|
||||
Behavior on x {
|
||||
NumberAnimation {
|
||||
duration: 150
|
||||
easing.type: Easing.InQuart
|
||||
onRunningChanged: { Lisp.call("qsoko:animation-change", running) }
|
||||
}
|
||||
}
|
||||
|
||||
Behavior on y {
|
||||
NumberAnimation {
|
||||
duration: 150
|
||||
easing.type: Easing.InQuart
|
||||
onRunningChanged: { Lisp.call("qsoko:animation-change", running) }
|
||||
}
|
||||
}
|
||||
|
||||
SequentialAnimation {
|
||||
objectName: "wiggle"
|
||||
loops: 5
|
||||
onRunningChanged: { Lisp.call("qsoko:animation-change", running) }
|
||||
|
||||
RotationAnimation {
|
||||
target: box2
|
||||
property: "rotation"
|
||||
from: -30; to: 30
|
||||
duration: 300
|
||||
}
|
||||
|
||||
RotationAnimation {
|
||||
target: box2
|
||||
property: "rotation"
|
||||
from: 30; to: -30
|
||||
duration: 300
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -45,6 +45,7 @@
|
|||
|
||||
(defvar *player-item* (qml-component "player.qml")) ; :player
|
||||
(defvar *box-item* (qml-component "box.qml")) ; :object
|
||||
(defvar *box-item-2* (qml-component "box2.qml")) ; :object2
|
||||
(defvar *static-item* (qml-component "static.qml")) ; :wall :goal
|
||||
|
||||
(defun assoc* (item alist)
|
||||
|
|
@ -61,15 +62,17 @@
|
|||
(create-items)
|
||||
(place-all-items))
|
||||
|
||||
(defun create-item-type (type)
|
||||
(qt-object-? (|create| (case type
|
||||
(:object *box-item*)
|
||||
(:object2 *box-item-2*)
|
||||
((:player :player2) *player-item*)
|
||||
((:wall :goal) *static-item*)))))
|
||||
|
||||
(defun create-item (type)
|
||||
;; QT-OBJECT-?: auto cast to the most specific class
|
||||
;; here: from <QObject> to <QQuickItem>
|
||||
(let ((item (qt-object-? (|create| (case type
|
||||
((:player :player2) *player-item*)
|
||||
((:object :object2) *box-item*)
|
||||
((:wall :goal) *static-item*))))))
|
||||
(let ((item (create-item-type type)))
|
||||
(qml-set item "source" (|fromLocalFile.QUrl| (format nil "qml/img/~(~A~).png" type)))
|
||||
(|setObjectName| item (symbol-name type))
|
||||
(|setObjectName| item (string-downcase type))
|
||||
(unless *item-size*
|
||||
(setf *item-size* (qml-get item "sourceSize")))
|
||||
item))
|
||||
|
|
@ -160,7 +163,7 @@
|
|||
(setf (nth *level* *my-mazes*)
|
||||
(sokoban:copy-maze (nth *level* sokoban:*mazes*)))
|
||||
(set-maze))))
|
||||
t) ; event filter
|
||||
nil) ; event filter
|
||||
|
||||
(defun place-items (type)
|
||||
(let ((char (type-char type))
|
||||
|
|
@ -209,7 +212,19 @@
|
|||
(when (or (find type update-types)
|
||||
(find ex-type update-types))
|
||||
(queued (update-placed-items))))
|
||||
(setf ex-type type)))))
|
||||
(setf ex-type type)
|
||||
(qlater (lambda () (when (game-finished)
|
||||
(final-animation))))))))
|
||||
|
||||
(defun game-finished ()
|
||||
(let ((ch (type-char :object)))
|
||||
(dolist (str (sokoban:maze-text *maze*))
|
||||
(when (find ch str) (return-from game-finished))))
|
||||
t)
|
||||
|
||||
(defun final-animation ()
|
||||
(queued (qml-set-all "wiggle" "running" t)
|
||||
(qml-set-all "object2" "rotation" 0)))
|
||||
|
||||
(defun run ()
|
||||
(x:do-with *quick-view*
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue