Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (def testds {:e [
- {:c :blah :x 1 :y 2}
- {:c :foo :x 2 :y 5}]
- :e1 [
- {:c :blah :x 1 :z 2}
- {:c :foo :x 5 :z 12}]})
- repl=> (swap! testds update-in [:e0] conj {:c :zoom :x 1 :y 1})
- {:e0 [{:c :blah, :x 1, :y 2} {:c :foo, :x 2, :y 5} {:c :zoom, :x 1, :y 1}], :e1 [{:c :blah, :x 1, :z 2} {:c :foo, :x 5, :z 12}]}
- ;; Adding a map to the entity vector works at the repl.
- (defn create-entity! [state name]
- "adds entity with given name to state atom"
- (swap! state assoc (gensym name) (vector nil)))
- (defn add-component! [state e m]
- "add given component c to entity e in the game state"
- (let [entity e
- component m]
- (swap! state update-in (vector entity) conj component)))
- repl=> (create-entity! testds :e4)
- {:e0 [{:c :blah, :x 1, :y 2} {:c :foo, :x 2, :y 5}], :e1 [{:c :blah, :x 1, :z 2} {:c :foo, :x 5, :z 12}], :e42 [nil]}
- ;; OK, that looks correct
- repl=> (add-component! testds :e42 {:c :bleck :x 1 :y 2})
- {:e0 [{:c :blah, :x 1, :y 2} {:c :foo, :x 2, :y 5}], :e1 [{:c :blah, :x 1, :z 2} {:c :foo, :x 5, :z 12}], :e42 [nil], :e42 ({:c :bleck, :x 1, :y 2})}
- ;; But when using add-component! it appends a new entity vs adding a map to the entity vector.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement