Skip to content

Instantly share code, notes, and snippets.

@sarasfox
Created April 20, 2025 16:04
Show Gist options
  • Save sarasfox/a89ebec47a934412316fe2eecd9fdab2 to your computer and use it in GitHub Desktop.
Save sarasfox/a89ebec47a934412316fe2eecd9fdab2 to your computer and use it in GitHub Desktop.
import lustre
import lustre/attribute
import lustre/element/html
import lustre/event
import gleam/int
import gleam/list
import gleam/io
import gleam/dynamic/decode
type Model {
Model(x: Int, y: Int)
}
pub type Msg {
PickStat(x: Int, y: Int)
}
fn update(_, msg: Msg) -> Model {
echo msg
case msg {
PickStat(x, y) -> Model(x, y)
}
}
pub fn main() {
let stat = ["Strength", "Intelligence", "Luck", "Wisdom", "Perception", "Dexterity", "Speed", "Endurance","Constitution", "Appearance", "Charisma", "Willpower"]
let numbers = list.repeat(0, times: 12)
|> list.map(fn(_) { int.random(12) + 1 })
let get_drop =event.on("drop", {
use x <- decode.field("offsetX", decode.int)
use y <- decode.field("offsetY", decode.int)
decode.success(PickStat(x, y))
})
let app =
lustre.element(
html.div([], [
html.h1([], [html.text("Create a new character")]),
html.section([], [
html.h2([], [html.text("Name")]),
html.input([attribute.name("name"), attribute.type_("text")]),
html.div([attribute.class("stats-grid")],
list.map(stat, fn(stat) {
html.h3([attribute.class("stat-card")], [html.text(stat)])
})
),
html.div([attribute.class("numbers-grid")],
list.map(numbers, fn(number) {
html.h3([attribute.class("number-card"), attribute.draggable(True), get_drop], [html.text(int.to_string(number))])
})
)
]),
html.link([attribute.rel("stylesheet"), attribute.href("priv/static/ia.css")]),
])
)
let assert Ok(_) = lustre.start(app, "#app", Nil)
Nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment