Add an Easy habit level that earns half a coin a day

Medium stays one coin, so a five-coin reward is still five medium days.
The wallet counts half coins and shows a leftover half as ½. Easy is the
first choice in a habit's difficulty, and the shop explains it in every
language.
This commit is contained in:
waozi committed 2026-10-19 12:22:00 -03:00
1 parent 0d3a229ea9
commit 2f4d0d551d
27 files changed
+246 -73

No files matched your search

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+10 -2
View File
@@ -7257,6 +7257,10 @@ Patnáctiminutová vedená vizualizace s uvolněním, představou vznášení a
Obtížnost
---
[habit_difficulty_easy]
Snadný
---
[habit_difficulty_medium]
Střední
---
@@ -7269,6 +7273,10 @@ Těžký
Velmi těžký
---
[habit_difficulty_earns_easy]
Za každý den, kdy ho splníš, získáš ½ mince.
---
[habit_difficulty_earns_medium]
Za každý den, kdy ho splníš, získáš 1 minci.
---
@@ -7302,7 +7310,7 @@ k utracení
---
[habit_shop_rule]
Každý den, kdy splníš návyk, získáš mince: 1 za střední, 2 za těžký a 3 za velmi těžký. Obtížnost návyku nastavíš v jeho úpravách.
Každý den, kdy splníš návyk, získáš mince: ½ za snadný, 1 za střední, 2 za těžký a 3 za velmi těžký. Obtížnost návyku nastavíš v jeho úpravách.
---
[habit_shop_rewards_title]
@@ -7342,7 +7350,7 @@ Koupit tuto odměnu?
---
[habit_shop_buy_left]
Zbylé mince: %d
Zbylé mince: %s
---
[habits_guide_coins]
+10 -2
View File
@@ -7251,6 +7251,10 @@ Eine 15-minütige geführte Visualisierung mit Entspannung, vorgestelltem Schweb
Schwierigkeit
---
[habit_difficulty_easy]
Leicht
---
[habit_difficulty_medium]
Mittel
---
@@ -7263,6 +7267,10 @@ Schwer
Sehr schwer
---
[habit_difficulty_earns_easy]
Bringt ½ Münze an jedem Tag, an dem du sie erledigst.
---
[habit_difficulty_earns_medium]
Bringt 1 Münze an jedem Tag, an dem du sie erledigst.
---
@@ -7296,7 +7304,7 @@ Münzen zum Ausgeben
---
[habit_shop_rule]
Jeder Tag, an dem du eine Gewohnheit erledigst, bringt Münzen: 1 für mittel, 2 für schwer und 3 für sehr schwer. Die Schwierigkeit stellst du im Editor der Gewohnheit ein.
Jeder Tag, an dem du eine Gewohnheit erledigst, bringt Münzen: ½ für leicht, 1 für mittel, 2 für schwer und 3 für sehr schwer. Die Schwierigkeit stellst du im Editor der Gewohnheit ein.
---
[habit_shop_rewards_title]
@@ -7336,7 +7344,7 @@ Diese Belohnung kaufen?
---
[habit_shop_buy_left]
Danach übrige Münzen: %d
Danach übrige Münzen: %s
---
[habits_guide_coins]
+10 -2
View File
@@ -7275,6 +7275,10 @@ A 15-minute guided visualization with relaxation, imagined floating and a gentle
Difficulty
---
[habit_difficulty_easy]
Easy
---
[habit_difficulty_medium]
Medium
---
@@ -7287,6 +7291,10 @@ Hard
Very hard
---
[habit_difficulty_earns_easy]
Earns ½ coin each day you do it.
---
[habit_difficulty_earns_medium]
Earns 1 coin each day you do it.
---
@@ -7320,7 +7328,7 @@ coins to spend
---
[habit_shop_rule]
Each day you complete a habit earns coins: 1 for medium, 2 for hard and 3 for very hard. Set a habit's difficulty in its editor.
Each day you complete a habit earns coins: ½ for easy, 1 for medium, 2 for hard and 3 for very hard. Set a habit's difficulty in its editor.
---
[habit_shop_rewards_title]
@@ -7360,7 +7368,7 @@ Buy this reward?
---
[habit_shop_buy_left]
Coins left afterwards: %d
Coins left afterwards: %s
---
[habits_guide_coins]
+10 -2
View File
@@ -7251,6 +7251,10 @@ Una visualización guiada de 15 minutos con relajación, flotación imaginada y
Dificultad
---
[habit_difficulty_easy]
Fácil
---
[habit_difficulty_medium]
Media
---
@@ -7263,6 +7267,10 @@ Difícil
Muy difícil
---
[habit_difficulty_earns_easy]
Gana ½ moneda cada día que lo cumples.
---
[habit_difficulty_earns_medium]
Gana 1 moneda cada día que lo cumples.
---
@@ -7296,7 +7304,7 @@ monedas para gastar
---
[habit_shop_rule]
Cada día que cumples un hábito ganas monedas: 1 si es medio, 2 si es difícil y 3 si es muy difícil. Elige la dificultad de cada hábito en su editor.
Cada día que cumples un hábito ganas monedas: ½ si es fácil, 1 si es medio, 2 si es difícil y 3 si es muy difícil. Elige la dificultad de cada hábito en su editor.
---
[habit_shop_rewards_title]
@@ -7336,7 +7344,7 @@ Comprar
---
[habit_shop_buy_left]
Monedas que te quedarán: %d
Monedas que te quedarán: %s
---
[habits_guide_coins]
+10 -2
View File
@@ -7239,6 +7239,10 @@ Une visualisation guidée de 15 minutes avec détente, flottement imaginé et re
Difficulté
---
[habit_difficulty_easy]
Facile
---
[habit_difficulty_medium]
Moyenne
---
@@ -7251,6 +7255,10 @@ Difficile
Très difficile
---
[habit_difficulty_earns_easy]
Rapporte ½ pièce chaque jour où tu la fais.
---
[habit_difficulty_earns_medium]
Rapporte 1 pièce chaque jour où tu la fais.
---
@@ -7284,7 +7292,7 @@ pièces à dépenser
---
[habit_shop_rule]
Chaque jour où tu accomplis une habitude rapporte des pièces : 1 pour moyenne, 2 pour difficile et 3 pour très difficile. Règle la difficulté d'une habitude dans son éditeur.
Chaque jour où tu accomplis une habitude rapporte des pièces : ½ pour facile, 1 pour moyenne, 2 pour difficile et 3 pour très difficile. Règle la difficulté d'une habitude dans son éditeur.
---
[habit_shop_rewards_title]
@@ -7324,7 +7332,7 @@ Acheter cette récompense ?
---
[habit_shop_buy_left]
Pièces restantes ensuite : %d
Pièces restantes ensuite : %s
---
[habits_guide_coins]
+10 -2
View File
@@ -7240,6 +7240,10 @@ Visualisasi terpandu selama 15 menit dengan relaksasi, bayangan melayang, dan ke
Tingkat kesulitan
---
[habit_difficulty_easy]
Mudah
---
[habit_difficulty_medium]
Sedang
---
@@ -7252,6 +7256,10 @@ Sulit
Sangat sulit
---
[habit_difficulty_earns_easy]
Mendapat ½ koin setiap hari kamu melakukannya.
---
[habit_difficulty_earns_medium]
Mendapat 1 koin setiap hari kamu melakukannya.
---
@@ -7285,7 +7293,7 @@ koin untuk dibelanjakan
---
[habit_shop_rule]
Setiap hari kamu menyelesaikan kebiasaan, kamu mendapat koin: 1 untuk sedang, 2 untuk sulit, dan 3 untuk sangat sulit. Atur tingkat kesulitan kebiasaan di editornya.
Setiap hari kamu menyelesaikan kebiasaan, kamu mendapat koin: ½ untuk mudah, 1 untuk sedang, 2 untuk sulit, dan 3 untuk sangat sulit. Atur tingkat kesulitan kebiasaan di editornya.
---
[habit_shop_rewards_title]
@@ -7325,7 +7333,7 @@ Beli hadiah ini?
---
[habit_shop_buy_left]
Sisa koin setelahnya: %d
Sisa koin setelahnya: %s
---
[habits_guide_coins]
+10 -2
View File
@@ -7240,6 +7240,10 @@ Una visualizzazione guidata di 15 minuti con rilassamento, un galleggiamento imm
Difficoltà
---
[habit_difficulty_easy]
Facile
---
[habit_difficulty_medium]
Media
---
@@ -7252,6 +7256,10 @@ Difficile
Molto difficile
---
[habit_difficulty_earns_easy]
Fa guadagnare ½ moneta ogni giorno in cui la completi.
---
[habit_difficulty_earns_medium]
Fa guadagnare 1 moneta ogni giorno in cui la completi.
---
@@ -7285,7 +7293,7 @@ monete da spendere
---
[habit_shop_rule]
Ogni giorno in cui completi un'abitudine guadagni monete: 1 se è media, 2 se è difficile e 3 se è molto difficile. Imposta la difficoltà di un'abitudine nel suo editor.
Ogni giorno in cui completi un'abitudine guadagni monete: ½ se è facile, 1 se è media, 2 se è difficile e 3 se è molto difficile. Imposta la difficoltà di un'abitudine nel suo editor.
---
[habit_shop_rewards_title]
@@ -7325,7 +7333,7 @@ Comprare questo premio?
---
[habit_shop_buy_left]
Monete rimaste dopo: %d
Monete rimaste dopo: %s
---
[habits_guide_coins]
+10 -2
View File
@@ -7236,6 +7236,10 @@ Inner Breeze がバージョン %s に更新されました。
難易度
---
[habit_difficulty_easy]
簡単
---
[habit_difficulty_medium]
普通
---
@@ -7248,6 +7252,10 @@ Inner Breeze がバージョン %s に更新されました。
とても難しい
---
[habit_difficulty_earns_easy]
達成した日ごとに½コインもらえます。
---
[habit_difficulty_earns_medium]
達成した日ごとに1コインもらえます。
---
@@ -7281,7 +7289,7 @@ Inner Breeze がバージョン %s に更新されました。
---
[habit_shop_rule]
習慣を達成した日ごとにコインがもらえます。普通は1、難しいは2、とても難しいは3です。難易度は習慣の編集画面で設定できます。
習慣を達成した日ごとにコインがもらえます。簡単は½、普通は1、難しいは2、とても難しいは3です。難易度は習慣の編集画面で設定できます。
---
[habit_shop_rewards_title]
@@ -7321,7 +7329,7 @@ Inner Breeze がバージョン %s に更新されました。
---
[habit_shop_buy_left]
購入後の残りコイン: %d
購入後の残りコイン: %s
---
[habits_guide_coins]
+10 -2
View File
@@ -7246,6 +7246,10 @@ Inner Breeze가 %s 버전으로 업데이트되었어요.
난이도
---
[habit_difficulty_easy]
쉬움
---
[habit_difficulty_medium]
보통
---
@@ -7258,6 +7262,10 @@ Inner Breeze가 %s 버전으로 업데이트되었어요.
매우 어려움
---
[habit_difficulty_earns_easy]
해낸 날마다 코인 ½개를 받아요.
---
[habit_difficulty_earns_medium]
해낸 날마다 코인 1개를 받아요.
---
@@ -7291,7 +7299,7 @@ Inner Breeze가 %s 버전으로 업데이트되었어요.
---
[habit_shop_rule]
습관을 해낸 날마다 코인을 받아요. 보통은 1개, 어려움은 2개, 매우 어려움은 3개예요. 난이도는 습관 편집 화면에서 정해요.
습관을 해낸 날마다 코인을 받아요. 쉬움은 ½개, 보통은 1개, 어려움은 2개, 매우 어려움은 3개예요. 난이도는 습관 편집 화면에서 정해요.
---
[habit_shop_rewards_title]
@@ -7331,7 +7339,7 @@ Inner Breeze가 %s 버전으로 업데이트되었어요.
---
[habit_shop_buy_left]
구매 후 남는 코인: %d
구매 후 남는 코인: %s
---
[habits_guide_coins]
+10 -2
View File
@@ -7249,6 +7249,10 @@ Uma visualização guiada de 15 minutos com relaxamento, flutuação imaginada e
Dificuldade
---
[habit_difficulty_easy]
Fácil
---
[habit_difficulty_medium]
Média
---
@@ -7261,6 +7265,10 @@ Difícil
Muito difícil
---
[habit_difficulty_earns_easy]
Rende ½ moeda a cada dia em que você o cumpre.
---
[habit_difficulty_earns_medium]
Rende 1 moeda a cada dia em que você o cumpre.
---
@@ -7294,7 +7302,7 @@ moedas para gastar
---
[habit_shop_rule]
Cada dia em que você cumpre um hábito rende moedas: 1 para médio, 2 para difícil e 3 para muito difícil. Defina a dificuldade de um hábito no editor dele.
Cada dia em que você cumpre um hábito rende moedas: ½ para fácil, 1 para médio, 2 para difícil e 3 para muito difícil. Defina a dificuldade de um hábito no editor dele.
---
[habit_shop_rewards_title]
@@ -7334,7 +7342,7 @@ Comprar esta recompensa?
---
[habit_shop_buy_left]
Moedas que sobram depois: %d
Moedas que sobram depois: %s
---
[habits_guide_coins]
+10 -2
View File
@@ -7245,6 +7245,10 @@ Inner Breeze обновлён до версии %s.
Сложность
---
[habit_difficulty_easy]
Лёгкая
---
[habit_difficulty_medium]
Средняя
---
@@ -7257,6 +7261,10 @@ Inner Breeze обновлён до версии %s.
Очень трудная
---
[habit_difficulty_earns_easy]
Приносит ½ монеты за каждый день, когда ты её выполняешь.
---
[habit_difficulty_earns_medium]
Приносит 1 монету за каждый день, когда ты её выполняешь.
---
@@ -7290,7 +7298,7 @@ Inner Breeze обновлён до версии %s.
---
[habit_shop_rule]
За каждый день, когда ты выполняешь привычку, ты получаешь монеты: 1 за среднюю, 2 за трудную и 3 за очень трудную. Сложность привычки задаётся в её редакторе.
За каждый день, когда ты выполняешь привычку, ты получаешь монеты: ½ за лёгкую, 1 за среднюю, 2 за трудную и 3 за очень трудную. Сложность привычки задаётся в её редакторе.
---
[habit_shop_rewards_title]
@@ -7330,7 +7338,7 @@ Inner Breeze обновлён до версии %s.
---
[habit_shop_buy_left]
Останется монет: %d
Останется монет: %s
---
[habits_guide_coins]
+10 -2
View File
@@ -7251,6 +7251,10 @@ Inner Breeze 已更新至 %s 版本。
难度
---
[habit_difficulty_easy]
简单
---
[habit_difficulty_medium]
中等
---
@@ -7263,6 +7267,10 @@ Inner Breeze 已更新至 %s 版本。
非常困难
---
[habit_difficulty_earns_easy]
每完成一天可获得 ½ 枚金币。
---
[habit_difficulty_earns_medium]
每完成一天可获得 1 枚金币。
---
@@ -7296,7 +7304,7 @@ Inner Breeze 已更新至 %s 版本。
---
[habit_shop_rule]
每完成一天习惯就能获得金币:中等 1 枚,困难 2 枚,非常困难 3 枚。在习惯的编辑页设置难度。
每完成一天习惯就能获得金币:简单 ½ 枚,中等 1 枚,困难 2 枚,非常困难 3 枚。在习惯的编辑页设置难度。
---
[habit_shop_rewards_title]
@@ -7336,7 +7344,7 @@ Inner Breeze 已更新至 %s 版本。
---
[habit_shop_buy_left]
购买后剩余金币:%d
购买后剩余金币:%s
---
[habits_guide_coins]
+2 -1
View File
@@ -349,7 +349,8 @@ HabitEditState :: struct {
HabitShopState :: struct {
loaded: bool
revision: s64
balance: s64
// The coins to spend, counted in half coins.
halves: s64
rewards: [HABIT_REWARD_MAX]HabitReward
reward_count: s32
// The reward the form changes, or empty while it adds one.
+31 -4
View File
@@ -5,6 +5,9 @@
#import, file "habit_types.zi";
HabitDifficultyClamp :: (difficulty: s32) -> s32 {
if difficulty == HABIT_DIFFICULTY_EASY {
return HABIT_DIFFICULTY_EASY
}
if difficulty < HABIT_DIFFICULTY_MEDIUM {
return HABIT_DIFFICULTY_MEDIUM
}
@@ -14,10 +17,34 @@ HabitDifficultyClamp :: (difficulty: s32) -> s32 {
return difficulty
}
// The coins a done day of a habit this hard earns: medium one, hard two,
// very hard three.
HabitDifficultyCoins :: (difficulty: s32) -> s32 {
return HabitDifficultyClamp(difficulty) + 1
// The half coins a done day of a habit this hard earns: easy one, medium
// two, hard four, very hard six. The wallet counts half coins, so easy
// days add up without rounding.
HabitDifficultyHalfCoins :: (difficulty: s32) -> s32 {
level := HabitDifficultyClamp(difficulty)
if level == HABIT_DIFFICULTY_EASY {
return 1
}
return (level + 1) * 2
}
// The levels as the editor offers them, easiest first.
HabitDifficultyAt :: (index: s32) -> s32 {
if index <= 0 {
return HABIT_DIFFICULTY_EASY
}
if index >= HABIT_DIFFICULTY_COUNT - 1 {
return HABIT_DIFFICULTY_VERY_HARD
}
return index - 1
}
HabitDifficultyIndex :: (difficulty: s32) -> s32 {
level := HabitDifficultyClamp(difficulty)
if level == HABIT_DIFFICULTY_EASY {
return 0
}
return level + 1
}
HabitRewardPriceClamp :: (price: s32) -> s32 {
+7 -5
View File
@@ -137,12 +137,14 @@ HabitAnswer :: struct {
value: [HABIT_ANSWER_SIZE]u8
}
// How hard a habit is. A done day earns one coin for each level: medium
// one, hard two, very hard three (habit_coins.zi).
// How hard a habit is. A done day earns half a coin when easy, then one
// coin for each level: medium one, hard two, very hard three
// (habit_coins.zi). Easy was added last, so stored levels keep their value.
HABIT_DIFFICULTY_MEDIUM :: 0
HABIT_DIFFICULTY_HARD :: 1
HABIT_DIFFICULTY_VERY_HARD :: 2
HABIT_DIFFICULTY_COUNT :: 3
HABIT_DIFFICULTY_EASY :: 3
HABIT_DIFFICULTY_COUNT :: 4
// The shop's rewards: what the person enjoys and how many coins it costs.
HABIT_REWARD_MAX :: 64
@@ -186,8 +188,8 @@ Habit :: struct {
// HABIT_ICON_LETTER for its name's first letter, or 0 while none is
// chosen and its practice's icon or a suggested one is shown.
icon: s32
// How hard the habit is, HABIT_DIFFICULTY_MEDIUM to
// HABIT_DIFFICULTY_VERY_HARD; each done day earns its coins.
// How hard the habit is, a HABIT_DIFFICULTY_ level; each done day
// earns its coins.
difficulty: s32
// The first day whose completion earns coins, YYYYMMDD.
coins_from: s32
+3
View File
@@ -154,6 +154,9 @@ HabitReminderDescribe :: (text: string, output: []u8) -> string {
// How hard a habit is, as its editor names it.
HabitDifficultyLabel :: (difficulty: s32) -> string {
if difficulty == HABIT_DIFFICULTY_EASY {
return LocaleText("habit_difficulty_easy")
}
if difficulty == HABIT_DIFFICULTY_HARD {
return LocaleText("habit_difficulty_hard")
}
+3
View File
@@ -61,6 +61,9 @@ HabitCoinAmount :: (session: Session, amount: string, bounds: Rectangle,
// What a done day of a habit this hard earns, in words.
HabitDifficultyEarns :: (difficulty: s32) -> string {
if difficulty == HABIT_DIFFICULTY_EASY {
return LocaleText("habit_difficulty_earns_easy")
}
if difficulty == HABIT_DIFFICULTY_HARD {
return LocaleText("habit_difficulty_earns_hard")
}
+3 -2
View File
@@ -1882,6 +1882,7 @@ habit_edit_difficulty :: (app: *InnerBreeze, x: s32, y: s32, width: s32) {
habit_edit_text(app, LocaleText("habit_difficulty_label"),
x, y, width, AppScale(26))
options: [HABIT_DIFFICULTY_COUNT]SegmentOption = .[
SegmentOption.{.label = HabitDifficultyLabel(HABIT_DIFFICULTY_EASY)},
SegmentOption.{.label = HabitDifficultyLabel(HABIT_DIFFICULTY_MEDIUM)},
SegmentOption.{.label = HabitDifficultyLabel(HABIT_DIFFICULTY_HARD)},
SegmentOption.{.label = HabitDifficultyLabel(HABIT_DIFFICULTY_VERY_HARD)}]
@@ -1890,11 +1891,11 @@ habit_edit_difficulty :: (app: *InnerBreeze, x: s32, y: s32, width: s32) {
props.bounds = Rectangle.{cast(float32)x, cast(float32)(y + AppScale(30)),
cast(float32)width, cast(float32)AppScale(42)}
props.height = AppScale(42)
props.selected_index = HabitDifficultyClamp(app.habit_edit.difficulty)
props.selected_index = HabitDifficultyIndex(app.habit_edit.difficulty)
props.has_selection = true
switch := SegmentedControl(app.ui.session, props, options[:])
if switch.changed {
app.habit_edit.difficulty = HabitDifficultyClamp(switch.selected_index)
app.habit_edit.difficulty = HabitDifficultyAt(switch.selected_index)
}
hint_y := y + AppScale(80)
coin := AppScale(18)
+28 -6
View File
@@ -62,13 +62,14 @@ HabitShopRefresh :: (app: *InnerBreeze) {
}
shop.loaded = true
shop.revision = revision
shop.balance = storage_habit_wallet_balance()
shop.halves = storage_habit_wallet_halves()
shop.reward_count = storage_habit_rewards_load(shop.rewards[:])
}
// The coins to spend, in half coins.
HabitShopBalance :: (app: *InnerBreeze) -> s64 {
HabitShopRefresh(app)
return app.habit_shop.balance
return app.habit_shop.halves
}
HabitShopNumber :: (app: *InnerBreeze, value: s64) -> string {
@@ -80,6 +81,26 @@ HabitShopNumber :: (app: *InnerBreeze, value: s64) -> string {
AppTextFromCString(*buffer[0], cast(s32)buffer.count))
}
// Half coins as Habits shows them: 12, 12½ or ½.
HabitShopCoins :: (app: *InnerBreeze, halves: s64) -> string {
buffer: [40]u8
buffer[0] = cast(u8)0
whole := halves / 2
odd := halves % 2 != 0
if whole != 0 || !odd {
if !AppFormatS64(whole, buffer[:]) {
return ""
}
} else if halves < 0 {
unused AppCopyText("-", buffer[:])
}
if odd && !AppAppendText("½", buffer[:]) {
return ""
}
return FrameTextHold(*app.ui.frame_text,
AppTextFromCString(*buffer[0], cast(s32)buffer.count))
}
HabitShopPriceText :: (app: *InnerBreeze) {
shop := *app.habit_shop
unused AppFormatS32(shop.price, shop.price_text[:])
@@ -276,7 +297,7 @@ HabitShopBalanceCard :: (app: *InnerBreeze, x: s32, y: s32, width: s32) -> s32 {
cast(float32)coin})
text_x := x + pad + coin + AppScale(14)
text_w := width - (text_x - x) - pad
amount := HabitShopNumber(app, app.habit_shop.balance)
amount := HabitShopCoins(app, app.habit_shop.halves)
strong := StrongWhole(amount)
figure: TextProps
figure.bounds = Rectangle.{cast(float32)text_x, cast(float32)(y + AppScale(14)),
@@ -347,7 +368,7 @@ HabitShopRow :: (app: *InnerBreeze, index: s32, x: s32, y: s32, width: s32) {
HabitCoinAmount(app.ui.session, price, Rectangle.{cast(float32)price_x,
cast(float32)y, cast(float32)price_w, cast(float32)height},
AppFontSize(), true)
affordable := shop.balance >= cast(s64)reward.price
affordable := shop.halves >= cast(s64)reward.price * 2
if HabitShopButton(app, 8600 + index, buy_label, Rectangle.{
cast(float32)buy_x, cast(float32)(y + (height - AppScale(40)) / 2),
cast(float32)buy_w, cast(float32)AppScale(40)},
@@ -617,8 +638,9 @@ HabitShopBuyDialog :: (app: *InnerBreeze) {
AppFontSize() + AppScale(4), true)
y += AppScale(36)
left_args: [1]FormatArg
left := shop.balance - cast(s64)reward.price
left_args[0].number = cast(s32)left
left := shop.halves - cast(s64)reward.price * 2
left_args[0].text = HabitShopCoins(app, left)
left_args[0].is_text = true
left_text: [128]u8
unused FormatTemplate(LocaleText("habit_shop_buy_left"), left_args[:],
left_text[:])
+1 -1
View File
@@ -1439,7 +1439,7 @@ HabitScreenOverview :: (app: *InnerBreeze,
// The coins to spend and the shop's mark end the line of today's
// count, both the size of its text; a tap on either opens the shop.
icon := AppTextLineHeight(AppFontSize())
coins := HabitShopNumber(app, HabitShopBalance(app))
coins := HabitShopCoins(app, HabitShopBalance(app))
coins_w := HabitCoinAmountWidth(coins, AppFontSize())
cluster_w := coins_w + AppScale(12) + icon
cluster_x := geometry.x + geometry.width - cluster_w
+23 -19
View File
@@ -14,22 +14,24 @@ c :: #system_library "c";
sqlite3_bind_int :: (statement: *void, index: s32, value: s32) -> s32 #foreign c "sqlite3_bind_int";
sqlite3_column_int :: (statement: *void, column: s32) -> s32 #foreign c "sqlite3_column_int";
// The coins the done days of the user's habits earned, or of the habit ?2
// alone. A day earns from its habit's coins_from day on, at the difficulty
// the habit had that day: a difficulty change applies from the day it was
// made, so the days before keep the value the change replaced. A day is
// done as the habit list shows it: counted to its target, with linked
// practice sessions as the floor, or marked.
StorageHabitEarnedCoinsSQL :: #string SQL
SELECT COALESCE(SUM(1+MIN(MAX(COALESCE((SELECT CAST(c.old_value AS INTEGER)
// The half coins the done days of the user's habits earned, or of the
// habit ?2 alone: easy one, medium two, hard four, very hard six
// (HabitDifficultyHalfCoins). A day earns from its habit's coins_from day
// on, at the difficulty the habit had that day: a difficulty change applies
// from the day it was made, so the days before keep the value the change
// replaced. A day is done as the habit list shows it: counted to its
// target, with linked practice sessions as the floor, or marked.
StorageHabitEarnedHalvesSQL :: #string SQL
SELECT COALESCE(SUM(CASE WHEN e.level=3 THEN 1 ELSE 2+2*MIN(MAX(e.level,0),2) END),0)
FROM (SELECT COALESCE((SELECT CAST(c.old_value AS INTEGER)
FROM habit_changes c WHERE c.habit_id=h.id AND c.kind=19 AND c.deleted_at=0 AND
CAST(strftime('%Y%m%d',c.changed_at,'unixepoch','localtime') AS INTEGER)>d.local_date
ORDER BY c.changed_at,c.rowid LIMIT 1),h.difficulty),0),2)),0)
ORDER BY c.changed_at,c.rowid LIMIT 1),h.difficulty) AS level
FROM habit_days d JOIN habits h ON h.id=d.habit_id
WHERE h.user_id=?1 AND h.deleted_at=0 AND (?2='' OR h.id=?2) AND h.coins_from>0 AND
d.local_date>=h.coins_from AND CASE WHEN h.counter_enabled<>0 THEN
MAX(d.count,d.session_count,CASE WHEN d.completed<>0 THEN 1 ELSE 0 END)>=MAX(h.counter_target,1)
ELSE d.completed<>0 OR d.count>0 OR d.session_count>0 END
ELSE d.completed<>0 OR d.count>0 OR d.session_count>0 END) e
SQL
// Coins kept from deleted habits less the coins rewards cost.
@@ -56,24 +58,26 @@ storage_habit_wallet_select :: (sql: string, habit_id: string,
return value
}
// The coins the done days of a habit earned, or of every habit for "".
storage_habit_earned_coins :: (habit_id: string) -> s64 {
return storage_habit_wallet_select(StorageHabitEarnedCoinsSQL, habit_id,
// The half coins the done days of a habit earned, or of every habit for "".
storage_habit_earned_halves :: (habit_id: string) -> s64 {
return storage_habit_wallet_select(StorageHabitEarnedHalvesSQL, habit_id,
true)
}
// The coins there are to spend; below 0 when days that paid for a reward
// were cleared afterwards.
storage_habit_wallet_balance :: () -> s64 {
return storage_habit_earned_coins("") +
storage_habit_wallet_select(StorageHabitCoinRecordsSQL, "", false)
// The half coins there are to spend; below 0 when days that paid for a
// reward were cleared afterwards. Kept and spent coins are whole.
storage_habit_wallet_halves :: () -> s64 {
records := storage_habit_wallet_select(StorageHabitCoinRecordsSQL, "",
false)
return storage_habit_earned_halves("") + records * 2
}
// Keeps the coins a habit's days earned before the habit and its days are
// deleted. The record is the habit's own, so two devices deleting it keep
// them once.
storage_habit_coins_keep :: (habit_id: string, at: s64) -> s32 {
earned := storage_habit_earned_coins(habit_id)
// A kept record holds whole coins; an odd half coin goes with the habit.
earned := storage_habit_earned_halves(habit_id) / 2
if earned <= 0 || habit_id.count == 0 {
return 1
}
+25 -11
View File
@@ -12,6 +12,7 @@
#import, file "../src/storage/storage_profile_stats.zi";
#import, file "../src/storage/storage_sessions.zi";
#import, file "../src/habits/habit_types.zi";
#import, file "../src/habits/habit_coins.zi";
#import, file "../src/habits/habit_memory.zi";
#import, file "../src/storage/storage_habits.zi";
#import, file "../src/habits/habit_model.zi";
@@ -889,10 +890,10 @@ synced_changes :: (entity_type: string, entity_id: string, array: string,
}
// Done days earn coins by their habit's difficulty from its coins_from day
// on; a difficulty change pays from the day it was made, so earlier days
// keep what they earned. Rewards spend coins, a deleted habit's coins stay,
// and rewards, purchases and the habits' coin fields travel to the other
// devices.
// on, counted in half coins; a difficulty change pays from the day it was
// made, so earlier days keep what they earned. Rewards spend coins, a
// deleted habit's coins stay, and rewards, purchases and the habits' coin
// fields travel to the other devices.
test_habit_wallet :: () {
root := make_root("habit-wallet")
check_true("init db", storage_init(root) != 0)
@@ -902,10 +903,10 @@ test_habit_wallet :: () {
// Walk earns 1 on two days; push, very hard, 3 on its counted day and
// its day of linked sessions, not before its coins_from day nor short
// of its target.
check_int("done days earn by difficulty", cast(s32)storage_habit_wallet_balance(), 8)
check_int("done days earn by difficulty", cast(s32)storage_habit_wallet_halves(), 16)
// Walk became hard on 2026-10-03: that day pays 2, the day before 1.
exec_db_sql("UPDATE habits SET difficulty=1 WHERE id='walk';INSERT INTO habit_changes(id,user_id,habit_id,changed_at,kind,question,question_text,old_value,new_value,deleted_at,updated_at) VALUES('d1',(SELECT id FROM users LIMIT 1),'walk',CAST(strftime('%s','2026-10-03 12:00:00','utc') AS INTEGER),19,0,'','0','1',0,1);")
check_int("a difficulty change pays from its day", cast(s32)storage_habit_wallet_balance(), 9)
check_int("a difficulty change pays from its day", cast(s32)storage_habit_wallet_halves(), 18)
habits_a = Habits.{}
check_true("load habits", storage_habits_load(cast(*void)*habits_a) != 0)
walk := find_habit(*habits_a, "Walk")
@@ -916,7 +917,7 @@ test_habit_wallet :: () {
habits_save(*habits_a)
check_int("the editor's change is logged",
read_db_count("SELECT COUNT(*) FROM habit_changes WHERE habit_id='walk' AND kind=19 AND old_value='1' AND new_value='2'"), 1)
check_int("days before today keep their coins", cast(s32)storage_habit_wallet_balance(), 9)
check_int("days before today keep their coins", cast(s32)storage_habit_wallet_halves(), 18)
// The shop.
exec_db_sql("DELETE FROM sync_outbox;")
movie: [HABIT_REWARD_ID_SIZE]u8
@@ -929,7 +930,7 @@ test_habit_wallet :: () {
count == 2 && rewards[0].price == 5 && rewards[1].price == HABIT_REWARD_PRICE_MAX &&
AppTextFromCString(*rewards[0].name[0], HABIT_REWARD_NAME_SIZE) == "Movie night")
check_true("buy the movie night", storage_habit_reward_buy(*rewards[0]) != 0)
check_int("the price is spent", cast(s32)storage_habit_wallet_balance(), 4)
check_int("the price is spent", cast(s32)storage_habit_wallet_halves(), 8)
renamed: [HABIT_REWARD_ID_SIZE]u8
check_true("rename a reward", storage_habit_reward_save(TextUntilNul(other[:]),
"Long sauna", 20, renamed[:]) != 0 && TextUntilNul(renamed[:]) == TextUntilNul(other[:]))
@@ -947,7 +948,7 @@ test_habit_wallet :: () {
habits_delete(*habits_a, position)
habits_save(*habits_a)
check_int("its coins are kept", read_db_count("SELECT COUNT(*) FROM habit_coins WHERE id='kept:push' AND kind=2 AND coins=6 AND name='Push ups'"), 1)
check_int("the balance stays", cast(s32)storage_habit_wallet_balance(), 4)
check_int("the balance stays", cast(s32)storage_habit_wallet_halves(), 8)
// The records another device receives.
buffer: [8192]u8
bought := read_db_text("SELECT id FROM habit_coins WHERE kind=1")
@@ -961,9 +962,9 @@ test_habit_wallet :: () {
check_int("the reward arrives", storage_habit_rewards_load(rewards[:]), 1)
coin_json := synced_changes("habit_coin", TextUntilNul(coin_id[:]), "habit_coins", buffer[:])
exec_db_sql("DELETE FROM habit_coins WHERE kind=1;")
check_int("without the purchase", cast(s32)storage_habit_wallet_balance(), 9)
check_int("without the purchase", cast(s32)storage_habit_wallet_halves(), 18)
check_true("apply the purchase", storage_apply_sync_habit_coins_json(coin_json) != 0)
check_int("the purchase arrives", cast(s32)storage_habit_wallet_balance(), 4)
check_int("the purchase arrives", cast(s32)storage_habit_wallet_halves(), 8)
habit_json := synced_changes("habit", "walk", "habits", buffer[:])
check_true("a habit's record has its coin fields",
contains(habit_json, "\"difficulty\":2") && contains(habit_json, "\"coins_from\":20261001"))
@@ -971,6 +972,19 @@ test_habit_wallet :: () {
check_true("apply the habit", storage_apply_sync_habits_json(habit_json) != 0)
check_int("the earliest first coin day and the difficulty arrive",
read_db_count("SELECT COUNT(*) FROM habits WHERE id='walk' AND coins_from=20261001 AND difficulty=2"), 1)
// An easy habit earns half a coin on each done day.
exec_db_sql("INSERT INTO habits(id,user_id,name,color_r,color_g,color_b,sync_mode,sync_activity,counter_enabled,counter_target,sort_order,deleted_at,updated_at,difficulty,coins_from) VALUES('read',(SELECT id FROM users LIMIT 1),'Read',7,8,9,0,0,0,1,2,0,1782200000,3,20261001);INSERT INTO habit_days(habit_id,local_date,completed,count,session_count,updated_at) VALUES('read',20261001,1,1,0,1),('read',20261002,1,1,0,1),('read',20261003,1,1,0,1);")
check_int("easy days earn half coins", cast(s32)storage_habit_wallet_halves(), 11)
check_true("each level's half coins",
HabitDifficultyHalfCoins(HABIT_DIFFICULTY_EASY) == 1 &&
HabitDifficultyHalfCoins(HABIT_DIFFICULTY_MEDIUM) == 2 &&
HabitDifficultyHalfCoins(HABIT_DIFFICULTY_HARD) == 4 &&
HabitDifficultyHalfCoins(HABIT_DIFFICULTY_VERY_HARD) == 6)
check_true("the editor offers easy first",
HabitDifficultyAt(0) == HABIT_DIFFICULTY_EASY &&
HabitDifficultyIndex(HABIT_DIFFICULTY_MEDIUM) == 1 &&
HabitDifficultyAt(HabitDifficultyIndex(HABIT_DIFFICULTY_VERY_HARD)) ==
HABIT_DIFFICULTY_VERY_HARD)
habits_free(*habits_a)
storage_close()
}