yath_ex/lib/yath_ex.ex

100 lines
1.8 KiB
Elixir
Raw Normal View History

2021-01-03 16:49:38 +01:00
defmodule YathEx do
@behaviour Ratatouille.App
import Ratatouille.View
import Ratatouille.Constants, only: [key: 1]
alias YathEx.Views.{
Encounter,
Equipment,
Help,
Logbook,
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)
@view_keymap %{
?c => :encounter,
?C => :encounter,
?l => :logbook,
?L => :logbook,
?i => :equipment,
?I => :equipment,
?h => :help,
?H => :help,
?? => :help,
?k => :spells,
?K => :spells,
?s => :savegame,
?S => :savegame
}
@view_keys Map.keys(@view_keymap)
@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},
luck: %{max: :none, current: :none},
equipment: [],
spells: []
},
logbook: [],
encounters: []
}
model
end
@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)
:equipment -> Equipment.render(model)
:help -> Help.render(model)
:logbook -> Logbook.render(model)
:savegame -> Savegame.render(model)
:spells -> Spells.render(model)
end
end
def render_panel(model) do
end
end