refactor(packages): 0.R5 - a question no longer starts its state - 64 lazy starts ('if st.x == null { st.x = ... }' inside a getter) are the state's defaults, gear__ensure is gone, and ludic migrate state --tighten took mut off 208 package parameters: things_all, thing_find, gear_charge, gear_level, jobs_state and the rest read

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Orkun ÇAKILKAYA 2026-09-27 00:51:03 +03:00
parent 54f5efb23f
commit 9862ec82e3
102 changed files with 320 additions and 351 deletions

View file

@ -46,4 +46,4 @@ export function update_plan_version(update_st: UpdateState, i: int) -> string {
export function update_target(update_st: UpdateState) -> string { return update_st.update__target }
export function update_total_bytes(update_st: UpdateState) -> int { return update_st.update__total_bytes }
function update__path(update_st: mut UpdateState, i: int) -> string { return update_packages(update_st) + update__sep() + update_st.update__files[i] }
function update__path(update_st: UpdateState, i: int) -> string { return update_packages(update_st) + update__sep() + update_st.update__files[i] }

View file

@ -44,7 +44,7 @@ function update__up(p: string) -> string {
# the executable's directory
export function update_dir() -> string { return update__up(UpdateWorld.exe()) }
export function update_root(update_st: mut UpdateState) -> string {
export function update_root(update_st: UpdateState) -> string {
let c = update__conf(update_st)
if len(c.root) > 0 { return c.root }
if update__mac() { return update__up(update__up(update_dir())) }
@ -52,7 +52,7 @@ export function update_root(update_st: mut UpdateState) -> string {
}
# where the packages live: never inside a macOS bundle, which is read-only and which apply replaces
export function update_packages(update_st: mut UpdateState) -> string {
export function update_packages(update_st: UpdateState) -> string {
let c = update__conf(update_st)
if len(c.packages) > 0 { return c.packages }
if update__mac() and len(c.mac_packages) > 0 { return c.mac_packages }
@ -64,7 +64,7 @@ function update__feed_file() -> string {
return "releases.win.json"
}
function update__updater(update_st: mut UpdateState) -> string {
function update__updater(update_st: UpdateState) -> string {
if update__mac() { return update_root(update_st) + "/Contents/MacOS/UpdateMac" }
return update_root(update_st) + update__sep() + "Update.exe"
}
@ -76,7 +76,7 @@ export function update_translocated() -> bool {
}
# can this copy update itself? A copy Velopack did not install downloads the game again instead.
export function update_installed(update_st: mut UpdateState) -> bool {
export function update_installed(update_st: UpdateState) -> bool {
if len(update__conf(update_st).root) > 0 { return true }
if update_translocated() { return false }
if update__mac() { return Fs.exists(update_dir() + "/UpdateMac") }

View file

@ -10,7 +10,7 @@ property UpdateAsset {
}
# this app's packages in the feed ({"Assets": [{PackageId, Version, Type, FileName, SHA256, Size}]})
function update__assets(update_st: mut UpdateState, feed: Val) -> []UpdateAsset {
function update__assets(update_st: UpdateState, feed: Val) -> []UpdateAsset {
let out = new []UpdateAsset
if feed == null or Value.kind(feed) != 6 or Value.has(feed, "Assets") == 0 { return out }
let all = Value.get(feed, "Assets")
@ -31,7 +31,7 @@ function update__assets(update_st: mut UpdateState, feed: Val) -> []UpdateAsset
# What the feed calls the FULL package of version v. Never built here: Velopack puts the channel in
# a macOS name (App-0.3.4-osx-full.nupkg) and not a Windows one, and it is both the name a patch
# writes and the name the next update looks for as its base.
function update__full_name(update_st: mut UpdateState, as: []UpdateAsset, v: string) -> string {
function update__full_name(update_st: UpdateState, as: []UpdateAsset, v: string) -> string {
for i in 0 .. len(as) { if not as[i].delta and as[i].ver == v { return as[i].file } }
return update__conf(update_st).app_id + "-" + v + "-full.nupkg"
}
@ -46,7 +46,7 @@ function update__newest_full(as: []UpdateAsset) -> int {
}
# the deltas above this version up to the newest, oldest first
function update__chain(update_st: mut UpdateState, as: []UpdateAsset, newest: string) -> []UpdateAsset {
function update__chain(update_st: UpdateState, as: []UpdateAsset, newest: string) -> []UpdateAsset {
let out = new []UpdateAsset
let mine = update__conf(update_st).version
for i in 0 .. len(as) {
@ -65,7 +65,7 @@ function update__chain(update_st: mut UpdateState, as: []UpdateAsset, newest: st
return out
}
function update__fulls_after(update_st: mut UpdateState, as: []UpdateAsset) -> int {
function update__fulls_after(update_st: UpdateState, as: []UpdateAsset) -> int {
var n = 0
for i in 0 .. len(as) { if not as[i].delta and update_newer(as[i].ver, update__conf(update_st).version) { n += 1 } }
return n

View file

@ -56,7 +56,7 @@ export state UpdateState {
update__ask_h: int = -1
update__latest: string = ""
update__notes: Val = null
update__cfg: UpdateConfig = null
update__cfg: UpdateConfig = new UpdateConfig
update__state: int = 0
update__err: int = 0
update__h: int = -1 # the request
@ -77,22 +77,20 @@ export state UpdateState {
update__rate: int = 0 # bytes a second, eased
update__rate_t: int = -1
update__rate_bytes: int = 0
update__facts: Queue<UpdateFact> = null
update__facts: Queue<UpdateFact> = update__facts__new()
}
export function update_config(update_st: mut UpdateState, c: UpdateConfig) -> void { update_st.update__cfg = c }
function update__conf(update_st: mut UpdateState) -> UpdateConfig {
if update_st.update__cfg == null { update_st.update__cfg = new UpdateConfig }
function update__conf(update_st: UpdateState) -> UpdateConfig {
return update_st.update__cfg
}
export function update_facts(update_st: mut UpdateState) -> Queue<UpdateFact> {
if update_st.update__facts == null { update_st.update__facts = queue_new("update.facts") }
export function update_facts(update_st: UpdateState) -> Queue<UpdateFact> {
return update_st.update__facts
}
function update__fact(update_st: mut UpdateState, what: int) -> void {
function update__fact(update_st: UpdateState, what: int) -> void {
let f = new UpdateFact
f.what = what
f.error = update_st.update__err
@ -101,3 +99,4 @@ function update__fact(update_st: mut UpdateState, what: int) -> void {
f.bytes = update_st.update__total_bytes
q_push(update_facts(update_st), f)
}
function update__facts__new() -> Queue<UpdateFact> { return queue_new("update.facts") }

View file

@ -50,7 +50,7 @@ function update__fetch(update_st: mut UpdateState, i: int) -> void {
update_st.update__state = UPDATE_FETCH
}
function update__hash_file(update_st: mut UpdateState) -> string {
function update__hash_file(update_st: UpdateState) -> string {
if len(update__conf(update_st).scratch) > 0 { return update__conf(update_st).scratch }
return Os.temp_dir() + "/ludic-update-hash.txt"
}
@ -80,7 +80,7 @@ function update__check(update_st: mut UpdateState, i: int) -> void {
}
# the hash the child wrote: the first line with anything on it
function update__hash_read(update_st: mut UpdateState) -> string {
function update__hash_read(update_st: UpdateState) -> string {
let s = Fs.read_text(update__hash_file(update_st))
if s == null { return "" }
let lines = Text.split(s, "\n")

View file

@ -89,7 +89,7 @@ program UpdateTest {
function seed_base() -> void { Fs.write_text(pkgs() + "/Game-1.0.0-osx-full.nupkg", "base") }
function plan_of(update_st: mut UpdateState, text: string) -> bool { return update_plan(update_st, Json.parse(text)) }
function facts_of(update_st: mut UpdateState, what: int) -> int {
function facts_of(update_st: UpdateState, what: int) -> int {
let fs = q_drain(update_facts(update_st))
var n = 0
for i in 0 .. len(fs) { if fs[i].what == what { n += 1 } }