cljfx

Jonathan Bennett 2026-01-06T04:25:57.195729Z

I'm having some trouble with images in a table cell not loading correctly. I am in the process of getting my game to work online in a peer to peer style of gameplay, and part of that required me to pull each unit's image path out of the unit's data map because that map is getting sent over the network (so the addresses would break). I switched to creating a map which preloads each image and then it's supposed to be just a lookup. Unfortunately the images are not loading and I'm not sure why. Here is my draw-sprite method and the description of the table cell where the image should be drawn. I know that assets/get-unit-sprite returns a javafx.scene.image.Image object from my logging. The result right now is an empty cell of the correct size for the image.

(defn draw-sprite
  [{:keys [unit assets bf x y shift direction]}]
  (let [camo nil ;;(:unit-group/camo bf)
        image (assets/get-unit-sprite assets (:unit/full-name unit) (:unit/chassis unit))
        color "#FFFFFF"]
    {:fx/type :image-view
     :image image
     :fit-width 84
     :fit-height 72
     :preserve-ratio true
     :effect {:fx/type :blend
              :mode :src-atop
              :opacity 0.5
              ;; The 'bottom-input' is implicitly the ImageView itself!
              :top-input (if camo
                           {:fx/type :image-input
                            :source camo}
                           {:fx/type :color-input
                            :paint color
                            ;; Match the size of the sprite
                            :width 84
                            :height 72})}
     :rotate (or (:angle direction) 0)
     :translate-x x
     :translate-y (+ y shift)}))

(defn units-table [{:keys [fx/context]}]
  (let [units (subs/units context)
        assets (subs/assets context)
        forces (subs/forces context)
        selected nil]
    (if (empty? units)
      {:fx/type :label
       :text "Please add a unit."}
      {:fx/type tables/with-selection-props
       :props {:selection-mode :single
               :on-selected-item-changed {:event-type ::events/unit-selection-changed :fx/sync true}
               :selected-item selected}
       :desc {:fx/type :table-view
              :columns [{:fx/type :table-column
                         :text "Unit"
                         :cell-value-factory identity
                         :cell-factory {:fx/cell-type :table-cell
                                        :describe (fn [x] {:text (:unit/id x)})}}
                        {:fx/type :table-column
                         :text "Image"
                         :cell-value-factory identity
                         :cell-factory {:fx/cell-type :table-cell
                                        :describe (fn [x] {:graphic {:fx/type elements/draw-sprite
                                                                     :unit x
                                                                     :assets assets
                                                                     :bf (battle-force/select-force forces (:unit/battle-force x))
                                                                     :x 0
                                                                     :y 0
                                                                     :shift 0}})}}
;; Continues below
}})))

Jonathan Bennett 2026-01-07T04:24:03.781059Z

I was able to fix it. Somehow the address wasn't getting concatenated correctly, it had an extra slash in the middle (file:/users/my.name/src//megastrike/data/images/units/image.png) and I missed that in my vdiff of my logs. Sorry!