commit 8234acb993fd16cb385ce62de88d4aa0319479b8 Author: fanyx Date: Sun Jan 3 16:49:38 2021 +0100 initial commit diff --git a/lib/yath_ex.ex b/lib/yath_ex.ex new file mode 100644 index 0000000..8e7fca2 --- /dev/null +++ b/lib/yath_ex.ex @@ -0,0 +1,99 @@ +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 diff --git a/mix.exs b/mix.exs new file mode 100644 index 0000000..dde651f --- /dev/null +++ b/mix.exs @@ -0,0 +1,28 @@ +defmodule YathEx.MixProject do + use Mix.Project + + def project do + [ + app: :yath_ex, + version: "0.1.0", + elixir: "~> 1.10", + start_permanent: Mix.env() == :prod, + deps: deps() + ] + end + + # Run "mix help compile.app" to learn about applications. + def application do + [ + extra_applications: [:logger] + ] + end + + # Run "mix help deps" to learn about dependencies. + defp deps do + [ + {:ratatouille, ">= 0.5.1"}, + {:jason, "~> 1.2"} + ] + end +end