Last active
June 10, 2018 19:41
-
-
Save gcentauri/6101906ab3d56738ee83f27d76819d2a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Html exposing (Html, button, div, text) | |
import Html.Events exposing (onClick) | |
import Game exposing (..) | |
import Game.Lenses exposing(..) | |
main = | |
Html.beginnerProgram { model = game, view = view, update = update } | |
type Msg = UpdateGame | |
update msg model = | |
case msg of | |
UpdateGame -> | |
updateGame model | |
view model = | |
div [] | |
[ div [] [ text (toString (model |> inventory_.get)) ] | |
] | |
player = Player 10 [Item "Sword" "it cuts"] | |
slime = Monster "Slime" 1 (Item "goo" "it goos") | |
game = Game player [slime] | |
module Game exposing (..) | |
type alias Game = | |
{ player: Player | |
, monsters: List Monster | |
} | |
type alias Player = | |
{ health: Int -- [lens : playerHealth] | |
, inventory: List Item | |
} | |
type alias Item = | |
{ name: String -- [lens : itemName] | |
, description: String | |
} | |
type alias Monster = | |
{ name: String -- [lens :monsterName] | |
, health: Int -- [lens :monsterHealth] | |
, drops: Item | |
} | |
updateGame : Game -> Game | |
updateGame game = game |
To append to the inventory:
model |> (player_ >. inventory_ >. (nth_ hugenumber defaultItem)).set myitem
where hugenumber
is either a fixed huge number or is the length of the current inventory as determined by an erlier step, say stored in a let
expression, and defaultItem
is some fixed default item that is needed for formal purposes in this example.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Then you can just do
model |> inv_.set [...]
or whatever