Store screenshots now render at real phone and tablet density (--screenshot-ui-scale), show the painted Wim Hof, Sun Salutation and Meditation cards, an Upward salute pose and showcase habits instead of test fixtures. Descriptions in all five store locales name the actual practices, patterns and habit features. TODO.md tracks the marketing plan.
141 lines
4.1 KiB
Ziran
141 lines
4.1 KiB
Ziran
#import "c_string"
|
|
|
|
SCREENSHOT_THEME_CURRENT :: -1
|
|
|
|
ScreenshotRequest :: struct {
|
|
active: s32
|
|
valid: bool
|
|
width: s32
|
|
height: s32
|
|
theme_id: s32
|
|
dark_mode: s32
|
|
// The app's ui_scale setting in tenths, or 0 to keep the saved scale.
|
|
ui_scale_tenths: s32
|
|
scene: [64]u8
|
|
output: [512]u8
|
|
}
|
|
|
|
ScreenshotParseInt :: (text: string, fallback: s32) -> s32 {
|
|
index: s32 = 0
|
|
while index < cast(s32)text.count && (text[index] == cast(u8)32 || text[index] == cast(u8)9) {
|
|
index += 1
|
|
}
|
|
negative := false
|
|
if index < cast(s32)text.count && text[index] == cast(u8)45 {
|
|
negative = true
|
|
index += 1
|
|
} else if index < cast(s32)text.count && text[index] == cast(u8)43 {
|
|
index += 1
|
|
}
|
|
start := index
|
|
limit: s64 = ifx negative then 2147483648 else 2147483647
|
|
value: s64 = 0
|
|
while index < cast(s32)text.count {
|
|
digit: u8 = text[index]
|
|
if digit < cast(u8)48 || digit > cast(u8)57 {
|
|
break
|
|
}
|
|
value = value * 10 + cast(s64)(digit - cast(u8)48)
|
|
if value > limit {
|
|
return fallback
|
|
}
|
|
index += 1
|
|
}
|
|
if index == start {
|
|
return fallback
|
|
}
|
|
if negative {
|
|
return cast(s32)(-value)
|
|
}
|
|
return cast(s32)value
|
|
}
|
|
|
|
ScreenshotSceneEquals :: (scene: []u8, expected: string) -> bool {
|
|
if scene.count == 0 || expected.count >= scene.count {
|
|
return false
|
|
}
|
|
index: s32 = 0
|
|
while index < cast(s32)expected.count {
|
|
if scene[index] != expected[index] {
|
|
return false
|
|
}
|
|
index += 1
|
|
}
|
|
return scene[index] == 0
|
|
}
|
|
|
|
#program_export
|
|
ScreenshotParse :: (args: []string, width: s32, height: s32,
|
|
theme_count: s32, enabled: bool) -> ScreenshotRequest {
|
|
request: ScreenshotRequest
|
|
if !enabled {
|
|
return request
|
|
}
|
|
request.valid = true
|
|
request.width = width
|
|
request.height = height
|
|
request.theme_id = SCREENSHOT_THEME_CURRENT
|
|
index: s32 = 1
|
|
while index < cast(s32)args.count {
|
|
option := args[index]
|
|
if index + 1 >= cast(s32)args.count {
|
|
break
|
|
}
|
|
value := args[index + 1]
|
|
consumed := true
|
|
if option == "--screenshot" {
|
|
request.active = 1
|
|
if !CopyCString(value, request.output[:]) {
|
|
request.valid = false
|
|
}
|
|
} else if option == "--screenshot-scene" {
|
|
if !CopyCString(value, request.scene[:]) {
|
|
request.valid = false
|
|
}
|
|
} else if option == "--screenshot-width" {
|
|
request.width = ScreenshotParseInt(value, request.width)
|
|
} else if option == "--screenshot-height" {
|
|
request.height = ScreenshotParseInt(value, request.height)
|
|
} else if option == "--screenshot-theme" {
|
|
request.theme_id = ScreenshotParseInt(value, request.theme_id)
|
|
} else if option == "--screenshot-dark" {
|
|
request.dark_mode = ifx ScreenshotParseInt(value, 0) != 0 then 1 else 0
|
|
} else if option == "--screenshot-ui-scale" {
|
|
request.ui_scale_tenths = ScreenshotParseInt(value, 0)
|
|
} else {
|
|
consumed = false
|
|
}
|
|
index += ifx consumed then 2 else 1
|
|
}
|
|
if request.scene[0] == 0 {
|
|
if !CopyCString("home", request.scene[:]) {
|
|
request.valid = false
|
|
}
|
|
}
|
|
if request.active != 0 && request.output[0] == 0 {
|
|
request.valid = false
|
|
}
|
|
if request.width < 320 {
|
|
request.width = 320
|
|
}
|
|
if request.height < 320 {
|
|
request.height = 320
|
|
}
|
|
// Same range as the ui_scale setting; anything else keeps the saved scale.
|
|
if request.ui_scale_tenths < 5 || request.ui_scale_tenths > 25 {
|
|
request.ui_scale_tenths = 0
|
|
}
|
|
if request.theme_id < SCREENSHOT_THEME_CURRENT || request.theme_id >= theme_count {
|
|
request.theme_id = SCREENSHOT_THEME_CURRENT
|
|
}
|
|
return request
|
|
}
|
|
|
|
#program_export
|
|
ScreenshotWarmupFrames :: (request: ScreenshotRequest) -> s32 {
|
|
if ScreenshotSceneEquals(request.scene[:], "tutorial_whm_step2") {
|
|
return 150
|
|
}
|
|
return 4
|
|
}
|