Begin typed MainActivity conversion
ober
0581ba85db8350adae92d5533f15f476396e2668
new file mode 100644 --- /dev/null +++ b/templates/original-tactics-parts/MainActivity.kt.ss @@ -0,0 +1,367 @@ +(import (jerboa prelude)) + +(def fragment + '((typed-kotlin-file "com/jerboa/originaltactics/MainActivity.kt" + (kotlin-imports (android graphics Color) + (android view View) + (org json JSONObject)) + (typed-library (com jerboa originaltactics) + (export ShipChoice FireTargetChoice TruthMatch FullscreenPanelSpec + CommandTone mainActivityShipChoiceDisplay + mainActivityFireTargetShipTarget autoEventDelayMillis + isPhaserWeapon weaponSortBucket actorLabel fireGroupName + hudActionLabel seekingSortBucket shortDefenseKind + truncateForLog isInterestingEvent) + (type Any) + (type Float32) + (type Int32) + (type JSONObject) + (type View) + (extern (mainActivityColorRgb + (red : Int32) + (green : Int32) + (blue : Int32)) : Int32 + (kotlin-call Color rgb)) + (extern (mainActivityTargetValue + (target : JSONObject) + (key : String) + (fallback : String)) : String + (kotlin-member-call optString)) + (extern (mainActivityEventType + (event : JSONObject) + (key : String) + (fallback : String)) : String + (kotlin-member-call optString)) + (extern (mainActivityStringReplace + (text : String) + (old : String) + (replacement : String)) : String + (kotlin-member-call replace)) + (def (mainActivityShipChoiceDisplay + (name : String) + (race : String) + (source : String) + (page : Int32)) : String + (if (and (equal? source "ssd-truth") (> page (int32 0))) + (string-append + name + (string-append " p" (int32->string page))) + (if (equal? source "ssd-truth") + name + (if (or (string-blank? race) + (string-contains? + (string-lowercase name) + (string-lowercase race))) + name + (string-append race (string-append " " name)))))) + (def (mainActivityFireTargetShipTarget + (target : JSONObject)) : (Nullable String) + (let ((value + (mainActivityTargetValue target "target" ""))) + (if (or (equal? value "alpha") (equal? value "beta")) + (nullable-some value) + (nullable-none String)))) + (class ShipChoice + ((id : String (property val)) + (name : String (property val)) + (race : String (property val)) + (source : String (property val)) + (page : Int32 (property val))) + (val display : String + (mainActivityShipChoiceDisplay name race source page)) + (def (toString) : String + (modifiers override) + display)) + (class FireTargetChoice + ((key : String (property val)) + (label : String (property val)) + (target : JSONObject (property val))) + (val shipTarget : (Nullable String) + (mainActivityFireTargetShipTarget target))) + (class TruthMatch + ((entry : JSONObject (property val)) + (score : Int32 (property val)) + (overlap : Int32 (property val)) + (diff : Int32 (property val)))) + (class FullscreenPanelSpec + ((title : String (property val)) + (factory : (-> View) (property val)))) + (enum CommandTone () + (NAV) + (PRIMARY) + (WEAPON) + (AUTO) + (DANGER) + (UTILITY)) + (val UI_BG : Int32 + (mainActivityColorRgb (int32 6) (int32 10) (int32 16)) + (modifiers private)) + (val UI_PANEL_DARK : Int32 + (mainActivityColorRgb (int32 11) (int32 17) (int32 27)) + (modifiers private)) + (val UI_PANEL : Int32 + (mainActivityColorRgb (int32 18) (int32 27) (int32 40)) + (modifiers private)) + (val UI_STROKE : Int32 + (mainActivityColorRgb (int32 64) (int32 84) (int32 112)) + (modifiers private)) + (val UI_TEXT : Int32 + (mainActivityColorRgb (int32 231) (int32 238) (int32 248)) + (modifiers private)) + (val UI_MUTED : Int32 + (mainActivityColorRgb (int32 151) (int32 170) (int32 198)) + (modifiers private)) + (val UI_DIM : Int32 + (mainActivityColorRgb (int32 102) (int32 120) (int32 148)) + (modifiers private)) + (val UI_ACCENT : Int32 + (mainActivityColorRgb (int32 88) (int32 156) (int32 226)) + (modifiers private)) + (val DEFAULT_ENDPOINT : String + "http://127.0.0.1:8788/api/service" + (modifiers private const)) + (val CLIENT_LOG_ENDPOINT : String + "http://10.66.60.2:8799/api/client-log" + (modifiers private const)) + (val PREF_ENDPOINT : String + "endpoint" + (modifiers private const)) + (val PREF_STATE_SCHEMA_VERSION : String + "state_schema_version" + (modifiers private const)) + (val STATE_SCHEMA_VERSION : Int32 + (int32 2) + (modifiers private const)) + (val GAME_STATE_FILE : String + "current_game.json" + (modifiers private const)) + (var clientCrashLoggerInstalled : Bool + #f + (modifiers @Volatile private)) + (val PAIR_MARKER : String + (string-append "$" "pair") + (modifiers private)) + (val PA_PANEL_BOX_CODE : String + "52" + (modifiers private const)) + (val STATUS_TEXT_SP : Float32 + (float32 18.0) + (modifiers private const)) + (val OUTPUT_TEXT_SP : Float32 + (float32 17.0) + (modifiers private const)) + (val LABEL_TEXT_SP : Float32 + (float32 18.0) + (modifiers private const)) + (val CONTROL_TEXT_SP : Float32 + (float32 20.0) + (modifiers private const)) + (val BUTTON_TEXT_SP : Float32 + (float32 16.0) + (modifiers private const)) + (val SPINNER_TEXT_SP : Float32 + (float32 19.0) + (modifiers private const)) + (val FIRE_GROUP_ALL : Int32 + (int32 1) + (modifiers private const)) + (val FIRE_GROUP_HEAVY : Int32 + (int32 2) + (modifiers private const)) + (val FIRE_GROUP_PHASER : Int32 + (int32 3) + (modifiers private const)) + (val AUTO_QUIET_STEP_DELAY_MS : Int + (int 70) + (modifiers private const)) + (val AUTO_MOVEMENT_STEP_DELAY_MS : Int + (int 320) + (modifiers private const)) + (val AUTO_ACTION_EVENT_DELAY_MS : Int + (int 430) + (modifiers private const)) + (val AUTO_COMBAT_EVENT_DELAY_MS : Int + (int 650) + (modifiers private const)) + (val AUTO_UI_RENDER_INTERVAL_MS : Int + (int 450) + (modifiers private const)) + (val SERVICE_READ_TIMEOUT_MS : Int32 + (int32 30000) + (modifiers private const)) + (val AUTO_BATTLE_READ_TIMEOUT_MS : Int32 + (int32 30000) + (modifiers private const)) + (val CLIENT_LOG_READ_TIMEOUT_MS : Int32 + (int32 1500) + (modifiers private const)) + (val CLIENT_LOG_CRASH_TIMEOUT_MS : Int32 + (int32 1500) + (modifiers private const)) + (val CLIENT_LOG_JSON_CHARS : Int32 + (int32 6000) + (modifiers private const)) + (val CLIENT_LOG_STACK_CHARS : Int32 + (int32 12000) + (modifiers private const)) + (val AUTO_GAME_EVENT_LIMIT : Int32 + (int32 32) + (modifiers private const)) + (val STATE_SAVE_DEBOUNCE_MS : Int + (int 500) + (modifiers private const)) + (val DASHBOARD_QUERY_MIN_INTERVAL_MS : Int + (int 350) + (modifiers private const)) + (val STATUS_QUERY_MIN_INTERVAL_MS : Int + (int 350) + (modifiers private const)) + (val ACTION_QUERY_MIN_INTERVAL_MS : Int + (int 500) + (modifiers private const)) + (val HUD_ACTION_PRIORITY : (List String) + (list-of String + "direct-fire" + "seeking-launch" + "shuttle-operations" + "wild-weasel-preparation" + "suicide-shuttle" + "scatter-pack" + "carrier-fighter-operations" + "pf-operations" + "tractors" + "transporters" + "shield-control" + "continuous-damage-repair" + "emergency-damage-repair" + "electronic-warfare" + "automated-battle") + (modifiers private)) + (val MANEUVERS : (List String) + (list-of String + "none" "left" "right" + "sideslip-left" "sideslip-right" "het") + (modifiers private)) + (val DEFAULT_SEEKING_KINDS : (List String) + (list-of String + "none" + "drone" + "drone-i-slow" + "drone-iv-slow" + "plasma" + "plasma-f" + "plasma-g" + "plasma-s" + "plasma-r" + "plasma-d") + (modifiers private)) + (def (autoEventDelayMillis (type : String)) : Int + (if (or (equal? type "fire-weapons") + (or (equal? type "direct-fire") + (or (equal? type "seeking-impact") + (or (equal? type "suicide-shuttle-impact") + (or (equal? type "ship-destroyed") + (or (equal? type "game-over") + (equal? type "victory"))))))) + AUTO_COMBAT_EVENT_DELAY_MS + (if (or (equal? type "seeking-launch") + (or (equal? type "defensive-fire") + (or (equal? type "damage-applied") + (or (equal? type "ew-control") + (or (equal? type "ew-support") + (or (equal? type "ew-support-rejected") + (or (equal? type "ew-support-lost") + (or (equal? type "lock-on-control") + (or (equal? type "shield-control") + (or (equal? type "energy-allocation") + (or (equal? type "web-created") + (or (equal? type "web-reduced") + (or (equal? type "web-caster") + (or (equal? type "web-snare") + (or (equal? type "web-breaker") + (or (equal? type "wild-weasel-preparation") + (or (equal? type "scatter-pack") + (or (equal? type "suicide-shuttle") + (or (equal? type "turn-blocked") + (equal? type "maneuver-blocked")))))))))))))))))))) + AUTO_ACTION_EVENT_DELAY_MS + (if (or (equal? type "movement") + (or (equal? type "turn") + (or (equal? type "sideslip") + (or (equal? type "high-energy-turn") + (or (equal? type "shuttle-movement") + (equal? type "seeking-movement")))))) + AUTO_MOVEMENT_STEP_DELAY_MS + AUTO_QUIET_STEP_DELAY_MS)))) + (def (isPhaserWeapon (weapon : String)) : Bool + (string-starts-with? weapon "phaser")) + (def (weaponSortBucket (weapon : String)) : Int32 + (if (isPhaserWeapon weapon) + (int32 2) + (if (or (string-contains? weapon "drone") + (string-contains? weapon "plasma")) + (int32 1) + (int32 0)))) + (def (actorLabel (actor : String)) : String + (if (equal? actor "alpha") "Alpha" "Beta")) + (def (fireGroupName (group : Int32)) : String + (if (= group FIRE_GROUP_HEAVY) + "heavy" + (if (= group FIRE_GROUP_PHASER) "phaser" "all"))) + (def (hudActionLabel (id : String)) : String + (if (equal? id "direct-fire") + "fire" + (if (equal? id "seeking-launch") + "seek" + (if (equal? id "shuttle-operations") + "units" + (if (equal? id "wild-weasel-preparation") + "ww" + (if (equal? id "suicide-shuttle") + "suicide" + (if (equal? id "scatter-pack") + "scatter" + (if (equal? id "carrier-fighter-operations") + "ftr" + (if (equal? id "pf-operations") + "pf" + (if (equal? id "tractors") + "tractor" + (if (equal? id "transporters") + "tran" + (if (equal? id "shield-control") + "shield" + (if (equal? id "continuous-damage-repair") + "repair" + (if (equal? id "emergency-damage-repair") + "emerg" + (if (equal? id "electronic-warfare") + "ew" + (if (equal? id "automated-battle") + "auto" + (mainActivityStringReplace id "-" " "))))))))))))))))) + (def (seekingSortBucket (kind : String)) : Int32 + (if (string-starts-with? kind "drone") + (int32 0) + (if (equal? kind "plasma") + (int32 1) + (if (string-starts-with? kind "plasma") + (int32 2) + (int32 3))))) + (def (shortDefenseKind (kind : String)) : String + (if (equal? kind "pa-panels") "pa" "sh")) + (def (truncateForLog (text : String) (limit : Int32)) : String + (if (<= (string-length-int32 text) limit) + text + (string-append + (string-take text limit) + (string-append + "...[truncated " + (string-append + (int32->string (- (string-length-int32 text) limit)) + " chars]"))))) + (def (isInterestingEvent (event : JSONObject)) : Bool + (let ((type + (mainActivityEventType event "type" ""))) + (and (not (string-blank? type)) + (not (equal? type "impulse-activity")))))))))