From fd595dd749c84f7e8a4adcdbe8f7ef456329b3ae Mon Sep 17 00:00:00 2001 From: Kodi Arfer Date: Wed, 10 Jan 2024 17:08:04 -0500 Subject: [PATCH] Use `MetaDict`s in more places. --- simalq/save_load.hy | 23 ++++++++++++----------- simalq/tile/item.hy | 11 ++++++----- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/simalq/save_load.hy b/simalq/save_load.hy index 491d5da..cccbb76 100644 --- a/simalq/save_load.hy +++ b/simalq/save_load.hy @@ -8,6 +8,7 @@ json pickle zipfile [ZipFile ZIP-STORED ZIP-DEFLATED] + metadict [MetaDict] simalq.game-state [G] simalq.util [menu-letters saved-games-dir mixed-number]) (setv T True F False) @@ -96,14 +97,14 @@ (list (.iterdir (/ saved-games-dir (or quest-name G.quest.name)))) (except [FileNotFoundError] [])) - (dict + (MetaDict :path path :main (= path.stem "main") :time (. path (stat) st-mtime) #** (get-saved-game-meta path))) :key (fn [d] #( - (not (get d "main")) - (get d "time"))))) + (not d.main) + d.time)))) (setv display-lines [ " Date DL Turn HP Score HP f. Poison f." @@ -111,13 +112,13 @@ [i save] (enumerate saves) (.format " ({}) {:4} {:%Y %b %d %H:%M} {:3d} {:6,} {:5,} {:7,} {:>6} {:>10}" (get menu-letters i) - (if (get save "main") "main" "") - (datetime.fromtimestamp (get save "time")) - (get save "level_n") - (get save "turn_n") - (get save "player_hp") - (get save "score") - (mixed-number (f/ #* (get save "player_hp_factor"))) - (mixed-number (f/ #* (get save "poison_factor")))))]) + (if save.main "main" "") + (datetime.fromtimestamp save.time) + save.level-n + save.turn-n + save.player-hp + save.score + (mixed-number (f/ #* save.player-hp-factor)) + (mixed-number (f/ #* save.poison-factor))))]) #(saves display-lines)) diff --git a/simalq/tile/item.hy b/simalq/tile/item.hy index f2f939f..c96f163 100644 --- a/simalq/tile/item.hy +++ b/simalq/tile/item.hy @@ -2,6 +2,7 @@ simalq.macros [unless defmeth] simalq.tile [deftile]) (import + metadict [MetaDict] simalq.strings simalq.util [CommandError] simalq.game-state [G] @@ -180,17 +181,17 @@ :eat-messages #("You drink a jar of poison. It tastes pretty bad.") :hook-player-shot (meth [] - (doc #[f[Explodes in a size-{(get poison-burst "size")} burst of poison, which does {(get poison-burst "dmg_monster")} poison damage to monsters and {(get poison-burst "dmg_player")} to you.]f]) + (doc #[f[Explodes in a size-{poison-burst.size} burst of poison, which does {poison-burst.dmg-monster} poison damage to monsters and {poison-burst.dmg-player} to you.]f]) (burst-damage @pos :damage-type DamageType.Poison :amount (* - [(get poison-burst "dmg_monster")] - (+ 1 (get poison-burst "size"))) + [poison-burst.dmg-monster] + (+ 1 poison-burst.size)) :color 'moss-green - :player-amount (get poison-burst "dmg_player")) + :player-amount poison-burst.dmg-player) (@rm-from-map)) :flavor "I think you're not supposed to drink this.") -(setv poison-burst (dict +(setv poison-burst (MetaDict :size 2 :dmg-player 20 :dmg-monster 3))