Finish typed ShipStatusView conversion
ober
a9642fadb6e54751c8ac57fa26908a441c6ea1f7
--- a/templates/original-tactics-parts/ShipStatusView.ss +++ b/templates/original-tactics-parts/ShipStatusView.ss @@ -6,9 +6,10 @@ (android graphics Canvas) (android graphics Color) (android graphics Paint) + (android graphics Paint Align) + (android graphics Paint Style) (android graphics RectF) (android view View) - (java util Iterator) (org json JSONArray) (org json JSONObject)) (typed-library (com jerboa originaltactics) @@ -20,30 +21,29 @@ (type Float32) (type Float64) (type Int32) - (type Iterator) (type JSONArray) (type JSONObject) (type Paint) - (type PaintAlign) - (type PaintStyle) + (type Align) + (type Style) (type RectF) (type Resources) (type View) (extern (paintAntiAliasFlag) : Int32 (kotlin-value Paint ANTI_ALIAS_FLAG)) - (extern (paintStyleFill) : PaintStyle + (extern (paintStyleFill) : Style (kotlin-value Paint Style FILL)) - (extern (paintStyleStroke) : PaintStyle + (extern (paintStyleStroke) : Style (kotlin-value Paint Style STROKE)) - (extern (paintAlignLeft) : PaintAlign + (extern (paintAlignLeft) : Align (kotlin-value Paint Align LEFT)) - (extern (paintAlignRight) : PaintAlign + (extern (paintAlignRight) : Align (kotlin-value Paint Align RIGHT)) - (extern (paintAlignCenter) : PaintAlign + (extern (paintAlignCenter) : Align (kotlin-value Paint Align CENTER)) (extern (paintColorSet (paint : Paint) (color : Int32)) : Unit (kotlin-member-set color)) - (extern (paintStyleSet (paint : Paint) (style : PaintStyle)) : Unit + (extern (paintStyleSet (paint : Paint) (style : Style)) : Unit (kotlin-member-set style)) (extern (paintStrokeWidthSet (paint : Paint) @@ -59,7 +59,7 @@ (kotlin-member-set isFakeBoldText)) (extern (paintTextAlignSet (paint : Paint) - (align : PaintAlign)) : Unit + (align : Align)) : Unit (kotlin-member-set textAlign)) (extern (colorRgb (red : Int32) @@ -179,10 +179,16 @@ (index : Int32)) : (Nullable JSONObject) (kotlin-member-call optJSONObject)) (extern (anyString (value : (Nullable Any))) : String - (kotlin-call String valueOf)) + (kotlin-call java lang String valueOf)) (extern (sortedStrings (values : (MutableList String))) : (List String) (kotlin-member-call sorted)) + (extern (stringListSize (values : (List String))) : Int32 + (kotlin-member-get size)) + (extern (stringListGet + (values : (List String)) + (index : Int32)) : String + (kotlin-member-call get)) (extern (statusFloatToInt (value : Float32)) : Int32 (kotlin-member-call toInt)) (extern (shipDisplay @@ -196,7 +202,7 @@ (def (configureStatusPaint (paint : Paint) (color : Int32) - (style : PaintStyle) + (style : Style) (strokeWidth : Float32) (textSize : Float32) (bold : Bool)) : Paint @@ -441,28 +447,18 @@ paMax) (+ shieldTop (float32 36.0)))) (begin - (for ((i (in-range (int32 0) (int32 6)))) - (let ((value - (nullableJsonFloat - shields - (string-append - "shield-" - (int32->string (+ i (int32 1)))) - (float32 0.0)))) - (drawShieldBar - canvas - (+ (rectLeft rect) (float32 10.0)) - (+ shieldTop - (* (float32 i) (float32 18.0))) - (- (rectWidth rect) (float32 20.0)) - (+ i (int32 1)) - value - (nullableJsonFloat - maxShields - (string-append - "shield-" - (int32->string (+ i (int32 1)))) - value))) + (drawShieldAt + canvas rect shieldTop shields maxShields (int32 0)) + (drawShieldAt + canvas rect shieldTop shields maxShields (int32 1)) + (drawShieldAt + canvas rect shieldTop shields maxShields (int32 2)) + (drawShieldAt + canvas rect shieldTop shields maxShields (int32 3)) + (drawShieldAt + canvas rect shieldTop shields maxShields (int32 4)) + (drawShieldAt + canvas rect shieldTop shields maxShields (int32 5)) (+ shieldTop (float32 120.0)))))) (begin (drawObjectLine @@ -482,7 +478,30 @@ (int32 4) (floatMin (- (rectBottom rect) (float32 10.0)) - (+ infoTop (float32 44.0)))))))))))) + (+ infoTop (float32 44.0)))))))))) + (def (drawShieldAt + (canvas : Canvas) + (rect : RectF) + (shieldTop : Float32) + (shields : (Nullable JSONObject)) + (maxShields : (Nullable JSONObject)) + (index : Int32)) : Unit + (modifiers private) + (let ((key + (string-append + "shield-" + (int32->string (+ index (int32 1)))))) + (let ((value + (nullableJsonFloat + shields key (float32 0.0)))) + (drawShieldBar + canvas + (+ (rectLeft rect) (float32 10.0)) + (+ shieldTop (* (float32 index) (float32 18.0))) + (- (rectWidth rect) (float32 20.0)) + (+ index (int32 1)) + value + (nullableJsonFloat maxShields key value))))) (def (drawObjectLine (canvas : Canvas) (rect : RectF) @@ -638,38 +657,46 @@ (count (intMax (int32 1) limit))) (let ((actual - (if (< (list-size sorted) count) - (list-size sorted) + (if (< (stringListSize sorted) count) + (stringListSize sorted) count))) - (for/fold ((text "")) - ((index (in-range actual))) - (let ((key (list-ref sorted index))) - (string-append - text - (string-append - (if (= index (int32 0)) "" " ") - (string-append - key - (string-append - "=" - (anyString (jsonOpt json key))))))))))))))) + (var ((text "") + (index (int32 0))) + (begin + (while (< index actual) + (let ((key (stringListGet sorted index))) + (begin + (set! text + (string-append + text + (string-append + (if (= index (int32 0)) "" " ") + (string-append + key + (string-append + "=" + (anyString (jsonOpt json key))))))) + (set! index (+ index (int32 1)))))) + text)))))))))) (def (objectTotal (obj : (Nullable JSONObject))) : Int32 (modifiers private) (if (nullable-null? obj) (int32 0) - (let ((json (nullable-get obj)) - (total (int32 0))) + (let ((json (nullable-get obj))) (let ((keys (jsonKeys json))) - (begin + (var ((total (int32 0))) + (begin (while (iteratorHasNext keys) (set! total (+ total (intMax (int32 0) (jsonOptInt - json (iteratorNext keys) (int32 0)))))) - total))))) + json + (iteratorNext keys) + (int32 0)))))) + total)))))) (def (nullableJsonFloat (obj : (Nullable JSONObject)) (key : String) @@ -700,12 +727,18 @@ (if (nullable-null? arrayValue) (int32 0) (let ((array (nullable-get arrayValue))) - (for/fold ((total (int32 0))) - ((index (in-range (arrayLength array)))) - (+ total - (counterPairValue - (arrayObject array index) - wantedKey)))))) + (var ((total (int32 0)) + (index (int32 0))) + (begin + (while (< index (arrayLength array)) + (begin + (set! total + (+ total + (counterPairValue + (arrayObject array index) + wantedKey))) + (set! index (+ index (int32 1))))) + total))))) (let ((json (nullable-get objectValue))) (let ((pair (jsonArrayChild json PAIR_MARKER))) (if (nullable-null? pair)