switch all views to overlays

This commit is contained in:
fanyx 2021-01-04 19:55:25 +01:00
parent 8234acb993
commit d15fcd7583
2 changed files with 57 additions and 28 deletions

View File

@ -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,15 +43,11 @@ defmodule YathEx do
@impl true
def init(_) do
model = %{
current_view: :savegame,
views: %{
encounter: %{
name: :none,
stamina: 0,
skill: 0
},
savegame: %{data: :none}
},
hero: %{
stamina: %{max: :none, current: :none},
skill: %{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
end
end
def render_view(model) do
case model.current_view do
:encounter -> Encounter.render(model)
# set overlay
:equipment -> Equipment.render(model)
{_,{:event, %{ch: ch}}} when ch in @view_keys ->
Update.set_overlay(model, @view_keymap[ch])
:help -> Help.render(model)
:logbook -> Logbook.render(model)
:savegame -> Savegame.render(model)
:spells -> Spells.render(model)
end
end
def render_panel(model) do
@impl true
def render(model) do
menu = Menu.render()
# top level view
view(bottom_bar: menu) do
# TODO: declare main view
# render overlay when not nil
render_overlay(model)
end
end
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

7
mix.lock Normal file
View File

@ -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"},
}