defmodule YathEx do @behaviour Ratatouille.App import Ratatouille.View import Ratatouille.Constants, only: [key: 1] alias YathEx.Update alias YathEx.Views.{ Encounter, Equipment, Help, Logbook, Menu, Savegame, Spells } @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, ?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 = %{ encounter: %{ name: :none, stamina: 0, skill: 0 }, hero: %{ stamina: %{max: :none, current: :none}, skill: %{max: :none, current: :none}, luck: %{max: :none, current: :none}, equipment: [], spells: [] }, logbook: [], 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 case {model, msg} do # set overlay {_,{:event, %{ch: ch}}} when ch in @view_keys -> Update.set_overlay(model, @view_keymap[ch]) end end @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