Beginning to get IOS, Android, and Desktop all working at once. Re-enabling steam.

This commit is contained in:
Bryce Covert
2020-01-07 22:18:35 -08:00
parent 7152acd658
commit d1a898035d
11 changed files with 582 additions and 457 deletions

View File

@@ -53,7 +53,7 @@
:mobile-dev {
:source-paths ["src" "src-common" "src-dev"]
:jvm-opts ["-Duse-repl=true" "-Dui_scale=1.5" "-Dno-steam=true" "-Dclojure.compiler.direct-linking=true" "-Dis-desktop=true" "-Dplatform=desktop"]
:dependencies [[com.badlogicgames.gdx/gdx-tools "1.5.3"]
:dependencies [[com.badlogicgames.gdx/gdx-tools "1.9.4"]
[org.clojure/tools.nrepl "0.2.12"]
[play-clj-nrepl "0.1.0" :exclusions [play-clj]]
[slamhound "1.5.5"]
@@ -72,7 +72,7 @@
:steam-dev {
:source-paths ["src" "src-common" "src-dev"]
:jvm-opts ["-Duse-repl=true" "-Dui_scale=1.0" "-Dis-desktop=true" "-Dplatform=desktop"]
:dependencies [[com.badlogicgames.gdx/gdx-tools "1.5.3"]
:dependencies [[com.badlogicgames.gdx/gdx-tools "1.9.4"]
[org.clojure/tools.nrepl "0.2.7"]
[play-clj-nrepl "0.1.0" :exclusions [play-clj]]
[slamhound "1.5.5"]

File diff suppressed because it is too large Load Diff

View File

@@ -1,5 +1,5 @@
{
com.badlogic.gdx.graphics.g2d.BitmapFont: { default-font: { file: ego/font.fnt, scale: 0.5 }, button-font: { file: ego/button-font.fnt }}
com.badlogic.gdx.graphics.g2d.BitmapFont: { default-font: { file: ego/font.fnt, scale: 0.5 }, button-font: { file: ego/button-font.fnt, scale: 0.5 }}
com.badlogic.gdx.graphics.Color: {
button-font-up: {hex: 19003Dff },
gray: {hex: 21172Eff },

View File

@@ -43,7 +43,8 @@
(defgame advent
:on-create
(fn [this]
(create-game advent)))
(steam/init)
(create-game advent)))
(defn reload []
(on-gl (set-screen! advent title/title-screen)))

View File

@@ -545,10 +545,12 @@
(-> e
(assoc-in [:room :entities :penultimate-black :opacity] 1)
(assoc-in [:cam :paused?] false)
(update-in [:room :entities :black-blowup] (fn [b]
(particle-effect! b :reset)
(particle-effect! b :start)
b)))))
(update-in [:room :entities (if won? :black-blowup-big
:black-blowup)]
(fn [b]
(particle-effect! b :reset)
(particle-effect! b :start)
b)))))
(println "doing screen shake?")
(actions/camera-shake entities 8.0)

View File

@@ -145,6 +145,7 @@
heart (utils/make-anim-seq atlas "heart" [24 24] 0.08 [3])
beat (utils/make-anim-seq atlas "heart" [24 24] 0.08 [0 1 0 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3])
black-blowup (particle-effect "particles/black-blowup")
black-blowup-big (particle-effect "particles/black-blowup-big")
tongue-idle (utils/make-anim-seq atlas "tongue-idle/tongue-idle" [135 145] 0.16 (range 5))
tongue-windup (utils/make-anim-seq atlas "tongue-windup" [135 145] 0.16 [0 1 2 3 2 1 2 3 2 1 0 ])
@@ -195,6 +196,10 @@
:black-blowup (assoc black-blowup
:x 222 :y 85
:baseline 241)
:black-blowup-big (assoc black-blowup-big
:x 222 :y 85
:baseline 241)
:hair-0 (assoc (animation->texture screen hair-0)
:x 35
:y 46

View File

@@ -1098,7 +1098,10 @@
(update-in entities [:tweens] dissoc :cam-x :cam-y :cam-zoom))
(defn render [{:keys [^OrthographicCamera camera ^FitViewport viewport ^Stage renderer] :as screen} {{:keys [last-pos ] [cursor-offset-x cursor-offset-y] :offset} :cursor :keys [tweens] :as entities} options]
#_(steam/update)
(utils/platformify
nil
nil
(steam/update))
(.apply viewport)
(if (-> entities :closing? :value)

View File

@@ -94,6 +94,7 @@
(utils/play-music (:pop-music entities))
(-> entities
(assoc-in [:pop-logo :anim-start] (:total-time screen))
(assoc-in [:pop-logo :opacity] 1.0)
(assoc-in [:pop-logo :anim] (get-in entities [:pop-logo :main-anim]))))
:duration 10.0}]))
@@ -112,12 +113,17 @@
:on-show
(fn [screen entities options]
(let [[screen splash-atlas] (utils/acquire-atlas screen "packed/splash.atlas")
[screen global-atlas] (utils/acquire-atlas screen "packed/global.atlas")]
[screen global-atlas] (utils/acquire-atlas screen "packed/global.atlas")
[screen pop-logo-atlas] (if utils/mobile?
[screen nil]
(utils/acquire-atlas screen "packed-pop-logo/pack.atlas"))]
(utils/setup-viewport screen 1280 960)
(log/info "Starting splash screen.")
(graphics! :set-cursor (utils/cursor "cursor.png" :hourglass))
(let [screen (assoc screen :total-time 0)
pop-anim (make-anim-seq splash-atlas "POPPixelLogo_02" [320 240] 0.05 (repeat 200 0))
pop-anim (if utils/mobile?
(make-anim-seq splash-atlas "POPPixelLogo_02" [320 240] 0.05 (repeat 200 0))
(make-anim-seq pop-logo-atlas "POPPixelLogo_02" [320 240] 0.05 (range 200)))
entities {:background (assoc (utils/atlas->texture global-atlas "black.png")
:scale-x 80
:scale-y 80
@@ -126,12 +132,12 @@
:origin-y 0
:z 0)
:pop-logo (assoc (animation->texture screen pop-anim)
:anim pop-anim
:main-anim pop-anim
:x 0 :y 0
:origin-x 0 :origin-y 0
:scale-x 4 :scale-y 4
:z 1
:opacity (if utils/mobile? 0.0 1.0))
:opacity 0.0)
:dbhlogo (assoc (utils/atlas->texture splash-atlas "dbh.png") :x 0 :y 0 :origin-x 0 :origin-y 0 :scale-x 4 :scale-y 4 :z 1 :opacity 0.0)
:steps steps
:pop-music (utils/make-music "music/POPPixelLogo2Audiomix_mixdown.ogg")
@@ -144,7 +150,10 @@
:on-render
(fn [{:keys [^FitViewport viewport] :as screen} entities options]
#_(steam/update)
(utils/platformify
nil
nil
(steam/update))
(.apply viewport)
(clear!)
(let [entities (utils/apply-tweens screen entities (:tweens entities))

View File

@@ -134,6 +134,7 @@
(tween/tween :fade-out-music screen [:volume] 1.0 0.0 1.0)))))
(defn button-style []
(let [^TextButton$TextButtonStyle style (skin! (skin "ui/ui.json") :get TextButton$TextButtonStyle)
tx (-> style .font .getRegion .getTexture)]
(-> style .font .getData (.setScale utils/button-font-scale))
@@ -149,7 +150,11 @@
([msg & rest]
(let [button (merge (text-button msg (button-style))
(apply hash-map rest))]
(utils/platformify
nil
nil
(doto (text-button! button :get-label)
(.setFontScale 0.5)))
(doto button save-object))))
@@ -164,10 +169,15 @@
([msg checked & rest]
(let [s (skin! (skin "ui/ui.json") :get CheckBox$CheckBoxStyle)]
(-> s .font .getData (.setScale utils/title-label-scale))
(doto (merge (check-box msg s)
(apply hash-map rest))
(set-checkbox-state checked)
save-object))))
(let [checkbox-entity (merge (check-box msg s)
(apply hash-map rest))]
(utils/platformify
nil
nil
(doto (check-box! checkbox-entity :get-label)
(.setFontScale 0.25)))
(set-checkbox-state checkbox-entity checked)
(save-object checkbox-entity)))))
(defn make-label
([msg]
@@ -456,7 +466,10 @@
:on-render
(fn [{:keys [^FitViewport viewport] :as screen} entities options]
#_(steam/update)
(utils/platformify
nil
nil
(steam/update))
(.apply viewport)
(clear!)
(let [entities (utils/apply-tweens screen entities (:tweens entities))

View File

@@ -1,59 +1,151 @@
(ns advent.steam
(:require [play-clj.core :refer :all])
(:import [com.badlogic.gdx.graphics Pixmap PixmapIO$PNG]
(:import [java.nio ByteBuffer CharBuffer]
[java.io ByteArrayOutputStream]
[com.badlogic.gdx.graphics Pixmap PixmapIO$PNG]
[com.badlogic.gdx.files FileHandle]))
(def has-steam?
false
)
(if (= "desktop" (System/getProperty "platform"))
(try
(import '[com.codedisaster.steamworks SteamUserStats SteamUserStatsCallback SteamAPI SteamRemoteStorage])
true
(catch Exception e
false))
false))
(println "loading steam")
(def is-app-store? false)
(defmacro steamify [steam-version & [regular-version]]
(if has-steam?
`(if (and has-steam? (not (System/getProperty "no-steam")))
~steam-version
~regular-version)
regular-version))
(defn init []
(steamify
(if (SteamAPI/init)
(println "Steam initialized")
(do
(println "Steam not initialized")
(def has-steam? false)))))
(defn update []
(steamify
(when (SteamAPI/isSteamRunning)
(SteamAPI/runCallbacks))))
(if has-steam?
(eval
'(do
(defn achievement-fn [f achievement]
(steamify
(let [stats (atom nil)]
(println "Getting stats...")
(reset! stats (SteamUserStats. (reify SteamUserStatsCallback
(onUserStatsReceived [_ _ _ _]
(f @stats achievement)
)
(onUserStatsStored [_ _ _])
(onUserAchievementStored [_ _ _ _ _ _]))))
(.requestCurrentStats @stats))))
(def set-achievement (partial achievement-fn
(fn [^SteamUserStats stats ^String achievement]
(println "Setting achievement" achievement)
(.setAchievement stats achievement)
(.storeStats stats)
(println "Done setting achievement" achievement))))
(def clear-achievement (partial achievement-fn
(fn [^SteamUserStats stats ^String achievement]
(println "Clearing achievement" achievement)
(.clearAchievement stats achievement)
(.storeStats stats)
(println "Done clearing achievement" achievement)))))
)
(do
(defn set-achievement [achievement])
(defn clear-achievement [achievement])))
(def is-app-store? (System/getProperty "app-store"))
(def all-achievements ["PARDON" "EX_CON" "PRO_WRESTLER" "SHEEP_HORDER" "SAFE_AND_SOUND" "DESTINY" "WISE_UP" "TONGUESBANE" "KITTY_KISS" "BEHOLDER" "MOUTH_DIVER"])
(defn clear-achievement [])
(defn set-achievement [x])
(defn clear-all-achievements []
(doall (map clear-achievement all-achievements)))
(defn get-bytes [filename]
(.readBytes (if is-app-store?
(files! :external filename)
(files! :local filename))))
(steamify
(let [rs (SteamRemoteStorage. nil)
len (.getFileSize rs filename)
bb (ByteBuffer/allocateDirect len)
bytes (make-array Byte/TYPE len)]
(.fileRead rs filename bb len)
(.get bb bytes)
bytes)
(.readBytes (if is-app-store?
(files! :external filename)
(files! :local filename)))))
(defn write-bytes [filename bytes]
(let [f (if is-app-store?
(files! :external filename)
(files! :local filename))]
(.writeBytes f bytes false)))
(steamify
(let [rs (SteamRemoteStorage. nil)
bb (ByteBuffer/allocateDirect (* 2 (count bytes)))]
(-> bb (.put bytes) )
(.fileWrite rs filename bb (* 2 (count bytes))))
(let [f (if is-app-store?
(files! :external filename)
(files! :local filename))]
(.writeBytes f bytes false))))
(defn list-edn-files []
(if is-app-store?
(for [save-file (.list (files! :external "saves/") ".edn")]
(str "saves/" (.name ^FileHandle save-file)))
(for [save-file (.list (files! :local "saves/") ".edn")]
(str "saves/" (.name ^FileHandle save-file)))))
(steamify
(let [rs (SteamRemoteStorage. nil)]
(for [i (range (.getFileCount rs))
:let [n (.getFileNameAndSize rs i (make-array Integer/TYPE 1))]
:when (.endsWith n ".edn")]
n))
(if is-app-store?
(for [save-file (.list (files! :external "saves/") ".edn")]
(str "saves/" (.name ^FileHandle save-file)))
(for [save-file (.list (files! :local "saves/") ".edn")]
(str "saves/" (.name ^FileHandle save-file))))))
(defn save-screenshot [^Pixmap pm ^String filename]
(let [f (if is-app-store?
(files! :external filename)
(files! :local filename))
png (PixmapIO$PNG. (* (.getWidth pm) (.getHeight pm) 1.5))]
(.write png f pm)
(.dispose png)))
(steamify
(let [rs (SteamRemoteStorage. nil)
png (PixmapIO$PNG. (* (.getWidth pm) (.getHeight pm) 1.5))
baos (ByteArrayOutputStream. (* (.getWidth pm) (.getHeight pm) 1.5))
_ (.write png baos pm)
bytes (.toByteArray baos)
bb (ByteBuffer/allocateDirect (count bytes))]
(.put bb bytes)
(.fileWrite rs filename bb (count bytes)))
(let [f (if is-app-store?
(files! :external filename)
(files! :local filename))
png (PixmapIO$PNG. (* (.getWidth pm) (.getHeight pm) 1.5))]
(.write png f pm)
(.dispose png))))
(defn delete-file [filename]
(let [file (if is-app-store?
(files! :external filename)
(files! :local filename))]
(when (.exists file)
(.delete file))))
(steamify
(.fileDelete (SteamRemoteStorage. nil) filename)
(let [file (if is-app-store?
(files! :external filename)
(files! :local filename))]
(when (.exists file)
(.delete file)))))
(defn save-screenshot-file-name [name]
(str "saves/screenshot-" (clojure.core/name name) ".png" ))
(steamify
(str "screenshot-" (clojure.core/name name) ".png" )
(str "saves/screenshot-" (clojure.core/name name) ".png" )))
(defn save-file-name [id]
(str "saves/" id ".edn"))
(steamify
(str id ".edn")
(str "saves/" id ".edn")))

View File

@@ -33,7 +33,8 @@
entity)
(def ui-scale (Double/parseDouble (str (or (System/getProperty "ui_scale") 1.5))))
(def ui-scale (doto (Double/parseDouble (str (or (System/getProperty "ui_scale") 1.5))) (println "UI scale")))
(def button-scale (+ 1 (* (- ui-scale 1.0) 2.0)))
(def mobile? (= 1.5 ui-scale))
(def max-zoom (if mobile? 0.5 0.75))
@@ -306,8 +307,7 @@
edn/read-string)))
(defn get-font [filename]
(let [font (-> (bitmap-font filename)
#_(doto (bitmap-font! :set-font-scale 0.5 0.5)))
(let [font (-> (bitmap-font filename))
tr (bitmap-font! font :get-region)
tx (.getTexture tr)]
(call! ^Texture tx :set-filter Texture$TextureFilter/Linear Texture$TextureFilter/Linear)