diff --git a/README.md b/README.md index e8c0df8..3c9705e 100644 --- a/README.md +++ b/README.md @@ -31,10 +31,24 @@ directly. But you can use the signals from cljs. :main {:aspect :proceed}})) ``` -Any of those signals can be displayed with calling +To display the signals, you need to include the +[signals.css](public/signals.css) (or [signals.styl](src/signals/signals.styl) +if you use [Stylus](https://stylus-lang.com/)) and create a React component +returning a `svg` tag. Inside, you have to once include `signals.signal/defs`, +then you can call `signals.signal/signal` passing the signal you want with the +`:signal` key. + +Here an example using [UIx](https://github.com/pitch-io/uix): ```cljs -TODO +(require '[signals.signal :as signal]) + +($ :svg {:version "1.1" + :viewBox "0 0 140 600" + :width "200" + :height "600"} + ($ signal/defs) + ($ signal/signal {:signal @!main})) ``` You can configure signals by adding features to the top level, to the diff --git a/src/signals/helper.cljs b/src/signals/helper.cljs new file mode 100644 index 0000000..066487f --- /dev/null +++ b/src/signals/helper.cljs @@ -0,0 +1,11 @@ +(ns signals.helper + (:require + [cljs.spec.alpha :as s] + [preo.core :as p] + [signals.spec :as spec])) + +(defn stop-aspect? + "Returns true when the given aspect is a stop aspect" + [aspect] + {:pre [(p/arg! (s/nilable ::spec/aspect) aspect)]} + (#{:stop :stop+zs1 :stop+zs7 :stop+sh1} aspect)) diff --git a/src/signals/hl.cljs b/src/signals/hl.cljs index 8db30dc..ed897aa 100644 --- a/src/signals/hl.cljs +++ b/src/signals/hl.cljs @@ -3,8 +3,9 @@ [cljs.spec.alpha :as s] [clojure.set :refer [intersection]] [preo.core :as p] + [signals.helper :refer [stop-aspect?]] [signals.lamp :as lamp :refer [lamp]] - [signals.signal :as signal :refer [stop-aspect?]] + [signals.spec :as spec] [uix.core :refer [$ defui]])) (s/def ::top-yellow ::lamp/state) @@ -31,7 +32,7 @@ distant-addition :distant-addition} :distant signal-type :type :as signal}] - {:pre [(p/arg! ::signal/signal signal)] + {:pre [(p/arg! ::spec/signal signal)] :post [(p/ret! ::lights %)]} (let [distant? (= :distant signal-type) main? (= :main signal-type) @@ -97,7 +98,7 @@ 227)})) (defui view [{:keys [signal]}] - {:pre [(p/arg! ::signal/signal signal)]} + {:pre [(p/arg! ::spec/signal signal)]} (let [{:keys [top-yellow top-green top-white red bottom-white bottom-yellow replacement-red yellow-stripe green-stripe]} (lights signal)] ($ :g.hlSignal @@ -162,7 +163,7 @@ (defn speed-limit-available? [{{slow-speed-lights :slow-speed-lights} :main :as signal} limit] - {:pre [(p/arg! ::signal/signal signal)]} + {:pre [(p/arg! ::spec/signal signal)]} (let [speeds (-> slow-speed-lights set (intersection #{40 60 100}))] diff --git a/src/signals/hv_light.cljs b/src/signals/hv_light.cljs index 1518959..2e47f0c 100644 --- a/src/signals/hv_light.cljs +++ b/src/signals/hv_light.cljs @@ -2,8 +2,9 @@ (:require [cljs.spec.alpha :as s] [preo.core :as p] + [signals.helper :refer [stop-aspect?]] [signals.lamp :as lamp] - [signals.signal :as signal] + [signals.spec :as spec] [uix.core :refer [$ defui]])) ;; ---- Distant aspect @@ -38,21 +39,21 @@ distant-addition :distant-addition} :distant signal-type :type :as signal}] - {:pre [(p/arg! ::signal/signal signal)] + {:pre [(p/arg! ::spec/signal signal)] :post [(p/ret! ::lights %)]} {:main (when-not (= :distant signal-type) - {:green (if (signal/stop-aspect? main-aspect) :off :on) - :red (if (signal/stop-aspect? main-aspect) :on :off) + {:green (if (stop-aspect? main-aspect) :off :on) + :red (if (stop-aspect? main-aspect) :on :off) :yellow (let [has-light? (some #{40} main-slow-speed-lights)] (cond (not has-light?) nil - (and (not (signal/stop-aspect? main-aspect)) + (and (not (stop-aspect? main-aspect)) main-speed-limit (>= 60 main-speed-limit)) :on :else :off)) :secondary-red (cond (not sh1?) nil (= :stop+sh1 main-aspect) :off - (signal/stop-aspect? main-aspect) :on + (stop-aspect? main-aspect) :on :else :off) :sh1 (cond (not sh1?) nil @@ -71,23 +72,23 @@ distant-speed-limit (>= 60 distant-speed-limit))] {:top-green (cond - (signal/stop-aspect? main-aspect) :off - (signal/stop-aspect? distant-aspect) :off + (stop-aspect? main-aspect) :off + (stop-aspect? distant-aspect) :off :else :on) :top-yellow (cond - (signal/stop-aspect? main-aspect) :off - (signal/stop-aspect? distant-aspect) :on + (stop-aspect? main-aspect) :off + (stop-aspect? distant-aspect) :on :else :off) :white (when distant-addition - (if (signal/stop-aspect? main-aspect) :off :on)) + (if (stop-aspect? main-aspect) :off :on)) :bottom-green (cond - (signal/stop-aspect? main-aspect) :off - (signal/stop-aspect? distant-aspect) :off + (stop-aspect? main-aspect) :off + (stop-aspect? distant-aspect) :off slow-speed? :off :else :on) :bottom-yellow (cond - (signal/stop-aspect? main-aspect) :off - (signal/stop-aspect? distant-aspect) :on + (stop-aspect? main-aspect) :off + (stop-aspect? distant-aspect) :on slow-speed? :on :else :off)}))}) @@ -127,7 +128,7 @@ :y 24})))) (defui view [{:keys [signal]}] - {:pre [(p/arg! ::signal/signal signal)]} + {:pre [(p/arg! ::spec/signal signal)]} (let [{{:keys [green red yellow secondary-red sh1] :as main} :main {:keys [top-green top-yellow white bottom-green bottom-yellow]} :distant} (lights signal)] ($ :<> @@ -231,7 +232,7 @@ (defn speed-limit-available? [{{:keys [zs3 slow-speed-lights]} :main :as signal} limit] - {:pre [(p/arg! ::signal/signal signal)]} + {:pre [(p/arg! ::spec/signal signal)]} (cond (= :display zs3) true (= :sign zs3) limit diff --git a/src/signals/hv_semaphore.cljs b/src/signals/hv_semaphore.cljs index dcaa775..8c8131b 100644 --- a/src/signals/hv_semaphore.cljs +++ b/src/signals/hv_semaphore.cljs @@ -2,9 +2,10 @@ (:require [cljs.spec.alpha :as s] [preo.core :as p] + [signals.helper :refer [stop-aspect?]] [signals.hv-light :as hv-light] [signals.lamp :as lamp] - [signals.signal :as signal] + [signals.spec :as spec] [uix.core :refer [$ defui]])) (s/def :distant/disk #{:vertical :horizontal}) @@ -34,13 +35,13 @@ distant-addition :distant-addition} :distant signal-type :type :as signal}] - {:pre [(p/arg! ::signal/signal signal)] + {:pre [(p/arg! ::spec/signal signal)] :post [(p/ret! ::arms %)]} {:main (when-not (= :distant signal-type) - {:top-arm (if (signal/stop-aspect? main-aspect) :horizontal :inclined) + {:top-arm (if (stop-aspect? main-aspect) :horizontal :inclined) :lower-arm (cond (not (some #{40} main-slow-speed-lights)) nil - (and (not (signal/stop-aspect? main-aspect)) + (and (not (stop-aspect? main-aspect)) main-speed-limit (>= 60 main-speed-limit)) :inclined :else :vertical) @@ -60,20 +61,20 @@ (not= :repeater distant-addition)) (let [has-slow-speed? (some #{40} distant-slow-speed-lights) slow-speed? (and has-slow-speed? - (not (signal/stop-aspect? main-aspect)) - (not (signal/stop-aspect? distant-aspect)) + (not (stop-aspect? main-aspect)) + (not (stop-aspect? distant-aspect)) distant-speed-limit (>= 60 distant-speed-limit))] - {:disk (if (or (signal/stop-aspect? main-aspect) - (signal/stop-aspect? distant-aspect) + {:disk (if (or (stop-aspect? main-aspect) + (stop-aspect? distant-aspect) slow-speed?) :vertical :horizontal) :arm (cond (not has-slow-speed?) nil slow-speed? :inclined :else :vertical) - :right-lights (if (and (not (signal/stop-aspect? main-aspect)) - (not (signal/stop-aspect? distant-aspect))) + :right-lights (if (and (not (stop-aspect? main-aspect)) + (not (stop-aspect? distant-aspect))) :inclined :vertical) :shortened-break-path? (= :shortened-break-path distant-addition)}))}) @@ -183,7 +184,7 @@ :height 22})) (defui view [{:keys [signal]}] - {:pre [(p/arg! ::signal/signal signal)]} + {:pre [(p/arg! ::spec/signal signal)]} (let [{{:keys [top-arm lower-arm sh1] :as main} :main {:keys [disk arm right-lights] diff --git a/src/signals/ks.cljs b/src/signals/ks.cljs index 99368ed..da55158 100644 --- a/src/signals/ks.cljs +++ b/src/signals/ks.cljs @@ -2,8 +2,9 @@ (:require [cljs.spec.alpha :as s] [preo.core :as p] + [signals.helper :refer [stop-aspect?]] [signals.lamp :as lamp :refer [lamp]] - [signals.signal :as signal] + [signals.spec :as signal] [uix.core :refer [$ defui]])) (s/def ::top-white ::lamp/state) @@ -31,23 +32,23 @@ :post [(p/ret! ::lights %)]} {:top-white (cond (not= :shortened-break-path distant-addition) nil - (signal/stop-aspect? main-aspect) :off - (or (signal/stop-aspect? distant-aspect) + (stop-aspect? main-aspect) :off + (or (stop-aspect? distant-aspect) (and distant-speed-limit zs3v)) :on :else :off) :red (cond (= :distant signal-type) nil - (signal/stop-aspect? main-aspect) :on + (stop-aspect? main-aspect) :on :else :off) :green (cond - (signal/stop-aspect? main-aspect) :off - (signal/stop-aspect? distant-aspect) :off + (stop-aspect? main-aspect) :off + (stop-aspect? distant-aspect) :off (and distant-speed-limit zs3v) :blinking :else :on) :yellow (cond (= :main signal-type) nil - (signal/stop-aspect? main-aspect) :off - (signal/stop-aspect? distant-aspect) :on + (stop-aspect? main-aspect) :off + (stop-aspect? distant-aspect) :on :else :off) :center-white (cond (and (not sh1?) @@ -64,7 +65,7 @@ :bottom-white (if (= :distant signal-type) (cond (not= :repeater distant-addition) nil - (or (signal/stop-aspect? distant-aspect) + (or (stop-aspect? distant-aspect) (and distant-speed-limit zs3v)) :on :else :off) (cond diff --git a/src/signals/main.cljs b/src/signals/main.cljs index 20b703a..692b7c6 100644 --- a/src/signals/main.cljs +++ b/src/signals/main.cljs @@ -1,86 +1,20 @@ (ns signals.main (:require + [signals.helper :refer [stop-aspect?]] [signals.hl :as hl] [signals.hv-light :as hv-light] - [signals.hv-semaphore :as hv-semaphore] [signals.ks :as ks] - [signals.ne :as ne] [signals.signal :as signal] - [signals.zs3 :refer [zs3 zs3v]] [uix.core :as uix :refer [$ defui]] [uix.dom :as uix.dom])) -(defui radial-gradient [{:keys [id stop-color1 stop-color2]}] - ($ :radialGradient {:id id} - ($ :stop {:stopColor stop-color1 - :offset "0.05"}) - ($ :stop {:stopColor stop-color2 - :offset "0.9"}))) - -(defui defs [] - ($ :defs - ($ radial-gradient {:id "green-gradient" - :stop-color1 "#33ff6d" - :stop-color2 "#00bd4a"}) - ($ radial-gradient {:id "red-gradient" - :stop-color1 "#ff3763" - :stop-color2 "#da012a"}) - ($ radial-gradient {:id "orange-gradient" - :stop-color1 "#ffc955" - :stop-color2 "#fc8e00"}) - ($ radial-gradient {:id "yellow-gradient" - :stop-color1 "#ffe060" - :stop-color2 "#fac412"}) - ($ radial-gradient {:id "white-gradient" - :stop-color1 "#fffaef" - :stop-color2 "#ebe6d8"}))) - (defui signal [{:keys [signal]}] ($ :svg {:version "1.1" :viewBox "0 0 140 600" :width "200" :height "600"} - ($ defs) - (case (:system signal) - :ks ($ :<> - ($ :g {:transform "translate(16,0)"} - ($ zs3 {:signal signal})) - ($ :g {:transform "translate(19,65)"} - ($ ks/view {:signal signal})) - ($ :g {:transform "translate(16,168)"} - ($ zs3v {:signal signal})) - (when (and (= :distant (:type signal)) - (not (= :repeater (-> signal :distant :distant-addition)))) - ($ :g {:transform "translate(33,500)"} - ($ ne/ne2)))) - - :hl ($ :<> ($ hl/view {:signal signal}) - (when (and (= :distant (:type signal)) - (not (= :repeater (-> signal :distant :distant-addition)))) - ($ :g {:transform "translate(17,500)"} - ($ ne/ne2 {:shortened-break-path? (-> signal hl/lights :shortened-break-path?)})))) - :hv-light ($ :<> - ($ :g {:transform "translate(19,0)"} - ($ zs3 {:signal signal})) - ($ :g {:transform "translate(3,65)"} - ($ hv-light/view {:signal signal})) - ($ :g {:transform "translate(19,350)"} - ($ zs3v {:signal signal})) - (when (and (= :distant (:type signal)) - (not (= :repeater (-> signal :distant :distant-addition)))) - ($ :g {:transform "translate(33,500)"} - ($ ne/ne2)))) - :hv-semaphore ($ :<> - ($ :g {:transform "translate(19,0)"} - ($ zs3 {:signal signal})) - ($ :g {:transform "translate(3,65)"} - ($ hv-semaphore/view {:signal signal})) - ($ :g {:transform "translate(19,350)"} - ($ zs3v {:signal signal})) - (when (and (= :distant (:type signal)) - (not (= :repeater (-> signal :distant :distant-addition)))) - ($ :g {:transform "translate(33,500)"} - ($ ne/ne2 {:shortened-break-path? (-> signal hv-semaphore/arms :distant :shortened-break-path?)}))))))) + ($ signal/defs) + ($ signal/signal {:signal signal}))) (defui button [{:keys [on-click active? children disabled? type title] :or {type "primary"}}] @@ -278,25 +212,25 @@ :type "success"} "Fahrt") ($ :div.btn-group ($ button {:on-click #(set-combination-aspect! :stop) - :active? (signal/stop-aspect? current-aspect) + :active? (stop-aspect? current-aspect) :type "danger"} "Halt") (when (:sh1? combination-main) ($ button {:on-click #(set-combination-aspect! (if (= :stop+sh1 current-aspect) :stop :stop+sh1)) - :disabled? (not (signal/stop-aspect? current-aspect)) + :disabled? (not (stop-aspect? current-aspect)) :active? (= :stop+sh1 current-aspect)} "Sh1/Ra12")) (when (:zs1? combination-main) ($ button {:on-click #(set-combination-aspect! (if (= :stop+zs1 current-aspect) :stop :stop+zs1)) - :disabled? (not (signal/stop-aspect? current-aspect)) + :disabled? (not (stop-aspect? current-aspect)) :active? (= :stop+zs1 current-aspect)} "Zs1")) (when (:zs7? combination-main) ($ button {:on-click #(set-combination-aspect! (if (= :stop+zs7 current-aspect) :stop :stop+zs7)) - :disabled? (not (signal/stop-aspect? current-aspect)) + :disabled? (not (stop-aspect? current-aspect)) :active? (= :stop+zs7 current-aspect)} "Zs7"))))) (let [main-state (:main main) current-aspect (:aspect main-state)] @@ -307,25 +241,25 @@ ($ :div.btn-group ($ button {:on-click #(set-main-aspect! :stop) - :active? (signal/stop-aspect? current-aspect) + :active? (stop-aspect? current-aspect) :type "danger"} "Halt") (when (:sh1? main-state) ($ button {:on-click #(set-main-aspect! (if (= :stop+sh1 current-aspect) :stop :stop+sh1)) - :disabled? (not (signal/stop-aspect? current-aspect)) + :disabled? (not (stop-aspect? current-aspect)) :active? (= :stop+sh1 current-aspect)} "Sh1/Ra12")) (when (:zs1? main-state) ($ button {:on-click #(set-main-aspect! (if (= :stop+zs1 current-aspect) :stop :stop+zs1)) - :disabled? (not (signal/stop-aspect? current-aspect)) + :disabled? (not (stop-aspect? current-aspect)) :active? (= :stop+zs1 current-aspect)} "Zs1")) (when (:zs7? main-state) ($ button {:on-click #(set-main-aspect! (if (= :stop+zs7 current-aspect) :stop :stop+zs7)) - :disabled? (not (signal/stop-aspect? current-aspect)) + :disabled? (not (stop-aspect? current-aspect)) :active? (= :stop+zs7 current-aspect)} "Zs7")))))) ($ :tr ($ :th "Features") diff --git a/src/signals/signal.cljs b/src/signals/signal.cljs index b32921b..26459c0 100644 --- a/src/signals/signal.cljs +++ b/src/signals/signal.cljs @@ -1,41 +1,87 @@ (ns signals.signal (:require - [cljs.spec.alpha :as s] - [preo.core :as p])) + [preo.core :as p] + [signals.hl :as hl] + [signals.hv-light :as hv-light] + [signals.hv-semaphore :as hv-semaphore] + [signals.ks :as ks] + [signals.ne :as ne] + [signals.spec :as spec] + [signals.zs3 :refer [zs3 zs3v]] + [uix.core :as uix :refer [$ defui]])) -;; Aspects -(s/def ::aspect #{:stop :proceed :stop+zs1 :stop+zs7 :stop+sh1}) -(s/def ::speed-limit (s/nilable (s/and int? pos?))) +(defui radial-gradient [{:keys [id stop-color1 stop-color2]}] + ($ :radialGradient {:id id} + ($ :stop {:stopColor stop-color1 + :offset "0.05"}) + ($ :stop {:stopColor stop-color2 + :offset "0.9"}))) -;; Configuration -(s/def ::sh1? boolean?) -(s/def ::zs1? boolean?) -(s/def ::zs3 (s/nilable #{:display :sign})) -(s/def ::zs3v (s/nilable #{:display :sign})) -(s/def ::zs7? boolean?) -;; Does the Hv have a yellow light/second arm or does Hl have yellow light, green or yellow strips? -(s/def ::slow-speed-lights (s/coll-of int? :distinct true :kind vector?)) -(s/def ::distant-addition (s/nilable #{:repeater :shortened-break-path})) +(defui defs [] + ($ :defs + ($ radial-gradient {:id "green-gradient" + :stop-color1 "#33ff6d" + :stop-color2 "#00bd4a"}) + ($ radial-gradient {:id "red-gradient" + :stop-color1 "#ff3763" + :stop-color2 "#da012a"}) + ($ radial-gradient {:id "orange-gradient" + :stop-color1 "#ffc955" + :stop-color2 "#fc8e00"}) + ($ radial-gradient {:id "yellow-gradient" + :stop-color1 "#ffe060" + :stop-color2 "#fac412"}) + ($ radial-gradient {:id "white-gradient" + :stop-color1 "#fffaef" + :stop-color2 "#ebe6d8"}))) -(s/def ::main (s/keys :req-un [::aspect ::speed-limit ::slow-speed-lights ::sh1? ::zs1? ::zs3 ::zs7?])) -(s/def ::distant (s/keys :req-un [::aspect ::speed-limit ::distant-addition ::slow-speed-lights ::zs3v])) +(defui signal [{:keys [signal]}] + (case (:system signal) + :ks ($ :<> + ($ :g {:transform "translate(16,0)"} + ($ zs3 {:signal signal})) + ($ :g {:transform "translate(19,65)"} + ($ ks/view {:signal signal})) + ($ :g {:transform "translate(16,168)"} + ($ zs3v {:signal signal})) + (when (and (= :distant (:type signal)) + (not (= :repeater (-> signal :distant :distant-addition)))) + ($ :g {:transform "translate(33,500)"} + ($ ne/ne2)))) -(s/def ::type #{:distant :main :combination}) -(s/def ::system #{:ks :hl :hv-light :hv-semaphore}) -(s/def ::signal (s/keys :req-un [::type ::system] - :opt-un [::distant ::main])) - -(defn stop-aspect? - "Returns true when the given aspect is a stop aspect" - [aspect] - {:pre [(p/arg! (s/nilable ::aspect) aspect)]} - (#{:stop :stop+zs1 :stop+zs7 :stop+sh1} aspect)) + :hl ($ :<> ($ hl/view {:signal signal}) + (when (and (= :distant (:type signal)) + (not (= :repeater (-> signal :distant :distant-addition)))) + ($ :g {:transform "translate(17,500)"} + ($ ne/ne2 {:shortened-break-path? (-> signal hl/lights :shortened-break-path?)})))) + :hv-light ($ :<> + ($ :g {:transform "translate(19,0)"} + ($ zs3 {:signal signal})) + ($ :g {:transform "translate(3,65)"} + ($ hv-light/view {:signal signal})) + ($ :g {:transform "translate(19,350)"} + ($ zs3v {:signal signal})) + (when (and (= :distant (:type signal)) + (not (= :repeater (-> signal :distant :distant-addition)))) + ($ :g {:transform "translate(33,500)"} + ($ ne/ne2)))) + :hv-semaphore ($ :<> + ($ :g {:transform "translate(19,0)"} + ($ zs3 {:signal signal})) + ($ :g {:transform "translate(3,65)"} + ($ hv-semaphore/view {:signal signal})) + ($ :g {:transform "translate(19,350)"} + ($ zs3v {:signal signal})) + (when (and (= :distant (:type signal)) + (not (= :repeater (-> signal :distant :distant-addition)))) + ($ :g {:transform "translate(33,500)"} + ($ ne/ne2 {:shortened-break-path? (-> signal hv-semaphore/arms :distant :shortened-break-path?)})))))) (defn main "Constructor for a main signal" [{:keys [aspect speed-limit slow-speed-lights sh1? zs1? zs3 zs7? system] :or {aspect :stop sh1? false zs1? false zs3 nil zs7? false slow-speed-lights []}}] - {:post [(p/ret! ::signal %)]} + {:post [(p/ret! ::spec/signal %)]} {:system system :type :main :main {:aspect aspect @@ -50,7 +96,7 @@ "Constructor for a distant signal" [{:keys [aspect speed-limit slow-speed-lights distant-addition zs3v system] :or {aspect :stop zs3v nil slow-speed-lights []}}] - {:post [(p/ret! ::signal %)]} + {:post [(p/ret! ::spec/signal %)]} {:system system :type :distant :distant {:aspect aspect @@ -72,7 +118,7 @@ :keys [sh1? zs1? zs3 zs7?] :or {main-aspect :stop sh1? false zs1? false zs3 nil zs7? false main-slow-speed-lights []}} :main system :system}] - {:post [(p/ret! ::signal %)]} + {:post [(p/ret! ::spec/signal %)]} {:system system :type :combination :distant {:aspect distant-aspect diff --git a/src/signals/spec.cljs b/src/signals/spec.cljs new file mode 100644 index 0000000..4ba622c --- /dev/null +++ b/src/signals/spec.cljs @@ -0,0 +1,26 @@ +(ns signals.spec + (:require + [cljs.spec.alpha :as s])) + +;; Aspects +(s/def ::aspect #{:stop :proceed :stop+zs1 :stop+zs7 :stop+sh1}) +(s/def ::speed-limit (s/nilable (s/and int? pos?))) + +;; Configuration +(s/def ::sh1? boolean?) +(s/def ::zs1? boolean?) +(s/def ::zs3 (s/nilable #{:display :sign})) +(s/def ::zs3v (s/nilable #{:display :sign})) +(s/def ::zs7? boolean?) +;; Does the Hv have a yellow light/second arm or does Hl have yellow light, green or yellow strips? +(s/def ::slow-speed-lights (s/coll-of int? :distinct true :kind vector?)) +(s/def ::distant-addition (s/nilable #{:repeater :shortened-break-path})) + +(s/def ::main (s/keys :req-un [::aspect ::speed-limit ::slow-speed-lights ::sh1? ::zs1? ::zs3 ::zs7?])) +(s/def ::distant (s/keys :req-un [::aspect ::speed-limit ::distant-addition ::slow-speed-lights ::zs3v])) + +(s/def ::type #{:distant :main :combination}) +(s/def ::system #{:ks :hl :hv-light :hv-semaphore}) +(s/def ::signal (s/keys :req-un [::type ::system] + :opt-un [::distant ::main])) + diff --git a/src/signals/zs3.cljs b/src/signals/zs3.cljs index 495235b..cd7b941 100644 --- a/src/signals/zs3.cljs +++ b/src/signals/zs3.cljs @@ -2,17 +2,18 @@ (:require [preo.core :as p] [signals.display :as display] - [signals.signal :as signal] + [signals.helper :refer [stop-aspect?]] + [signals.spec :as spec] [signals.zs3.sign :as zs3.sign] [uix.core :refer [$ defui]])) (defui zs3 [{{{:keys [zs3 speed-limit aspect]} :main :as signal} :signal}] - {:pre [(p/arg! ::signal/signal signal)]} + {:pre [(p/arg! ::spec/signal signal)]} (case zs3 :display ($ :g {:transform "translate(8,19)"} ($ display/view {:color :white - :value (when (and (not (signal/stop-aspect? aspect)) + :value (when (and (not (stop-aspect? aspect)) speed-limit) (/ speed-limit 10))})) :sign ($ zs3.sign/view {:position :main @@ -23,12 +24,12 @@ distant-aspect :aspect} :distant {main-aspect :aspect} :main :as signal} :signal}] - {:pre [(p/arg! ::signal/signal signal)]} + {:pre [(p/arg! ::spec/signal signal)]} (case zs3v :display ($ :g {:transform "translate(8,19)"} ($ display/view {:color :yellow - :value (when (and (not (signal/stop-aspect? distant-aspect)) - (not (signal/stop-aspect? main-aspect)) + :value (when (and (not (stop-aspect? distant-aspect)) + (not (stop-aspect? main-aspect)) speed-limit) (/ speed-limit 10))})) :sign ($ zs3.sign/view {:position :distant