ludic migrate state packages <every example program> packages/ludic.lab/example/plate.ludic 1804 vars into 126 states, 64 into lets; 23498 edits in 460 files Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
51 lines
2.4 KiB
Text
51 lines
2.4 KiB
Text
# order.ludic - the roll's order and its pages. Forty frames is a pile in taking order; once a frame
|
|
# has a grade the useful question is which are the best. The index is mapped, never the roll resorted.
|
|
export const PHOTO_NEWEST: int = 0
|
|
export const PHOTO_BEST: int = 1
|
|
export const PHOTO_BY_SUBJECT: int = 2
|
|
export const PHOTO_PAGE: int = 8
|
|
|
|
|
|
export function photo_sort(photo_st: PhotoState) -> int { return photo_st.pht_sort }
|
|
export function photo_sort_next(photo_st: mut PhotoState) -> void { photo_st.pht_sort = (photo_st.pht_sort + 1) % 3 }
|
|
export function photo_sort_set(photo_st: mut PhotoState, s: int) -> void { photo_st.pht_sort = Math.clamp(s, 0, 2) }
|
|
|
|
# the roll in the chosen order: newest first, best first, or by subject
|
|
export function photo_order(photo_st: mut PhotoState) -> []int {
|
|
photo_st.pht_order = new []int
|
|
for i in 0 .. photo_st.pht_n { push(photo_st.pht_order, i) }
|
|
if photo_st.pht_sort == PHOTO_NEWEST {
|
|
for i in 0 .. photo_st.pht_n { photo_st.pht_order[i] = photo_st.pht_n - 1 - i }
|
|
return photo_st.pht_order
|
|
}
|
|
for i in 0 .. photo_st.pht_n {
|
|
var best = i
|
|
for k in i + 1 .. photo_st.pht_n { if pht_before(photo_st, photo_st.pht_order[k], photo_st.pht_order[best]) { best = k } }
|
|
let t = photo_st.pht_order[i]
|
|
photo_st.pht_order[i] = photo_st.pht_order[best]
|
|
photo_st.pht_order[best] = t
|
|
}
|
|
return photo_st.pht_order
|
|
}
|
|
|
|
function pht_before(photo_st: PhotoState, a: int, b: int) -> bool {
|
|
if photo_st.pht_sort == PHOTO_BEST { return photo_st.pht_grade[a] > photo_st.pht_grade[b] }
|
|
return photo_st.pht_mask[a] < photo_st.pht_mask[b]
|
|
}
|
|
|
|
export function photo_pages(photo_st: PhotoState) -> int { return (photo_st.pht_n + PHOTO_PAGE - 1) / PHOTO_PAGE }
|
|
export function photo_page_now(photo_st: PhotoState) -> int { return photo_st.pht_page }
|
|
export function photo_page_step(photo_st: mut PhotoState, d: int) -> void { photo_st.pht_page = Math.clamp(photo_st.pht_page + d, 0, Math.max(photo_pages(photo_st) - 1, 0)) }
|
|
|
|
# a page of the roll, in its order; the page is held inside the roll
|
|
export function photo_page_list(photo_st: mut PhotoState) -> []int {
|
|
let out = new []int
|
|
if photo_st.pht_n == 0 { return out }
|
|
let order = photo_order(photo_st)
|
|
if photo_st.pht_page >= photo_pages(photo_st) { photo_st.pht_page = photo_pages(photo_st) - 1 }
|
|
for k in 0 .. PHOTO_PAGE {
|
|
let oi = photo_st.pht_page * PHOTO_PAGE + k
|
|
if oi < photo_st.pht_n { push(out, order[oi]) }
|
|
}
|
|
return out
|
|
}
|