From d15fcd7583fd0479777ebc4585297b45322ca7d8 Mon Sep 17 00:00:00 2001 From: fanyx Date: Mon, 4 Jan 2021 19:55:25 +0100 Subject: [PATCH] switch all views to overlays --- lib/yath_ex.ex | 78 ++++++++++++++++++++++++++++++++------------------ mix.lock | 7 +++++ 2 files changed, 57 insertions(+), 28 deletions(-) create mode 100644 mix.lock diff --git a/lib/yath_ex.ex b/lib/yath_ex.ex index 8e7fca2..843b863 100644 --- a/lib/yath_ex.ex +++ b/lib/yath_ex.ex @@ -4,21 +4,23 @@ defmodule YathEx do import Ratatouille.View import Ratatouille.Constants, only: [key: 1] + alias YathEx.Update + alias YathEx.Views.{ Encounter, Equipment, Help, Logbook, + Menu, Savegame, Spells } - alias YathEx.Update - @arrow_up key(:arrow_up) @arrow_down key(:arrow_down) @arrow_right key(:arrow_right) @arrow_left key(:arrow_left) + @escape key(:esc) @view_keymap %{ ?c => :encounter, @@ -41,14 +43,10 @@ defmodule YathEx do @impl true def init(_) do model = %{ - current_view: :savegame, - views: %{ - encounter: %{ - name: :none, - stamina: 0, - skill: 0 - }, - savegame: %{data: :none} + encounter: %{ + name: :none, + stamina: 0, + skill: 0 }, hero: %{ stamina: %{max: :none, current: :none}, @@ -58,42 +56,66 @@ defmodule YathEx do spells: [] }, logbook: [], - encounters: [] + encounters: [], + savegame: [], + overlay: nil } model end + # bind to overlay scene + # TODO: implement for each overlay + @impl true + def update(%{overlay: overlay} = model, msg) do + + end + + # catch all other updates @impl true def update(model, msg) do - - # change to selected view - case {model, msg} do - {_, {:event, %{key: key}}} when key in @view_keys -> - fn model -> - %{model | current_view: @view_keymap[key]} - end + + # set overlay + + {_,{:event, %{ch: ch}}} when ch in @view_keys -> + Update.set_overlay(model, @view_keymap[ch]) + end end - def render_view(model) do - case model.current_view do - :encounter -> Encounter.render(model) + @impl true + def render(model) do + menu = Menu.render() - :equipment -> Equipment.render(model) - :help -> Help.render(model) + # top level view + view(bottom_bar: menu) do - :logbook -> Logbook.render(model) + # TODO: declare main view - :savegame -> Savegame.render(model) - - :spells -> Spells.render(model) + # render overlay when not nil + render_overlay(model) end end - def render_panel(model) do + def render_overlay(model) do + overlay(padding: 10) do + case model.overlay do + :encounter -> Encounter.render(model.encounter) + :equipment -> Equipment.render(model.hero.equipment) + + :help -> Help.render() + + :logbook -> Logbook.render(model.logbook) + + :savegame -> Savegame.render(model.savegame) + + :spells -> Spells.render(model.hero.spells) + + _ -> model # or nil? + end + end end end diff --git a/mix.lock b/mix.lock new file mode 100644 index 0000000..dd753dc --- /dev/null +++ b/mix.lock @@ -0,0 +1,7 @@ +%{ + "asciichart": {:hex, :asciichart, "1.0.0", "6ef5dbeab545cb7a0bdce7235958f129de6cd8ad193684dc0953c9a8b4c3db5b", [:mix], [], "hexpm", "edc475e4cdd317599310fa714dbc1f53485c32fc918e23e95f0c2bbb731f2ee2"}, + "elixir_make": {:hex, :elixir_make, "0.6.2", "7dffacd77dec4c37b39af867cedaabb0b59f6a871f89722c25b28fcd4bd70530", [:mix], [], "hexpm", "03e49eadda22526a7e5279d53321d1cced6552f344ba4e03e619063de75348d9"}, + "ex_termbox": {:hex, :ex_termbox, "1.0.2", "30cb94c2585e28797bedfc771687623faff75ab0eb77b08b3214181062bfa4af", [:make, :mix], [{:elixir_make, "~> 0.4", [hex: :elixir_make, repo: "hexpm", optional: false]}], "hexpm", "ca7b14d1019f96466a65ba08bd6cbf46e8b16f87339ef0ed211ba0641f304807"}, + "jason": {:hex, :jason, "1.2.2", "ba43e3f2709fd1aa1dce90aaabfd039d000469c05c56f0b8e31978e03fa39052", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "18a228f5f0058ee183f29f9eae0805c6e59d61c3b006760668d8d18ff0d12179"}, + "ratatouille": {:hex, :ratatouille, "0.5.1", "0f80009fa9534e257505bfe06bff28e030b458d4a33ec2427f7be34a6ef1acf7", [:mix], [{:asciichart, "~> 1.0", [hex: :asciichart, repo: "hexpm", optional: false]}, {:ex_termbox, "~> 1.0", [hex: :ex_termbox, repo: "hexpm", optional: false]}], "hexpm", "b2394eb1cc662eae53ae0fb7c27c04543a6d2ce11ab6dc41202c5c4090cbf652"}, +}