wip(0.S3): the packages migrated by ludic migrate state packages - every package test green

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Orkun ÇAKILKAYA 2026-09-25 14:02:21 +03:00
parent 1e8b5b0523
commit 07505e7ef2
294 changed files with 14996 additions and 14675 deletions

View file

@ -4,26 +4,28 @@ numbers float
import "ludic.base"
export property Caught { species: int = 0, weight: float = 0.0 }
export port FishingWorld { is_water: fn(float, float) -> bool } # its port
var dice: Rng = null
var casts: int = 0
export var caught: Queue<Caught> = null # its facts
export function fishing_cast(x: float, z: float) -> bool { # its verb
export state ToyFishingState {
dice: Rng = null
casts: int = 0
caught: Queue<Caught> = null # its facts
}
export function fishing_cast(toy_fishing_st: mut ToyFishingState, x: float, z: float) -> bool { # its verb
if not FishingWorld.is_water(x, z) { return false }
casts += 1
toy_fishing_st.casts += 1
return true
}
function fishing_reset() -> void {
casts = 0
dice = rng_new(7)
caught = queue_new("fishing.caught")
function fishing_reset(base_st: mut BaseState, toy_fishing_st: mut ToyFishingState) -> void {
toy_fishing_st.casts = 0
toy_fishing_st.dice = rng_new(7)
toy_fishing_st.caught = queue_new(base_st, "fishing.caught")
}
function fishing_tick(t: Tick) -> void {
while casts > 0 {
function fishing_tick(base_st: mut BaseState, toy_fishing_st: mut ToyFishingState, t: Tick) -> void {
while toy_fishing_st.casts > 0 {
let c = new Caught
c.species = rng_between(dice, 0, 2)
c.weight = 0.5 + rng_float(dice)
q_push(caught, c)
casts -= 1
c.species = rng_between(toy_fishing_st.dice, 0, 2)
c.weight = 0.5 + rng_float(toy_fishing_st.dice)
q_push(base_st, toy_fishing_st.caught, c)
toy_fishing_st.casts -= 1
}
}
export function fishing_system() -> System {

View file

@ -2,22 +2,24 @@
module toy_pack uses ludic_base
numbers float
import "ludic.base"
var counts: []int = null
export function pack_add(kind: int, n: int) -> void { counts[kind] = counts[kind] + n }
export function pack_count(kind: int) -> int { return counts[kind] }
function pack_reset() -> void {
counts = new []int
for i in 0 .. 3 { push(counts, 0) }
export state ToyPackState {
counts: []int = null
}
function pack_save() -> Val {
export function pack_add(toy_pack_st: mut ToyPackState, kind: int, n: int) -> void { toy_pack_st.counts[kind] = toy_pack_st.counts[kind] + n }
export function pack_count(toy_pack_st: ToyPackState, kind: int) -> int { return toy_pack_st.counts[kind] }
function pack_reset(toy_pack_st: mut ToyPackState) -> void {
toy_pack_st.counts = new []int
for i in 0 .. 3 { push(toy_pack_st.counts, 0) }
}
function pack_save(toy_pack_st: ToyPackState) -> Val {
let v = Value.object()
sv_put_ints(v, "counts", counts)
sv_put_ints(v, "counts", toy_pack_st.counts)
return v
}
function pack_load(v: Val, version: int) -> void {
pack_reset()
function pack_load(toy_pack_st: mut ToyPackState, v: Val, version: int) -> void {
pack_reset(toy_pack_st)
let xs = sv_ints(v, "counts")
for i in 0 .. len(xs) { if i < len(counts) { counts[i] = xs[i] } }
for i in 0 .. len(xs) { if i < len(toy_pack_st.counts) { toy_pack_st.counts[i] = xs[i] } }
}
export function pack_system() -> System {
let s = system_new("pack", PH_COMMIT)