docs(0.S): the doc fences migrated by ludic migrate state; LANGUAGE.md's state section says what the tool and the checker do now; no module-level var left in the docs
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
19fcf60599
commit
a476ec7976
79 changed files with 481 additions and 355 deletions
|
|
@ -15,23 +15,25 @@ order: 2
|
|||
program CancelExample {
|
||||
event cancellable BeforeOpenDoor { key_count: int = 0 }
|
||||
|
||||
var keys: int = 0
|
||||
var doors_opened: int = 0
|
||||
state CancelExampleState {
|
||||
keys: int = 0
|
||||
doors_opened: int = 0
|
||||
}
|
||||
|
||||
@On(BeforeOpenDoor) handler RequireKey { if key_count <= 0 { cancel } }
|
||||
|
||||
handler TryOpen phase Update {
|
||||
handler TryOpen(cancel_example_st: mut CancelExampleState) phase Update {
|
||||
if Input.key() == 'o' {
|
||||
if emit BeforeOpenDoor(key_count: keys) == 0 {
|
||||
doors_opened = doors_opened + 1
|
||||
keys = keys - 1
|
||||
if emit BeforeOpenDoor(key_count: cancel_example_st.keys) == 0 {
|
||||
cancel_example_st.doors_opened = cancel_example_st.doors_opened + 1
|
||||
cancel_example_st.keys = cancel_example_st.keys - 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
handler DrawWorld phase Render {
|
||||
handler DrawWorld(cancel_example_st: CancelExampleState) phase Render {
|
||||
Screen.clear(Color.MidnightBlue)
|
||||
Screen.draw_number(x: 4, y: 4, value: doors_opened, color: Color.Gold, scale: 1)
|
||||
Screen.draw_number(x: 4, y: 4, value: cancel_example_st.doors_opened, color: Color.Gold, scale: 1)
|
||||
Screen.show()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,19 +15,21 @@ order: 50
|
|||
program CancellableExample {
|
||||
event cancellable BeforeHurt { amount: int = 0 }
|
||||
|
||||
var current_health: int = 100
|
||||
state CancellableExampleState {
|
||||
current_health: int = 100
|
||||
}
|
||||
|
||||
@On(BeforeHurt) handler AbsorbSmallHits { if amount <= 5 { cancel } }
|
||||
|
||||
handler TakeDamage phase Update {
|
||||
handler TakeDamage(cancellable_example_st: mut CancellableExampleState) phase Update {
|
||||
if Input.key() == 'h' {
|
||||
if emit BeforeHurt(amount: 3) == 0 { current_health = current_health - 3 }
|
||||
if emit BeforeHurt(amount: 3) == 0 { cancellable_example_st.current_health = cancellable_example_st.current_health - 3 }
|
||||
}
|
||||
}
|
||||
|
||||
handler DrawWorld phase Render {
|
||||
handler DrawWorld(cancellable_example_st: CancellableExampleState) phase Render {
|
||||
Screen.clear(Color.MidnightBlue)
|
||||
Screen.draw_number(x: 4, y: 4, value: current_health, color: Color.Crimson, scale: 1)
|
||||
Screen.draw_number(x: 4, y: 4, value: cancellable_example_st.current_health, color: Color.Crimson, scale: 1)
|
||||
Screen.show()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,19 +15,21 @@ order: 1
|
|||
program EmitExample {
|
||||
event cancellable BeforeSpend { amount: int = 0 }
|
||||
|
||||
var coins: int = 50
|
||||
state EmitExampleState {
|
||||
coins: int = 50
|
||||
}
|
||||
|
||||
@On(BeforeSpend) handler RejectOverdraft { if amount > coins { cancel } }
|
||||
@On(BeforeSpend) handler RejectOverdraft(emit_example_st: EmitExampleState) { if amount > emit_example_st.coins { cancel } }
|
||||
|
||||
handler TrySpend phase Update {
|
||||
handler TrySpend(emit_example_st: mut EmitExampleState) phase Update {
|
||||
if Input.key() == 'b' {
|
||||
if emit BeforeSpend(amount: 20) == 0 { coins = coins - 20 }
|
||||
if emit BeforeSpend(amount: 20) == 0 { emit_example_st.coins = emit_example_st.coins - 20 }
|
||||
}
|
||||
}
|
||||
|
||||
handler DrawWorld phase Render {
|
||||
handler DrawWorld(emit_example_st: EmitExampleState) phase Render {
|
||||
Screen.clear(Color.MidnightBlue)
|
||||
Screen.draw_number(x: 4, y: 4, value: coins, color: Color.Gold, scale: 1)
|
||||
Screen.draw_number(x: 4, y: 4, value: emit_example_st.coins, color: Color.Gold, scale: 1)
|
||||
Screen.show()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,18 +15,20 @@ order: 0
|
|||
program EventExample {
|
||||
event EnemyDefeated { points: int = 0 }
|
||||
|
||||
var score: int = 0
|
||||
state EventExampleState {
|
||||
score: int = 0
|
||||
}
|
||||
|
||||
@On(EnemyDefeated) handler AddScore { score = score + points }
|
||||
@On(EnemyDefeated) handler AddScore(event_example_st: mut EventExampleState) { event_example_st.score = event_example_st.score + points }
|
||||
@On(EnemyDefeated) handler PlayChime { Screen.status("enemy down") }
|
||||
|
||||
handler ScoreOnKey phase Update {
|
||||
if Input.key() == 'k' { emit EnemyDefeated(points: 10) }
|
||||
}
|
||||
|
||||
handler DrawWorld phase Render {
|
||||
handler DrawWorld(event_example_st: EventExampleState) phase Render {
|
||||
Screen.clear(Color.MidnightBlue)
|
||||
Screen.draw_number(x: 4, y: 4, value: score, color: Color.Gold, scale: 1)
|
||||
Screen.draw_number(x: 4, y: 4, value: event_example_st.score, color: Color.Gold, scale: 1)
|
||||
Screen.show()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue