350 lines
13 KiB
Ziran
350 lines
13 KiB
Ziran
#import, file "../../src/platform/host_clock.zi";
|
|
#import, file "recovery.zi";
|
|
#import, file "../../src/apps/practice_ui_types.zi";
|
|
#import, file "../../src/apps/practice_types.zi";
|
|
#import, file "../../src/practices/practice_movement_host.zi";
|
|
// The 7-Minute Workout owns its circuit, figure and session; the host
|
|
// supplies the existing audio, storage and platform lifecycle effects.
|
|
#import, file "workout_rules.zi";
|
|
#import, file "workout_moves.zi";
|
|
#import, file "../../src/app/app_types.zi";
|
|
#import, file "../../src/app/app_modal_state.zi";
|
|
#import, file "../../src/app/app_nav_state.zi";
|
|
#import, file "../../src/app/app_route_state.zi";
|
|
#import, file "../../src/app/activity_start.zi";
|
|
#import, file "../../src/app/assets.zi";
|
|
#import, file "../../src/app/cards.zi";
|
|
#import, file "../../src/app/color.zi";
|
|
#import, file "../../src/app/exercise_types.zi";
|
|
#import, file "../../src/app/locale.zi";
|
|
#import, file "../../src/app/manual_seen_actions.zi";
|
|
#import, file "../../src/app/metrics.zi";
|
|
#import, file "../../src/app/modal_rules.zi";
|
|
#import, file "../../src/app/practice_title_bar.zi";
|
|
#import, file "../../src/app/session_screen.zi";
|
|
#import, file "../../src/app/text_buffers.zi";
|
|
#import, file "../../src/app/app_notifications.zi";
|
|
#import, file "../../src/core/types.zi";
|
|
#import, file "../../src/practices/meditation/meditation_music.zi";
|
|
#import, file "../../src/practices/practice_audio_controls.zi";
|
|
#import, file "../../src/practices/practice_downloads.zi";
|
|
#import, file "../../src/practices/practice_narration.zi";
|
|
#import, file "../../src/practices/session_results.zi";
|
|
#import, file "../../src/practices/tai_chi/tai_chi_math.zi";
|
|
#import, file "../../src/practices/tai_chi/tai_chi_solve.zi";
|
|
#import, file "../../src/practices/tai_chi/tai_chi_flat.zi";
|
|
#import, file "../../src/practices/tai_chi/tai_chi_rules.zi";
|
|
#import, file "../../src/practices/tai_chi/tai_chi_draw.zi";
|
|
#import, file "../../src/storage/data.zi";
|
|
#import "locale_parser"
|
|
#import "locale_policy"
|
|
#import "byte_text_linux"
|
|
#import "text_buffer"
|
|
Layout :: #import "kryon/layout";
|
|
Text :: #import "kryon/text";
|
|
#import "session"
|
|
#import "control_props"
|
|
#import "drawing_props"
|
|
#import "geometry"
|
|
#import "text_align"
|
|
#import "kryon/tree"
|
|
|
|
c :: #system_library "c";
|
|
practice_background_start :: (app: *InnerBreeze, id: s32) #foreign c;
|
|
practice_active_background_stop :: (app: *InnerBreeze) #foreign c;
|
|
app_auto_sync :: (app: *InnerBreeze) -> s32 #foreign c;
|
|
sync_habits_for_activity :: (app: *InnerBreeze, activity: s32) #foreign c;
|
|
app_play_bell_cue :: (app: *InnerBreeze, volume: float32) #foreign c;
|
|
app_draw_session_exit_modal :: (app: *InnerBreeze, can_save: s32,
|
|
save_message: string, discard_message: string) -> SessionExitModalResult #foreign c;
|
|
|
|
using AppThemeMode;
|
|
using ExerciseType;
|
|
using ModalType;
|
|
using SessionExitModalResult;
|
|
using TextAlign;
|
|
using Text.Wrap;
|
|
using ButtonTone;
|
|
using ButtonEmphasis;
|
|
|
|
WORKOUT_EDGE_PATH :: "assets/practices/workout/flat-edge.png"
|
|
|
|
workout_elapsed_ms: s64;
|
|
workout_frame_carry: float64;
|
|
workout_exit_was_paused: s32;
|
|
// The phase and exercise last seen, so each change rings once.
|
|
workout_last_phase: s32 = -1;
|
|
workout_last_exercise: s32 = -1;
|
|
workout_figure: TaiChiFlatFrame;
|
|
workout_props: TaiChiFlatFrame;
|
|
|
|
WorkoutActive :: (app: *InnerBreeze) -> s32 {
|
|
return ifx app != null && app_session_screen(app) == ScreenWorkout then 1 else 0
|
|
}
|
|
|
|
WorkoutStart :: (app: *InnerBreeze) {
|
|
if app == null || !ActivityStartAllowed() {
|
|
return
|
|
}
|
|
mark_exercise_manual_seen(app, EXERCISE_WORKOUT)
|
|
workout_elapsed_ms = 0
|
|
workout_frame_carry = 0.0
|
|
workout_last_phase = WORKOUT_PHASE_PREPARE
|
|
workout_last_exercise = 0
|
|
app.session_paused = 0
|
|
PracticeNarrationStop()
|
|
app_close_modal(app)
|
|
PracticeDraftBegin(EXERCISE_WORKOUT)
|
|
app_switch_screen(app, ScreenWorkout)
|
|
meditation_music_start_session(app)
|
|
practice_background_start(app, EXERCISE_WORKOUT)
|
|
}
|
|
|
|
WorkoutElapsedSeconds :: () -> s32 {
|
|
return cast(s32)(workout_elapsed_ms / 1000)
|
|
}
|
|
|
|
WorkoutDuration :: () -> s32 {
|
|
return WORKOUT_TOTAL_MS / 1000
|
|
}
|
|
|
|
WorkoutRemaining :: () -> s32 {
|
|
return WorkoutDuration() - WorkoutElapsedSeconds()
|
|
}
|
|
|
|
WorkoutSave :: (app: *InnerBreeze, output: *u8, capacity: s64) {
|
|
seconds := WorkoutElapsedSeconds()
|
|
if seconds >= 60 && data_save_session_path_for_activity(*seconds, 1, 0,
|
|
EXERCISE_WORKOUT, output, capacity) != 0 {
|
|
sync_habits_for_activity(app, EXERCISE_WORKOUT)
|
|
unused app_auto_sync(app)
|
|
}
|
|
}
|
|
|
|
WorkoutStop :: (app: *InnerBreeze) {
|
|
PracticeDraftEnd()
|
|
PracticeNarrationStop()
|
|
meditation_music_stop(app)
|
|
practice_active_background_stop(app)
|
|
app.session_paused = 0
|
|
app.volume_popup_active = 0
|
|
app.music_volume_popup_active = 0
|
|
app_close_modal(app)
|
|
}
|
|
|
|
WorkoutEnd :: (app: *InnerBreeze) {
|
|
WorkoutSave(app, null, 0)
|
|
WorkoutStop(app)
|
|
app_switch_screen(app, ScreenStart)
|
|
}
|
|
|
|
WorkoutFinish :: (app: *InnerBreeze) {
|
|
result_path: [FS_PATH_MAX]u8
|
|
result_path[0] = cast(u8)0
|
|
WorkoutSave(app, *result_path[0], size_of(type_of(result_path)))
|
|
send_session_complete(app)
|
|
WorkoutStop(app)
|
|
app_prepare_session_results(app, EXERCISE_WORKOUT,
|
|
WorkoutElapsedSeconds(), 0, null, null, 0, *result_path[0])
|
|
app_switch_screen(app, ScreenResults)
|
|
}
|
|
|
|
// A bell starts each exercise, and a softer one ends it.
|
|
WorkoutRing :: (app: *InnerBreeze, step: WorkoutStep) {
|
|
if step.phase == workout_last_phase && step.exercise == workout_last_exercise {
|
|
return
|
|
}
|
|
if step.phase == WORKOUT_PHASE_WORK {
|
|
app_play_bell_cue(app, 1.0)
|
|
} else if workout_last_phase == WORKOUT_PHASE_WORK {
|
|
app_play_bell_cue(app, 0.6)
|
|
}
|
|
workout_last_phase = step.phase
|
|
workout_last_exercise = step.exercise
|
|
}
|
|
|
|
WorkoutAdvanceElapsed :: (app: *InnerBreeze, milliseconds: s32) {
|
|
if WorkoutActive(app) == 0 {
|
|
return
|
|
}
|
|
workout_elapsed_ms = WorkoutAdvance(workout_elapsed_ms, milliseconds, app.session_paused != 0)
|
|
step := WorkoutStepAt(workout_elapsed_ms)
|
|
WorkoutRing(app, step)
|
|
PracticeDraftElapsed(EXERCISE_WORKOUT, WorkoutElapsedSeconds(), step.exercise, false)
|
|
if step.phase == WORKOUT_PHASE_DONE {
|
|
WorkoutFinish(app)
|
|
}
|
|
}
|
|
|
|
WorkoutUpdate :: (app: *InnerBreeze) {
|
|
if WorkoutActive(app) == 0 {
|
|
return
|
|
}
|
|
meditation_music_update(app)
|
|
key: [64]u8
|
|
PracticeNarrationUpdate(app, "workout", WorkoutCueKey(WorkoutStepAt(workout_elapsed_ms), key[:]))
|
|
}
|
|
|
|
WorkoutRequestExit :: (app: *InnerBreeze) {
|
|
workout_exit_was_paused = app.session_paused
|
|
app.session_paused = 1
|
|
PracticeDraftElapsed(EXERCISE_WORKOUT, WorkoutElapsedSeconds(), 0, true)
|
|
app_open_modal(app, cast(ModalType)ModalConfirmExitSession)
|
|
}
|
|
|
|
WorkoutExitPrompt :: (app: *InnerBreeze) -> s32 {
|
|
if app.modal.active == 0 || app.modal.type != cast(ModalType)ModalConfirmExitSession {
|
|
return 0
|
|
}
|
|
result := app_draw_session_exit_modal(app, ifx WorkoutElapsedSeconds() >= 60 then 1 else 0,
|
|
LocaleText("meditation_save_elapsed_message"), LocaleText("meditation_under_minute_exit_message"))
|
|
if result == cast(SessionExitModalResult)SessionExitModalCancel {
|
|
app_close_modal(app)
|
|
app.session_paused = workout_exit_was_paused
|
|
} else if result == cast(SessionExitModalResult)SessionExitModalSave ||
|
|
result == cast(SessionExitModalResult)SessionExitModalDiscard {
|
|
if result == cast(SessionExitModalResult)SessionExitModalSave {
|
|
WorkoutSave(app, null, 0)
|
|
}
|
|
WorkoutStop(app)
|
|
app_switch_screen(app, ScreenStart)
|
|
return 2
|
|
}
|
|
return 1
|
|
}
|
|
|
|
// --- Words -----------------------------------------------------------------------
|
|
|
|
WorkoutTextAsset :: (code: string) -> AssetView {
|
|
path: [128]u8
|
|
if !AppCopyText("assets/practices/workout/text/", path[:]) ||
|
|
!AppAppendText(code, path[:]) || !AppAppendText(".txt", path[:]) {
|
|
return AssetView.{}
|
|
}
|
|
return AssetRead(TextUntilNul(path[:]))
|
|
}
|
|
|
|
// A line of the workout's own words, in the app's language when it has it.
|
|
WorkoutText :: (app: *InnerBreeze, key: string) -> string {
|
|
localized := WorkoutTextAsset(LocaleActiveCode())
|
|
english := WorkoutTextAsset("en")
|
|
return FrameTextHold(*app.ui.frame_text, LocaleResolveCatalog(localized.data, english.data, key))
|
|
}
|
|
|
|
WorkoutExerciseText :: (app: *InnerBreeze, prefix: string, exercise: s32) -> string {
|
|
key: [64]u8
|
|
return WorkoutText(app, WorkoutKeyFor(prefix, exercise, key[:]))
|
|
}
|
|
|
|
// The exercise being done, or the one to get into position for.
|
|
WorkoutHeading :: (app: *InnerBreeze, step: WorkoutStep) -> string {
|
|
return WorkoutExerciseText(app, "workout_name_", step.exercise)
|
|
}
|
|
|
|
// "Get into position" while waiting, "Exercise 2 of 12" while working.
|
|
WorkoutSubheading :: (app: *InnerBreeze, step: WorkoutStep) -> string {
|
|
if step.phase != WORKOUT_PHASE_WORK {
|
|
return LocaleText("workout_get_into_position")
|
|
}
|
|
buffer: [160]u8
|
|
args: [2]FormatArg = .[FormatArg.{.number = step.exercise + 1}, FormatArg.{.number = WORKOUT_EXERCISE_COUNT}]
|
|
unused FormatTemplate(LocaleText("workout_exercise_number"), args[:], buffer[:])
|
|
return FrameTextHold(*app.ui.frame_text, TextUntilNul(buffer[:]))
|
|
}
|
|
|
|
// How to do the exercise shown, or "Switch sides" halfway through the side
|
|
// plank.
|
|
WorkoutTip :: (app: *InnerBreeze, step: WorkoutStep) -> string {
|
|
if step.phase == WORKOUT_PHASE_WORK && step.exercise == WORKOUT_SIDE_PLANK &&
|
|
step.elapsed_ms >= WORKOUT_SIDE_SWITCH_MS && step.elapsed_ms < WORKOUT_SIDE_SWITCH_MS + 3000 {
|
|
return LocaleText("workout_switch_sides")
|
|
}
|
|
return WorkoutExerciseText(app, "workout_tip_", step.exercise)
|
|
}
|
|
|
|
// --- Drawing ---------------------------------------------------------------------
|
|
|
|
WorkoutDark :: (app: *InnerBreeze) -> bool {
|
|
return app.theme_mode == APP_THEME_DARK || (app.theme_mode != APP_THEME_LIGHT && app.dark_mode != 0)
|
|
}
|
|
|
|
// The figure doing the step's exercise, or waiting in the next one's first
|
|
// pose while getting ready or resting.
|
|
WorkoutDrawFigure :: (app: *InnerBreeze, step: WorkoutStep, area: Rectangle, key: u64, alt_text: string) {
|
|
if area.width <= 0.0 || area.height <= 0.0 {
|
|
return
|
|
}
|
|
rig := WorkoutRig()
|
|
pose: WorkoutPose
|
|
if step.phase == WORKOUT_PHASE_WORK {
|
|
pose = WorkoutPoseAt(step.exercise, cast(s64)step.elapsed_ms, *rig)
|
|
} else {
|
|
pose = WorkoutRestPose(step.exercise, workout_elapsed_ms, *rig)
|
|
}
|
|
solved := WorkoutSolve(*pose, *rig)
|
|
framing := WorkoutFramingFor(step.exercise)
|
|
// A wide area shows the same height; a narrow one widens the view so
|
|
// that lying exercises still fit.
|
|
across := framing.view_height * cast(float64)area.width / cast(float64)area.height
|
|
if across < 2.2 {
|
|
framing.view_height = framing.view_height * 2.2 / across
|
|
}
|
|
WorkoutPaintProps(*workout_props, step.exercise, framing.camera, WorkoutDark(app))
|
|
TaiChiPaintFlatEdge(app.ui.session, *workout_props, framing, false, area, key, "", WORKOUT_EDGE_PATH)
|
|
TaiChiFlatPaintLook(*workout_figure, *solved, *rig, TaiChiFlatLookNamed("jadeWoman"), framing.camera)
|
|
TaiChiPaintFlatEdge(app.ui.session, *workout_figure, framing, false, area, key + cast(u64)4096,
|
|
alt_text, WORKOUT_EDGE_PATH)
|
|
}
|
|
|
|
WorkoutDrawWindow :: (app: *InnerBreeze, picture: Rectangle, output: []u8) -> string {
|
|
step := WorkoutStepAt(workout_elapsed_ms)
|
|
WorkoutDrawFigure(app, step, picture, Layout.KeyHash("workout/window/figure"), "")
|
|
cursor: s32 = 0
|
|
output[0] = cast(u8)0
|
|
heading := WorkoutHeading(app, step)
|
|
for byte: heading {
|
|
unused TextBufferAppendByte(output, *cursor, byte)
|
|
}
|
|
unused TextBufferAppendByte(output, *cursor, cast(u8)32)
|
|
unused TextBufferAppendNumber(output, *cursor, WorkoutStepSecondsLeft(step))
|
|
return TextUntilNul(output)
|
|
}
|
|
|
|
WorkoutSessionFigure :: (app: *InnerBreeze, request: PracticeFigureRequest) {
|
|
WorkoutDrawFigure(app, WorkoutStepAt(workout_elapsed_ms), request.bounds, request.key, request.alt_text)
|
|
}
|
|
|
|
WorkoutDraw :: (app: *InnerBreeze, center_x: s32, center_y: s32) {
|
|
top := PracticeTitleBarHeight()
|
|
if PracticeTitleBar(app, LocaleText("exercise_workout"), top) {
|
|
WorkoutRequestExit(app)
|
|
}
|
|
if WorkoutExitPrompt(app) != 0 {
|
|
return
|
|
}
|
|
practice_draw_audio_controls(app)
|
|
step := WorkoutStepAt(workout_elapsed_ms)
|
|
frame := PracticeMovementFrameFor(app, EXERCISE_WORKOUT, top)
|
|
frame.heading = WorkoutHeading(app, step)
|
|
frame.subtitle = WorkoutSubheading(app, step)
|
|
frame.cue = WorkoutTip(app, step)
|
|
frame.exercise = step.exercise
|
|
frame.phase = step.phase
|
|
frame.elapsed_ms = step.elapsed_ms
|
|
frame.length_ms = step.length_ms
|
|
frame.seconds_left = WorkoutStepSecondsLeft(step)
|
|
frame = PracticeMovementRun(app, frame, WorkoutSessionFigure)
|
|
if frame.action == PRACTICE_MOVEMENT_PAUSE {
|
|
app.session_paused = ifx app.session_paused != 0 then 0 else 1
|
|
PracticeDraftElapsed(EXERCISE_WORKOUT, WorkoutElapsedSeconds(), 0, true)
|
|
}
|
|
if app.backgrounded == 0 {
|
|
total := cast(float64)HostFrameSeconds() * 1000.0 + workout_frame_carry
|
|
milliseconds := cast(s32)total
|
|
workout_frame_carry = total - cast(float64)milliseconds
|
|
WorkoutAdvanceElapsed(app, milliseconds)
|
|
}
|
|
unused center_x
|
|
unused center_y
|
|
}
|