initial commit

This commit is contained in:
fanyx 2021-01-03 16:49:38 +01:00
commit 8234acb993
2 changed files with 127 additions and 0 deletions

99
lib/yath_ex.ex Normal file
View File

@ -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

28
mix.exs Normal file
View File

@ -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