plum

#treesitter#compiler#wasm

git clone https://git.pyrossh.dev/plum

A statically typed, imperative programming language inspired by rust, python


257d46e — Peter John 2026-11-13T22:13:34+05:30
views as blocks, place defaults, one-pass upcast spreads, a bad default reported once: each view is one literal, one item a line with no commas, and a parent's children are its block: orbitrunner's play (`if self.over then Overlay(w: Arena.W, h: Arena.H) {` + the two labels + `}`) and ship, balloonpop's playground, hud and party, a balloon's view (its burst is `..Range.until(0, 8).map(|i| spark(i, reach, ..))`, the recursive `burst` gone), a cloud is a `Group(x: x, y: y) {` + three circles about its origin + `}` (it was three circles at absolute places, spread), the web-test stress fixture (`Scaled(scale: 0.8) {` + five spreads + `}`, each `Spinner(..) { ..dancers }`), the turn fixture, tests/port/game/screens (the `base.append([Overlay(..)])` is an `if` item), std/game's Overlay and View tests, the Overlay and Group doc comments; `Box`, `Circle`, `Label` and `Sprite` default `x: 0.0, y: 0.0`, as `Group` and `Overlay` already did, since an actor's own view draws at its place (`Sprite(tex: self.tex, ..)`), and every `x: 0.0`/`y: 0.0` of the six kinds is left out (std, games, tests, fixtures, scale benchmark, docs; tests that each kind is at the origin unless placed); a spread of a list that is upcast (`..self.mines`, a `List<Mine>` in a `List<View>` literal) is one pass: `lowerUpcasts` (checker/upcasts.rs) makes `xs.spreadOnto(rest)` with an upcast receiver a call of a helper made once per pair, `__upcastOnto0(xs, rest)` (`Nil => rest`, `Cons(h, t) => Cons(head: h, tail: __upcastOnto0(t, rest))`, a TRMC loop), not an upcast and then a copy; `list_items::SPREAD_ONTO` names the method for both; measured on benchmarks/screen_views/spread.plum (new: a 10,000-item `List<Dot>` spread into a `List<Shape>`, 200 passes): 16.6 ms before (fusion had merged the two there) and 16.8 ms after, 25.2 ms and 16.9 ms with `--no-fusion`; Orbit Runner's `paint` (orbit.plum, where fusion merged only some): 137 ms before, 132.5 ms after, checksum 925878360 unchanged; scale.plum has a `spread` mode (the 10,000 actors held as a `List<ViewDot>`, drawn through `[..self.dots, Box(..)]`; 353 ms like `view`, the draw dominates); a field default of the wrong type is reported once, at the default: `checkFieldDefaults` records each one that fails (`bad_defaults`, by constructor and field, with its span) and a construction's copy of it (the same span) is not checked again, while a wrong value given by name still is; docs: game.md (the view sample with a block, children as a block, Balloon Pop's cloud groups, the kinds table's place defaults, a kind of your own puts `children` last, the "Beside master" row), language.md (a spread of an upcast list is one pass); tests: diagnostics for the default reported once
benchmarks/screen_views/scale.plum CHANGED
@@ -6,8 +6,10 @@
6
6
  # `stepped` (`Views.stepIn` over its list); the tick action does nothing. One difference
7
7
  # from master: master's stepping walk makes each actor's view to look under it, and this
8
8
  # branch's does not (an actor found under another could not be put back into a value), so
9
- # `update view` makes 10,000 fewer one-`Sprite` lists a tick here. 20 ticks to warm up,
9
+ # `update view` makes 10,000 fewer one-`Sprite` lists a tick here. With `spread`, the
10
+ # screen holds the actors as a `List<ViewDot>` and its view is `[..self.dots, Box(..)]`: a
11
+ # spread that is upcast to a `List<View>` and copied in front of the box at each draw. 20
10
- # then 200 timed.
12
+ # ticks to warm up, then 200 timed.
11
13
  #
12
14
  # update each tick through the game (`Game.update`)
13
15
  # paint each tick, then the frame (`Game.draw`). Run with PLUM_NULL_GFX=1: there is no
@@ -20,6 +22,7 @@
20
22
  # PLUM_NULL_GFX=1 ./scale update view
21
23
  # PLUM_NULL_GFX=1 ./scale paint view
22
24
  # PLUM_NULL_GFX=1 ./scale paint hand
25
+ # PLUM_NULL_GFX=1 ./scale paint spread
23
26
  module scale_bench
24
27
 
25
28
  import std/Int
@@ -38,6 +41,7 @@ import std/game/Input
38
41
  import std/game/Place
39
42
  import std/game/View
40
43
  import std/game/Sprite
44
+ import std/game/Box
41
45
  import std/game/Screen
42
46
  import std/game/ScreenSlice
43
47
  import std/game/Game
@@ -64,6 +68,10 @@ primitive ScaleBench[App] =
64
68
  CrowdScreen as c => c
65
69
  _ => CrowdScreen(hand: false, dots: Nil)
66
70
 
71
+ fun frameSumOf(g: Game) -> Int = match g.screen()
72
+ SpreadScreen as s => s.frameSum()
73
+ _ => ScaleBench.crowdOf(g).frameSum()
74
+
67
75
  fun tickOnce(io: Io, g: Game, paint: Bool) -> Game =
68
76
  next := g.update(io, Input.create(), Clock.Tick)
69
77
  if paint
@@ -79,12 +87,13 @@ primitive ScaleBench[App] =
79
87
  args := io.args()
80
88
  paint := args.length() > 0 && args.at(0) == "paint"
81
89
  hand := args.length() > 1 && args.at(1) == "hand"
90
+ spread := args.length() > 1 && args.at(1) == "spread"
82
- only: Screen := CrowdScreen.of(hand, ScaleBench.Count)
91
+ only: Screen := if spread then SpreadScreen.of(ScaleBench.Count) else CrowdScreen.of(hand, ScaleBench.Count)
83
92
  warm := Range.until(0, 20).fold(Game(screens: [only]), |g, t| ScaleBench.tickOnce(io, g, paint))
84
93
  t0 := io.nowMicros()
85
94
  done := Range.until(0, 200).fold(warm, |g, t| ScaleBench.tickOnce(io, g, paint))
86
95
  total := io.nowMicros() - t0
87
- io.printLn("us {Int(total)} ticks 200 checksum {ScaleBench.crowdOf(done).frameSum()}")
96
+ io.printLn("us {Int(total)} ticks 200 checksum {ScaleBench.frameSumOf(done)}")
88
97
 
89
98
  struct ViewDot[Actor](i: Int, at: Place, clock: Float) =
90
99
  fun of(i: Int) -> ViewDot = ViewDot(i: i, at: Place.at(Float(i % 100) * 8.0, Float(i / 100) * 6.0), clock: 0.0)
@@ -94,7 +103,7 @@ struct ViewDot[Actor](i: Int, at: Place, clock: Float) =
94
103
  fun step(self, dt: Float) -> ViewDot = ViewDot(..self, clock: self.clock + dt)
95
104
 
96
105
  fun view(self) -> List<View> =
97
- [Sprite(x: 0.0, y: 0.0, tex: Texture(id: 1), w: 16.0, h: 16.0, srcX: 0.0, srcY: 0.0, srcW: 16.0, srcH: 16.0, frame: Int(self.clock * 8.0) % 4, tint: Color.White, touch: Disabled)]
106
+ [Sprite(tex: Texture(id: 1), w: 16.0, h: 16.0, srcX: 0.0, srcY: 0.0, srcW: 16.0, srcH: 16.0, frame: Int(self.clock * 8.0) % 4, tint: Color.White, touch: Disabled)]
98
107
 
99
108
  struct HandDot[Actor](i: Int, at: Place, clock: Float) =
100
109
  fun of(i: Int) -> HandDot = HandDot(i: i, at: Place.at(Float(i % 100) * 8.0, Float(i / 100) * 6.0), clock: 0.0)
@@ -124,3 +133,22 @@ struct CrowdScreen[ScreenSlice<CrowdAct>](hand: Bool, dots: List<View>) =
124
133
  CrowdTick(dt) => self
125
134
 
126
135
  fun frameSum(self) -> Int = Timing.hash(self.dots.map(|d| ScaleBench.frameOf(d)))
136
+
137
+ struct SpreadScreen[ScreenSlice<CrowdAct>](dots: List<ViewDot>) =
138
+ fun of(n: Int) -> SpreadScreen = SpreadScreen(dots: Range.until(0, n).map(|i| ViewDot.of(i)))
139
+
140
+ fun name(self) -> Str = "spread"
141
+
142
+ fun view(self) -> List<View> = [
143
+ ..self.dots
144
+ Box(w: 800.0, h: 4.0, color: Color.White)
145
+ ]
146
+
147
+ fun stepped(self, dt: Float) -> SpreadScreen = SpreadScreen(..self, dots: Views.stepAll(self.dots, dt))
148
+
149
+ fun tick(self, dt: Float) -> Option<CrowdAct> = Some(CrowdTick(dt: dt))
150
+
151
+ fun reduce(self, a: CrowdAct) -> SpreadScreen = match a
152
+ CrowdTick(dt) => self
153
+
154
+ fun frameSum(self) -> Int = Timing.hash(self.dots.map(|d| Int(d.clock * 8.0) % 4))
benchmarks/screen_views/spread.plum ADDED
@@ -0,0 +1,43 @@
1
+ # A spread that is upcast: `[..dots, Sq(k: k)]` where `dots` is a `List<Dot>` and the literal
2
+ # a `List<Shape>`, as a view spreads `..self.mines` into its `List<View>`. 10,000 dots, 200
3
+ # passes; it prints `us <total> items <n> checksum <c>`.
4
+ #
5
+ # plum build benchmarks/screen_views/spread.plum -o spread
6
+ # ./spread
7
+ #
8
+ # 2026-11-13, debug compiler, wasmtime: before the spread of an upcast list was one helper
9
+ # (`__upcastOnto0(dots, rest)`, checker/upcasts.rs), it was an upcast and then a copy:
10
+ # 16.6 ms (fusion merged the two here) and 25.2 ms with `--no-fusion`; after, 16.8 ms and
11
+ # 16.9 ms. Orbit Runner's `paint` (orbit.plum, whose view spreads its mines, orbs and rings,
12
+ # where fusion had merged only some): 137 ms before, 132.5 ms after, checksum 925878360.
13
+ import std/Int
14
+ import std/Float
15
+ import std/Str
16
+ import std/Io
17
+ import std/Option
18
+ import std/collections/List
19
+ import std/App
20
+
21
+ trait Shape =
22
+ fun area(self) -> Int
23
+
24
+ struct Dot[Shape](r: Int) =
25
+ fun area(self) -> Int = self.r
26
+
27
+ struct Sq[Shape](k: Int) =
28
+ fun area(self) -> Int = self.k * self.k
29
+
30
+ primitive SpreadBench[App] =
31
+ fun scene(dots: List<Dot>, k: Int) -> List<Shape> = [
32
+ ..dots
33
+ Sq(k: k)
34
+ ]
35
+
36
+ fun main(io: Io) =
37
+ dots := Range.until(0, 10000).map(|i| Dot(r: i % 7))
38
+ t0 := io.nowMicros()
39
+ sum := Range.until(0, 200).fold(0, |acc, p|
40
+ shapes := SpreadBench.scene(dots, p)
41
+ acc + shapes.length() + shapes.get(p * 50).map(|s| s.area()).unwrapOr(0))
42
+ total := io.nowMicros() - t0
43
+ io.printLn("us {Int(total)} items {200 * 10001} checksum {sum}")
compiler/checker/src/callcheck.rs CHANGED
@@ -143,6 +143,11 @@ pub(crate) fn inferClassCallRaw(
143
143
  // and again when every field has had its say.
144
144
  let mut open: Vec<(PlumType, PlumType)> = Vec::new();
145
145
  for fa in others.into_iter().chain(closures) {
146
+ // A copy of a default that failed where it is declared: reported there.
147
+ let bad = withCheck(|s| s.bad_defaults.borrow().get(&(call.type_name.clone(), fa.name.clone())) == Some(&fa.value.span));
148
+ if bad {
149
+ continue;
150
+ }
146
151
  match info.field_names.iter().position(|n| n == &fa.name) {
147
152
  Some(i) => {
148
153
  let pat = types::substitute(&info.field_types[i], &owner);
compiler/checker/src/fncheck.rs CHANGED
@@ -114,13 +114,13 @@ pub(crate) fn checkFieldDefaults(source: &ast::Source, global_env: &TypeEnv, ctx
114
114
  let at = (e.line, e.column);
115
115
  let say = |msg: String| format!("{} '{}': default of field '{}': {}", what, v.name, field, msg);
116
116
  let (r, pos, resolution) = withFailure(|| inferExprWith(&d, &env, ctx, Some(&declared)));
117
- match r {
117
+ let failed = match r {
118
- Ok(t) => {
119
- if let Err(msg) = unifyArg(&declared, &t, &d, ctx) {
120
- errors.push(failureError(spanOf(&d), false, at, say(msg)));
118
+ Ok(t) => unifyArg(&declared, &t, &d, ctx).err().map(|msg| failureError(spanOf(&d), false, at, say(msg))),
121
- }
122
- }
123
- Err(msg) => errors.push(failureError(pos, resolution, at, say(msg))),
119
+ Err(msg) => Some(failureError(pos, resolution, at, say(msg))),
120
+ };
121
+ if let Some(err) = failed {
122
+ errors.push(err);
123
+ withCheck(|s| s.bad_defaults.borrow_mut().insert((v.name.clone(), field.clone()), d.span));
124
124
  }
125
125
  if let Some(p) = prev {
126
126
  setCurrentFile(&p);
compiler/checker/src/state.rs CHANGED
@@ -86,6 +86,10 @@ pub(crate) struct CheckState {
86
86
  pub(crate) bad_arity: RefCell<std::collections::HashSet<(String, usize)>>,
87
87
  /// The names of the top-level functions and constants (the keys of the global env).
88
88
  pub(crate) globals: RefCell<std::collections::HashSet<String>>,
89
+ /// The field defaults that failed their check where they are declared, by (constructor,
90
+ /// field), with the span of the default: a construction's copy of one (the same span)
91
+ /// is not checked again, so the error is reported once (`checkFieldDefaults`).
92
+ pub(crate) bad_defaults: RefCell<HashMap<(String, String), plum_core::ast::Span>>,
89
93
  pub(crate) scope_site: RefCell<Option<(String, usize, String)>>,
90
94
  /// The traits of the program being checked (`traits::buildTraits`).
91
95
  pub(crate) traits: RefCell<std::rc::Rc<crate::traits::Traits>>,
compiler/checker/src/upcasts.rs CHANGED
@@ -20,6 +20,11 @@
20
20
  //!
21
21
  //! which TRMC makes a loop, the same work as `xs.map(|x| x)`. A value already of the wider
22
22
  //! type is no site and costs nothing.
23
+ //!
24
+ //! A list literal's spread of such a list, `xs.spreadOnto(rest)` with `xs` upcast, is one
25
+ //! pass, not an upcast and then a copy: a helper made for the pair builds the wider cells in
26
+ //! front of `rest` (`__upcastOnto0(xs, rest)`, `Nil => rest`, `Cons(h, t) => Cons(head: h,
27
+ //! tail: __upcastOnto0(t, rest))`).
23
28
 
24
29
  use crate::loops::astTypeOf;
25
30
  use crate::*;
@@ -259,6 +264,43 @@ pub(crate) fn literalJoin(call: &ast::ClassCall, env: &TypeEnv, ctx: &CheckCtx)
259
264
  pub(crate) fn lowerUpcasts(source: &ast::Source, ups: &mut BTreeMap<ast::NodeId, (PlumType, PlumType)>) -> ast::Source {
260
265
  let mut out = source.clone();
261
266
  let mut helpers = Helpers { made: HashMap::new(), items: Vec::new(), source };
267
+ // A spread of an upcast list first: the upcast and the copy are one helper.
268
+ let mut fuse = |e: &mut ast::Expr| {
269
+ let ast::ExprKind::Attribute(a) = &mut e.kind else { return };
270
+ let ast::AttrKind::Method(m) = &mut a.attr else { return };
271
+ if m.name != plum_core::list_items::SPREAD_ONTO || m.args.len() != 1 {
272
+ return;
273
+ }
274
+ match ups.get(&a.object.id) {
275
+ Some((PlumType::TApp(n, _), _)) if n == "List" => {}
276
+ _ => return,
277
+ }
278
+ let (to, from) = ups.remove(&a.object.id).expect("checked above");
279
+ let ast::Arg::Positional(rest) = m.args.remove(0) else { unreachable!("a spread's rest is positional") };
280
+ let object = std::mem::replace(&mut a.object, ast::Expr::TypeName(String::new()));
281
+ let name = helpers.onto(&to, &from);
282
+ let span = e.span;
283
+ let mut fused = call(&name, object);
284
+ if let ast::ExprKind::FnCall(c) = &mut fused.kind {
285
+ c.args.push(ast::Arg::Positional(rest));
286
+ }
287
+ *e = fused;
288
+ e.span = span;
289
+ };
290
+ for item in &mut out.items {
291
+ match item {
292
+ ast::Item::Fn(f) => {
293
+ for p in &mut f.params {
294
+ if let Some(d) = &mut p.default {
295
+ plum_core::forms::mapExprsIn(d, &mut fuse);
296
+ }
297
+ }
298
+ plum_core::forms::mapExprs(&mut f.body, &mut fuse);
299
+ }
300
+ ast::Item::Const(c) => plum_core::forms::mapExprsIn(&mut c.value, &mut fuse),
301
+ _ => {}
302
+ }
303
+ }
262
304
  let mut wrap = |e: &mut ast::Expr| {
263
305
  let Some((to, from)) = ups.remove(&e.id) else { return };
264
306
  let name = helpers.helper(&to, &from);
@@ -366,6 +408,58 @@ impl Helpers<'_> {
366
408
  name
367
409
  }
368
410
 
411
+ /// The helper that puts the cells of a `from` list, each made a `to`'s, in front of a `to`
412
+ /// list (a spread of an upcast list; see the module doc), made if new.
413
+ fn onto(&mut self, to: &PlumType, from: &PlumType) -> String {
414
+ let key = (PlumType::TApp("onto".to_string(), vec![to.clone()]), from.clone());
415
+ if let Some(n) = self.made.get(&key) {
416
+ return n.clone();
417
+ }
418
+ let name = format!("__upcastOnto{}", self.made.len());
419
+ self.made.insert(key, name.clone());
420
+ let (PlumType::TApp(_, tos), PlumType::TApp(_, froms)) = (to, from) else {
421
+ unreachable!("an upcast is between two instances of one container")
422
+ };
423
+ let h = ast::Expr::Var("__h".to_string());
424
+ let head = if upcastable(&tos[0], &froms[0]) { call(&self.helper(&tos[0], &froms[0]), h) } else { h };
425
+ let mut rest = call(&name, ast::Expr::Var("__t".to_string()));
426
+ if let ast::ExprKind::FnCall(c) = &mut rest.kind {
427
+ c.args.push(ast::Arg::Positional(ast::Expr::Var("__rest".to_string())));
428
+ }
429
+ let (none, some) = self.variants("List");
430
+ let cases = vec![
431
+ case(&none.0, vec![], ast::Expr::Var("__rest".to_string())),
432
+ case(&some.0, vec!["__h", "__t"], build(&some, vec![head, rest])),
433
+ ];
434
+ let x = ast::Expr::Var("__xs".to_string());
435
+ let body = ast::Block { stmts: vec![ast::Stmt::Match(ast::Match { subjects: vec![x], cases })] };
436
+ let mut generics = Vec::new();
437
+ let param = |n: &str, t: &PlumType, generics: &mut Vec<String>| ast::Param {
438
+ name: n.to_string(),
439
+ ty: ast::ParamType::Type(astTypeOf(t, generics).expect("an upcast's types are closed")),
440
+ default: None,
441
+ };
442
+ let params = vec![param("__xs", from, &mut generics), param("__rest", to, &mut generics)];
443
+ self.items.push(ast::Item::Fn(ast::Fn {
444
+ name: name.clone(),
445
+ file: self.source.file.clone(),
446
+ line: 0,
447
+ column: 0,
448
+ type_param: None,
449
+ generics: vec![],
450
+ bounds: vec![],
451
+ is_extern: false,
452
+ is_export: false,
453
+ is_test: false,
454
+ is_fip: false,
455
+ has_self: false,
456
+ params,
457
+ returns: Some(astTypeOf(to, &mut generics).expect("an upcast's types are closed")),
458
+ body: ast::FnBody::Block(body),
459
+ }));
460
+ name
461
+ }
462
+
369
463
  /// The container's empty variant and its other one, with that one's field names
370
464
  /// (`Nil`, `Cons(head, tail)`; `None`, `Some(value)`), as declared.
371
465
  fn variants(&self, kind: &str) -> ((String, Vec<String>), (String, Vec<String>)) {
compiler/checker/tests/checker/diagnostic_tests.rs CHANGED
@@ -376,3 +376,15 @@ fn aBlockOpensOnTheCallsLine() {
376
376
  let es = errors("struct P(x: Int, xs: List<Int>)\n\nprimitive Main[App] =\n fun main() -> Int =\n p := P(x: 1)\n { 2 }\n");
377
377
  assert!(es.iter().any(|e| e.message.contains("missing field 'xs'")), "{es:?}");
378
378
  }
379
+
380
+ /// A default of the wrong type is reported once, where it is declared, not again at each
381
+ /// construction that leaves the field out; a wrong value given by name still is.
382
+ #[test]
383
+ fn aBadFieldDefaultIsReportedOnce() {
384
+ let es = errors("struct P(x: Int, y: Int = \"no\")\n\nprimitive Main[App] =\n fun main() -> Int = P(x: 1).y + P(x: 2).y\n\n fun other() -> Int = P(x: 3).y\n");
385
+ assert_eq!(es.len(), 1, "{es:?}");
386
+ assert_eq!((es[0].line, es[0].column), (1, 27), "{es:?}");
387
+ let es = errors("struct P(x: Int, y: Int = \"no\")\n\nprimitive Main[App] =\n fun main() -> Int = P(x: 1, y: \"s\").y\n");
388
+ assert_eq!(es.len(), 2, "{es:?}");
389
+ assert!(es[1].message.contains("variant 'P' field 'y'"), "{es:?}");
390
+ }
compiler/core/src/list_items.rs CHANGED
@@ -20,6 +20,9 @@
20
20
  //! (`if c then ..xs` binds `xs` in a `Some` the same way and spreads it in a `match`).
21
21
  use crate::ast::*;
22
22
 
23
+ /// The method a spread is a call of: `xs.spreadOnto(rest)`.
24
+ pub const SPREAD_ONTO: &str = "spreadOnto";
25
+
23
26
  /// One item of a list literal.
24
27
  pub enum ListItem {
25
28
  Value(Expr),
@@ -84,7 +87,7 @@ fn spreadOnto(xs: Expr, rest: Expr, line: usize, column: usize) -> Expr {
84
87
  Expr::Attribute(Box::new(AttributeExpr {
85
88
  object: xs,
86
89
  attr: AttrKind::Method(FnCall {
87
- name: "spreadOnto".to_string(),
90
+ name: SPREAD_ONTO.to_string(),
88
91
  args: vec![Arg::Positional(rest)],
89
92
  line,
90
93
  column,
compiler/game/tests/fixtures/turn_fixture.plum CHANGED
@@ -25,7 +25,12 @@ struct Turned[View](children: List<View>) =
25
25
  struct TurnScreen[Screen](n: Int) =
26
26
  fun name(self) -> Str = "turn"
27
27
 
28
- fun view(self) -> List<View> = [Turned(children: [Box(x: 0.0, y: 0.0, w: 40.0, h: 20.0, color: Color.Red), Label(x: 0.0, y: 0.0, text: "hi", size: 10.0)])]
28
+ fun view(self) -> List<View> = [
29
+ Turned() {
30
+ Box(w: 40.0, h: 20.0, color: Color.Red)
31
+ Label(text: "hi", size: 10.0)
32
+ }
33
+ ]
29
34
 
30
35
  fun hud(self, window: Vec2) -> List<View> = [Label(x: 5.0, y: 5.0, text: "hud", size: 10.0)]
31
36
 
compiler/game/web-test/fixtures/stress_state_view.plum CHANGED
@@ -98,14 +98,16 @@ struct ViewScreen[ScreenSlice<StressAction>](clock: Float, frames: Int, clicks:
98
98
  fun background(self) -> Color = Color.rgb(0.05, 0.06, 0.1)
99
99
 
100
100
  fun view(self) -> List<View> = [
101
- Scaled(scale: 0.8, children: [
101
+ Scaled(scale: 0.8) {
102
- ..Range.until(0, StressStateView.Groups).map(|gi| self.spinner(gi)),
102
+ ..Range.until(0, StressStateView.Groups).map(|gi| self.spinner(gi))
103
- ..Range.until(0, StressStateView.Pulsers).map(|i| self.pulser(i)),
103
+ ..Range.until(0, StressStateView.Pulsers).map(|i| self.pulser(i))
104
- ..Range.until(0, StressStateView.Rects).map(|i| self.rect(i)),
104
+ ..Range.until(0, StressStateView.Rects).map(|i| self.rect(i))
105
- ..Range.until(0, StressStateView.Circles).map(|i| self.circle(i)),
105
+ ..Range.until(0, StressStateView.Circles).map(|i| self.circle(i))
106
- ..Range.until(0, StressStateView.Texts).map(|i| self.counter(i))]),
106
+ ..Range.until(0, StressStateView.Texts).map(|i| self.counter(i))
107
+ }
107
- ..self.buttons,
108
+ ..self.buttons
108
- ..Range.until(0, StressStateView.Buttons).map(|i| self.buttonLabel(i))]
109
+ ..Range.until(0, StressStateView.Buttons).map(|i| self.buttonLabel(i))
110
+ ]
109
111
 
110
112
  fun onPress(self, target: View, at: Vec2) -> Option<StressAction> =
111
113
  Range.until(0, StressStateView.Buttons).find(|i| @sameRef(target, self.buttons.at(i))).map(|i| Clicked(i: i))
@@ -117,7 +119,9 @@ struct ViewScreen[ScreenSlice<StressAction>](clock: Float, frames: Int, clicks:
117
119
  Clicked(_) => ViewScreen(..self, clicks: self.clicks + 1)
118
120
 
119
121
  fun spinner(self, gi: Int) -> View =
122
+ Spinner(x: Float(gi % 10 * 160), y: Float(gi / 10 * 180), rotation: 0.24 * self.clock) {
120
- Spinner(x: Float(gi % 10 * 160), y: Float(gi / 10 * 180), rotation: 0.24 * self.clock, children: Range.until(0, StressStateView.Sprites / StressStateView.Groups).map(|j| self.dancer(gi, j)))
123
+ ..Range.until(0, StressStateView.Sprites / StressStateView.Groups).map(|j| self.dancer(gi, j))
124
+ }
121
125
 
122
126
  fun dancer(self, gi: Int, j: Int) -> View =
123
127
  i := gi * {StressStateView.Sprites / StressStateView.Groups} + j
docs/game.md CHANGED
@@ -41,7 +41,7 @@ enum TapAction = Tapped | Push(dx: Float) | Quit
41
41
  struct Ball[Actor](x: Float, y: Float, vx: Float) =
42
42
  fun place(self) -> Place = Place.at(self.x, self.y)
43
43
 
44
- fun view(self) -> List<View> = [Circle(x: 0.0, y: 0.0, r: 10.0, color: Color.Yellow)]
44
+ fun view(self) -> List<View> = [Circle(r: 10.0, color: Color.Yellow)]
45
45
 
46
46
  fun push(self, vx: Float) -> Ball = Ball(..self, vx: vx)
47
47
 
@@ -88,23 +88,25 @@ A screen's `view(self) -> List<View>` is what the frame shows: a list of views,
88
88
 
89
89
  ```plum
90
90
  fun view(self) -> List<View> = [
91
- Box(x: 0.0, y: 0.0, w: Arena.W, h: Arena.H, color: Color.rgb(0.07, 0.08, 0.16)),
91
+ Box(w: Arena.W, h: Arena.H, color: Color.rgb(0.07, 0.08, 0.16))
92
- ..Range.until(0, Star.Count).map(|i| Star(index: i, clock: self.clock)),
92
+ ..Range.until(0, Star.Count).map(|i| Star(index: i, clock: self.clock))
93
- ..self.mines,
93
+ ..self.mines
94
- ..self.orbs,
94
+ ..self.orbs
95
- if !self.over then self.ship,
95
+ if !self.over then self.ship
96
- ..self.rings,
96
+ ..self.rings
97
- Label(x: 16.0, y: 12.0, text: "Score {self.score}", size: 28.0),
97
+ Label(x: 16.0, y: 12.0, text: "Score {self.score}", size: 28.0)
98
- Label(x: 16.0, y: 44.0, text: "Best {self.best.max(self.score)}", color: Color.Yellow),
98
+ Label(x: 16.0, y: 44.0, text: "Best {self.best.max(self.score)}", color: Color.Yellow)
99
- ..Range.until(0, self.lives).map(|i| Sprite(x: Arena.W - 40.0 - Float(i) * 36.0, y: 12.0, tex: self.assets.sheet, w: 32.0, h: 32.0, srcX: 0.0, srcY: 0.0, srcW: Sheet.Cell, srcH: Sheet.Cell)),
99
+ ..Range.until(0, self.lives).map(|i| Sprite(x: Arena.W - 40.0 - Float(i) * 36.0, y: 12.0, tex: self.assets.sheet, w: 32.0, h: 32.0, srcX: 0.0, srcY: 0.0, srcW: Sheet.Cell, srcH: Sheet.Cell))
100
- if self.over then Overlay(w: Arena.W, h: Arena.H, children: [
100
+ if self.over then Overlay(w: Arena.W, h: Arena.H) {
101
- Label(x: 300.0, y: 258.0, text: "Game over", size: 48.0, color: Color.Red),
101
+ Label(x: 300.0, y: 258.0, text: "Game over", size: 48.0, color: Color.Red)
102
- Label(x: 270.0, y: 316.0, text: "Press Enter to play again", size: 24.0)])]
102
+ Label(x: 270.0, y: 316.0, text: "Press Enter to play again", size: 24.0)
103
+ }
104
+ ]
103
105
  ```
104
106
 
105
- The view is one list literal, its items in drawing order (later items draw over earlier ones). What shows only sometimes is an `if` item (the ship until the run is over, the game over panel once it is), what repeats is a spread of a `map` over a range (forty stars, one icon a life), and a list the screen holds is spread as it is (`..self.mines`). Nothing is annotated: the literal is a `List<View>` because `view` returns one, and each spread `List<Mine>` widens to it (rebuilt as a `List<View>` there; see [Coercion](language.md#coercion) and [list literal items](language.md#lists-slices-and-maps)).
107
+ The view is one list literal, one item a line, its items in drawing order (later items draw over earlier ones). A parent's children are its block: `Overlay(w: .., h: ..) {` + one child a line + `}` is the overlay with those `children` (a construction's block is its last field; see [blocks](language.md#lists-slices-and-maps)), so the view reads as the tree it draws. What shows only sometimes is an `if` item (the ship until the run is over, the game over panel once it is), what repeats is a spread of a `map` over a range (forty stars, one icon a life), and a list the screen holds is spread as it is (`..self.mines`). Nothing is annotated: the literal is a `List<View>` because `view` returns one, and each spread `List<Mine>` widens to it (rebuilt as a `List<View>` there; see [Coercion](language.md#coercion) and [list literal items](language.md#lists-slices-and-maps)).
106
108
 
107
- - **Drawn, not live.** The view is made again every time it is walked (to draw, to hit-test a press), and an item made inside it keeps nothing from one walk to the next. So each takes plain values read from the fields (a `Label`'s `text`, a `Sprite`'s `frame`). A `Group` or an `Overlay` in a view has the children it is made with as its own `view`, and an actor with a view of its own draws that, so views nest.
109
+ - **Drawn, not live.** The view is made again every time it is walked (to draw, to hit-test a press), and an item made inside it keeps nothing from one walk to the next. So each takes plain values read from the fields (a `Label`'s `text`, a `Sprite`'s `frame`). A `Group` or an `Overlay` in a view has the children it is made with (its block) as its own `view`, and an actor with a view of its own draws that, so views nest. Balloon Pop's clouds are groups: `Group(x: x, y: y) {` + three circles placed around the group's origin + `}`.
108
110
  - **Two kinds of item.** An actor the screen holds in a field and names in its view (the ship, each mine of `self.mines`) is the very object in the field when the frame is drawn: a press on it reaches the screen as that object ([Clicks](#clicks)), and `@sameRef(target, self.box)` tells which. The game steps it through the screen's `stepped`, which returns the screen with the actor's next version. An item made inside `view` (the score label, the stars, the game over panel) is a new object every frame, made from the fields.
109
111
  - **What is there, what shows.** An item that is not there is left out (the ship once the run is over). An actor that is there but hides itself for a moment says so with `visible()` (the ship blinking after a hit): it is not drawn or hit, but the screen still steps it.
110
112
  - **The state rule.** `view` only reads; the state changes in the actors' `step`, the screen's `stepped` and the reducer. A screen is a value, so this holds by construction: there is nothing for the draw to change.
@@ -149,7 +151,7 @@ struct Mine[Actor](at: Place, vx: Float, vy: Float, clock: Float, tex: Texture)
149
151
  fun place(self) -> Place = self.at
150
152
 
151
153
  fun view(self) -> List<View> =
152
- [Sprite(x: 0.0, y: 0.0, tex: self.tex, w: Sheet.Size, h: Sheet.Size, srcX: 0.0, srcY: 2.0 * Sheet.Cell, srcW: Sheet.Cell, srcH: Sheet.Cell, frame: Sprite.frameAt(self.clock, 4.0, 4))]
154
+ [Sprite(tex: self.tex, w: Sheet.Size, h: Sheet.Size, srcX: 0.0, srcY: 2.0 * Sheet.Cell, srcW: Sheet.Cell, srcH: Sheet.Cell, frame: Sprite.frameAt(self.clock, 4.0, 4))]
153
155
 
154
156
  fun step(self, dt: Float) -> Mine =
155
157
  moved := Mine(..self, clock: self.clock + dt).put(self.motion().drifted(Mine.Radius, dt))
@@ -189,14 +191,14 @@ The ready-made kinds are made with their fields named, and their fields have def
189
191
 
190
192
  | Kind | Fields | Defaults |
191
193
  |---|---|---|
192
- | `Group` | `x, y, touch, children`: a parent that paints nothing; its children are its `view` | `x: 0.0, y: 0.0, touch: ChildrenOnly` |
193
- | `Box` | `x, y, w, h, color, touch` (x, y its top-left) | `touch: Disabled` |
194
- | `Circle` | `x, y, r, color, touch` (x, y its centre: its bounds are -r to r) | `touch: Disabled` |
195
- | `Sprite` | `x, y, tex, w, h, srcX, srcY, srcW, srcH, frame, tint, touch`; `frame` picks the cell along a strip of `srcW`-wide cells from (`srcX`, `srcY`), and `Sprite.frameAt(clock, fps, count)` is the frame of a looping strip at a clock | `frame: 0, tint: Color.White, touch: Disabled` |
196
- | `Label` | `x, y, text, size, color, align, touch`; `align` puts the text's start (`Left`), middle (`Centre`) or end (`Right`) on `x`, by the width estimate of 0.6 of the size a letter | `size: 20.0, color: Color.White, align: Left, touch: Disabled` |
197
- | `Overlay` | `x, y, w, h, color, touch, children`: a panel that dims what is under it and takes every press inside it, left out of the view while it should not show | `x: 0.0, y: 0.0, color: Overlay.Shade` (black at 0.6 alpha), `touch: Enabled` |
194
+ | `Group` | `x, y, touch, children`: a parent that paints nothing; its children (its block) are its `view` | `x: 0.0, y: 0.0, touch: ChildrenOnly` |
195
+ | `Box` | `x, y, w, h, color, touch` (x, y its top-left) | `x: 0.0, y: 0.0, touch: Disabled` |
196
+ | `Circle` | `x, y, r, color, touch` (x, y its centre: its bounds are -r to r) | `x: 0.0, y: 0.0, touch: Disabled` |
197
+ | `Sprite` | `x, y, tex, w, h, srcX, srcY, srcW, srcH, frame, tint, touch`; `frame` picks the cell along a strip of `srcW`-wide cells from (`srcX`, `srcY`), and `Sprite.frameAt(clock, fps, count)` is the frame of a looping strip at a clock | `x: 0.0, y: 0.0, frame: 0, tint: Color.White, touch: Disabled` |
198
+ | `Label` | `x, y, text, size, color, align, touch`; `align` puts the text's start (`Left`), middle (`Centre`) or end (`Right`) on `x`, by the width estimate of 0.6 of the size a letter | `x: 0.0, y: 0.0, size: 20.0, color: Color.White, align: Left, touch: Disabled` |
199
+ | `Overlay` | `x, y, w, h, color, touch, children`: a panel that dims what is under it and takes every press inside it, left out of the view while it should not show; its children are its block | `x: 0.0, y: 0.0, color: Overlay.Shade` (black at 0.6 alpha), `touch: Enabled` |
198
200
 
199
- A kind of your own that takes children has a `children: List<View>` field and returns it from `view`.
201
+ Every kind is at the origin of what it is in unless given an `x` and a `y`: an actor's own view draws at the actor's place (`Sprite(tex: self.tex, ..)`). A kind of your own that takes children has a `children: List<View>` field, last so that a block fills it, and returns it from `view`.
200
202
 
201
203
  ### How std draws a view
202
204
 
@@ -457,7 +459,7 @@ The engine has master's shape at e91c40ce (`View` and `Actor`, `Screen` with its
457
459
  | the frame sets the host's camera (`setCamera`) for a camera with one scale, and puts a `Stretch` camera into the transform | every camera goes into the transform the view is drawn through, in window pixels, and culling maps its area through it | this branch's draw has always gone through the transform; the host sees no `setCamera`/`resetCamera` in a frame, so the recorder's calls differ (`compiler/game/tests/host_test.rs` checks the pixels) |
458
460
  | the window's size on each tick's input (`input.screen`, `Input.sized`) | `Game.update(io, input, dt)` reads it from `Gfx`; `Game.step(io, input, dt, pixels)` takes it (a test's) | not ported: the replay records the size in its header, as before |
459
461
  | the fixed-timestep driver is `Ticker` (`Ticker.Tick`, `game.ticker.ticks`) | `Clock` (`Clock.Tick`), `game.ticks`, the rig's `t.frame(..)` | named before master's rename; not ported |
460
- | actor and view fields with defaults (`Box(w:, h:)`, `Held(buttons: [])`) | the same: struct fields with defaults (`Label(x:, y:, text:)`, `Held(keys: k)`, `Held()`) | master's `Box` and `Group` default their place and size too; here a `Box`, `Circle`, `Label` or `Sprite` names its `x` and `y` |
462
+ | actor and view fields with defaults (`Box(w:, h:)`, `Held(buttons: [])`) | the same: struct fields with defaults (`Label(x:, y:, text:)`, `Held(keys: k)`, `Held()`) | master's `Box` and `Group` default their size too; here every kind defaults its place (`x: 0.0, y: 0.0`) and names its size |
461
463
  | `Tween` advanced in place | `tween.advance(dt) -> Tween` | a value |
462
464
  | `Game` mutated by `update(&self, ..)` | `update(self, io, input, dt) -> Game`, `step(self, io, input, dt, pixels) -> Game` | the game is a value |
463
465
  | `Control`: methods on `&self` | methods that push onto its `asked` slice | an effect returns nothing; this is the one thing a tick writes in place |
docs/language.md CHANGED
@@ -433,7 +433,7 @@ primitive Demo[App] =
433
433
  [1, ..xs, if big then 100, ..extra, ..Range.until(0, 3).map(|i| i * 10)] # [1, 2, 3, 9, 0, 10, 20]
434
434
  ```
435
435
 
436
- Items run left to right, as written, and the list is built once, from its last item back: a value is one new cell, a spread copies the cells of what it spreads (a spread that ends the literal is shared, not copied), and nothing is appended to a list already built. Spreads are covariant like any `List`: `..self.orbs`, a `List<Orb>`, goes into a `List<View>`.
436
+ Items run left to right, as written, and the list is built once, from its last item back: a value is one new cell, a spread copies the cells of what it spreads (a spread that ends the literal is shared, not copied), and nothing is appended to a list already built. Spreads are covariant like any `List`: `..self.orbs`, a `List<Orb>`, goes into a `List<View>`, in the same one pass that copies it (each cell is made a `List<View>`'s as it is copied).
437
437
 
438
438
  **Items on lines:** a list literal written across lines may put one item on each line and leave out the commas. An item then ends with its line (break a long item inside its brackets), and commas are still allowed:
439
439
 
examples/games/balloonpop/actors/Balloon.plum CHANGED
@@ -71,15 +71,18 @@ struct Balloon[Actor, Sized, Touch](id: Int, x: Float, y: Float, speed: Float, h
71
71
  r := Balloon.Radius
72
72
  if !self.popped()
73
73
  [
74
- Circle(x: 0.0, y: r + 2.0, r: 6.0, color: hue.color),
74
+ Circle(y: r + 2.0, r: 6.0, color: hue.color)
75
- Circle(x: 0.0, y: 0.0, r: r, color: hue.color),
75
+ Circle(r: r, color: hue.color)
76
- Circle(x: 0.0 - r * 0.35, y: 0.0 - r * 0.4, r: r * 0.22, color: Color.White.withAlpha(0.55))]
76
+ Circle(x: -r * 0.35, y: -r * 0.4, r: r * 0.22, color: Color.White.withAlpha(0.55))
77
+ ]
77
78
  else
78
79
  t := {{self.clock - self.poppedAt} / Balloon.PopTime}.min(1.0)
79
80
  fade := 1.0 - t
80
81
  reach := 20.0 + 70.0 * t
82
+ [
81
- title := Label(x: 0.0, y: 0.0 - 20.0 - 60.0 * t, text: "{hue.name}!", size: 40.0, color: Color.rgb(0.15, 0.15, 0.3).withAlpha(fade), align: Centre)
83
+ Label(y: -20.0 - 60.0 * t, text: "{hue.name}!", size: 40.0, color: Color.rgb(0.15, 0.15, 0.3).withAlpha(fade), align: Centre)
82
- Cons(title, burst(0, reach, hue.color.withAlpha(fade)))
84
+ ..Range.until(0, 8).map(|i| spark(i, reach, hue.color.withAlpha(fade)))
85
+ ]
83
86
 
84
87
  fun paintSelf(self, io: Io, m: Affine, alpha: Float) =
85
88
  if !self.popped()
@@ -96,11 +99,8 @@ struct Balloon[Actor, Sized, Touch](id: Int, x: Float, y: Float, speed: Float, h
96
99
  tc := t.max(0.0).min(1.0)
97
100
  Math.hypot(px - {x1 + dx * tc}, py - {y1 + dy * tc}) <= thickness.max(1.0) / 2.0
98
101
 
99
- fun burst(i: Int, reach: Float, color: Color) -> List<View> =
102
+ fun spark(i: Int, reach: Float, color: Color) -> Circle =
100
- if i >= 8
101
- Nil
102
- else
103
- a := Float(i) * Float.Tau / 8.0
103
+ a := Float(i) * Float.Tau / 8.0
104
- Cons(Circle(x: Math.cos(a) * reach, y: Math.sin(a) * reach, r: 8.0, color: color), burst(i + 1, reach, color))
104
+ Circle(x: Math.cos(a) * reach, y: Math.sin(a) * reach, r: 8.0, color: color)
105
105
 
106
106
  struct Spawned(balloon: Balloon, rng: Random)
examples/games/balloonpop/screens/PlaygroundScreen.plum CHANGED
@@ -16,6 +16,7 @@ import std/game/Input
16
16
  import std/game/View
17
17
  import std/game/Box
18
18
  import std/game/Circle
19
+ import std/game/Group
19
20
  import std/game/Label
20
21
  import std/game/Control
21
22
  import std/game/Screen
@@ -59,19 +60,21 @@ struct PlaygroundScreen[ScreenSlice<PopAction>](
59
60
  fun background(self) -> Color = Color.rgb(0.55, 0.8, 1.0)
60
61
 
61
62
  fun view(self) -> List<View> = [
62
- Box(x: 0.0, y: 0.0, w: Arena.W, h: Arena.H, color: Color.rgb(0.55, 0.8, 1.0)),
63
+ Box(w: Arena.W, h: Arena.H, color: Color.rgb(0.55, 0.8, 1.0))
63
- Box(x: 0.0, y: 0.0, w: Arena.W, h: 200.0, color: Color.rgb(0.45, 0.72, 0.98)),
64
+ Box(w: Arena.W, h: 200.0, color: Color.rgb(0.45, 0.72, 0.98))
64
- Circle(x: 690.0, y: 90.0, r: 46.0, color: Color.rgb(1.0, 0.9, 0.35)),
65
+ Circle(x: 690.0, y: 90.0, r: 46.0, color: Color.rgb(1.0, 0.9, 0.35))
65
- ..cloud(wrapX(120.0 + self.clock * 12.0), 130.0),
66
+ cloud(wrapX(120.0 + self.clock * 12.0), 130.0)
66
- ..cloud(wrapX(520.0 + self.clock * 8.0), 220.0),
67
+ cloud(wrapX(520.0 + self.clock * 8.0), 220.0)
67
- Box(x: 0.0, y: Arena.H - 50.0, w: Arena.W, h: 50.0, color: Color.rgb(0.4, 0.78, 0.35)),
68
+ Box(y: Arena.H - 50.0, w: Arena.W, h: 50.0, color: Color.rgb(0.4, 0.78, 0.35))
68
- ..self.balloons,
69
+ ..self.balloons
69
- if self.partying() then ..self.party()]
70
+ if self.partying() then ..self.party()
71
+ ]
70
72
 
71
73
  fun hud(self, window: Vec2) -> List<View> = [
72
- Box(x: 16.0, y: 14.0, w: 170.0, h: 56.0, color: Color.White.withAlpha(0.7)),
74
+ Box(x: 16.0, y: 14.0, w: 170.0, h: 56.0, color: Color.White.withAlpha(0.7))
73
- Circle(x: 46.0, y: 42.0, r: 18.0, color: Hue.of(0).color),
75
+ Circle(x: 46.0, y: 42.0, r: 18.0, color: Hue.of(0).color)
74
- Label(x: 80.0, y: 20.0, text: "{self.pops}", size: 44.0, color: Color.rgb(0.15, 0.15, 0.3))]
76
+ Label(x: 80.0, y: 20.0, text: "{self.pops}", size: 44.0, color: Color.rgb(0.15, 0.15, 0.3))
77
+ ]
75
78
 
76
79
  fun stepped(self, dt: Float) -> PlaygroundScreen = PlaygroundScreen(..self, balloons: Views.stepAll(self.balloons, dt))
77
80
 
@@ -129,9 +132,10 @@ struct PlaygroundScreen[ScreenSlice<PopAction>](
129
132
  k := partyScale(age)
130
133
  cx := Arena.W / 2.0
131
134
  [
132
- ..Range.until(0, PlaygroundScreen.Confetti).map(|i| confetto(i, age)),
135
+ ..Range.until(0, PlaygroundScreen.Confetti).map(|i| confetto(i, age))
133
- Label(x: cx, y: 250.0 - 40.0 * k, text: "Hooray!", size: 72.0 * k, color: Color.rgb(0.95, 0.3, 0.5), align: Centre),
136
+ Label(x: cx, y: 250.0 - 40.0 * k, text: "Hooray!", size: 72.0 * k, color: Color.rgb(0.95, 0.3, 0.5), align: Centre)
134
- Label(x: cx, y: 250.0 + 40.0 * k, text: "{self.pops} balloons!", size: 40.0 * k, color: Color.rgb(0.15, 0.15, 0.3), align: Centre)]
137
+ Label(x: cx, y: 250.0 + 40.0 * k, text: "{self.pops} balloons!", size: 40.0 * k, color: Color.rgb(0.15, 0.15, 0.3), align: Centre)
138
+ ]
135
139
 
136
140
  fun partyScale(age: Float) -> Float =
137
141
  if age < 0.25
@@ -151,6 +155,10 @@ struct PlaygroundScreen[ScreenSlice<PopAction>](
151
155
  span := Arena.W + 200.0
152
156
  x - span * Float(Int(x / span)) - 100.0
153
157
 
154
- fun cloud(x: Float, y: Float) -> List<View> =
158
+ fun cloud(x: Float, y: Float) -> Group =
155
159
  white := Color.White.withAlpha(0.9)
160
+ Group(x: x, y: y) {
156
- [Circle(x: x - 30.0, y: y + 8.0, r: 24.0, color: white), Circle(x: x, y: y, r: 32.0, color: white), Circle(x: x + 32.0, y: y + 8.0, r: 24.0, color: white)]
161
+ Circle(x: -30.0, y: 8.0, r: 24.0, color: white)
162
+ Circle(r: 32.0, color: white)
163
+ Circle(x: 32.0, y: 8.0, r: 24.0, color: white)
164
+ }
examples/games/clicks.plum CHANGED
@@ -26,7 +26,7 @@ enum TapAction = Tapped | Push(dx: Float) | Quit
26
26
  struct Ball[Actor](x: Float, y: Float, vx: Float) =
27
27
  fun place(self) -> Place = Place.at(self.x, self.y)
28
28
 
29
- fun view(self) -> List<View> = [Circle(x: 0.0, y: 0.0, r: 10.0, color: Color.Yellow)]
29
+ fun view(self) -> List<View> = [Circle(r: 10.0, color: Color.Yellow)]
30
30
 
31
31
  fun push(self, vx: Float) -> Ball = Ball(..self, vx: vx)
32
32
 
examples/games/orbitrunner/actors/Mine.plum CHANGED
@@ -20,7 +20,7 @@ struct Mine[Actor](at: Place, vx: Float, vy: Float, clock: Float, tex: Texture)
20
20
  fun place(self) -> Place = self.at
21
21
 
22
22
  fun view(self) -> List<View> =
23
- [Sprite(x: 0.0, y: 0.0, tex: self.tex, w: Sheet.Size, h: Sheet.Size, srcX: 0.0, srcY: 2.0 * Sheet.Cell, srcW: Sheet.Cell, srcH: Sheet.Cell, frame: Sprite.frameAt(self.clock, 4.0, 4))]
23
+ [Sprite(tex: self.tex, w: Sheet.Size, h: Sheet.Size, srcX: 0.0, srcY: 2.0 * Sheet.Cell, srcW: Sheet.Cell, srcH: Sheet.Cell, frame: Sprite.frameAt(self.clock, 4.0, 4))]
24
24
 
25
25
  fun motion(self) -> Motion = Motion(x: self.at.x, y: self.at.y, vx: self.vx, vy: self.vy)
26
26
 
examples/games/orbitrunner/actors/Orb.plum CHANGED
@@ -24,7 +24,7 @@ struct Orb[Actor](at: Place, vx: Float, vy: Float, phase: Float, clock: Float, t
24
24
  fun place(self) -> Place = self.at
25
25
 
26
26
  fun view(self) -> List<View> =
27
- [Sprite(x: 0.0, y: 0.0, tex: self.tex, w: Sheet.Size, h: Sheet.Size, srcX: 0.0, srcY: Sheet.Cell, srcW: Sheet.Cell, srcH: Sheet.Cell, frame: Sprite.frameAt(self.clock + self.phase, 8.0, 4))]
27
+ [Sprite(tex: self.tex, w: Sheet.Size, h: Sheet.Size, srcX: 0.0, srcY: Sheet.Cell, srcW: Sheet.Cell, srcH: Sheet.Cell, frame: Sprite.frameAt(self.clock + self.phase, 8.0, 4))]
28
28
 
29
29
  fun motion(self) -> Motion = Motion(x: self.at.x, y: self.at.y, vx: self.vx, vy: self.vy)
30
30
 
examples/games/orbitrunner/actors/Ring.plum CHANGED
@@ -19,7 +19,7 @@ struct Ring[Actor](x: Float, y: Float, age: Float) =
19
19
 
20
20
  fun view(self) -> List<View> =
21
21
  k := self.age / Ring.Secs
22
- [Circle(x: 0.0, y: 0.0, r: Ring.Reach * k, color: Color.Red.withAlpha(1.0 - k))]
22
+ [Circle(r: Ring.Reach * k, color: Color.Red.withAlpha(1.0 - k))]
23
23
 
24
24
  fun step(self, dt: Float) -> Ring = Ring(..self, age: self.age + dt)
25
25
 
examples/games/orbitrunner/actors/Ship.plum CHANGED
@@ -28,8 +28,9 @@ struct Ship[Actor](tex: Texture, at: Place, vx: Float, vy: Float, ax: Float, ay:
28
28
  fun visible(self) -> Bool = self.lit()
29
29
 
30
30
  fun view(self) -> List<View> = [
31
- Circle(x: Sheet.Size / 2.0, y: Sheet.Size / 2.0, r: 17.0, color: Color(r: 0.4, g: 0.8, b: 1.0, a: 0.12)),
31
+ Circle(x: Sheet.Size / 2.0, y: Sheet.Size / 2.0, r: 17.0, color: Color(r: 0.4, g: 0.8, b: 1.0, a: 0.12))
32
- Sprite(x: 0.0, y: 0.0, tex: self.tex, w: Sheet.Size, h: Sheet.Size, srcX: 0.0, srcY: 0.0, srcW: Sheet.Cell, srcH: Sheet.Cell, frame: Sprite.frameAt(self.clock, 14.0, 4))]
32
+ Sprite(tex: self.tex, w: Sheet.Size, h: Sheet.Size, srcX: 0.0, srcY: 0.0, srcW: Sheet.Cell, srcH: Sheet.Cell, frame: Sprite.frameAt(self.clock, 14.0, 4))
33
+ ]
33
34
 
34
35
  fun steer(self, ax: Float, ay: Float) -> Ship = Ship(..self, ax: ax, ay: ay)
35
36
 
examples/games/orbitrunner/actors/Star.plum CHANGED
@@ -16,6 +16,6 @@ struct Star[View](index: Int, clock: Float) =
16
16
 
17
17
  fun place(self) -> Place = Place.at(Float({self.index * 7919} % 800), Float({self.index * 104729} % 600))
18
18
 
19
- fun view(self) -> List<View> = [Circle(x: 0.0, y: 0.0, r: self.r(), color: Color(r: 0.7, g: 0.8, b: 1.0, a: self.twinkle()))]
19
+ fun view(self) -> List<View> = [Circle(r: self.r(), color: Color(r: 0.7, g: 0.8, b: 1.0, a: self.twinkle()))]
20
20
 
21
21
  fun twinkle(self) -> Float = 0.25 + 0.2 * Math.sin(self.clock * 2.0 + Float(self.index))
examples/games/orbitrunner/screens/PlayingScreen.plum CHANGED
@@ -71,18 +71,20 @@ struct PlayingScreen[ScreenSlice<PlayAction>](
71
71
  PlayingScreen(..self, mines: Views.stepAll(self.mines, dt), orbs: Views.stepAll(self.orbs, dt), ship: self.ship.step(dt), rings: Views.stepAll(self.rings, dt))
72
72
 
73
73
  fun view(self) -> List<View> = [
74
- Box(x: 0.0, y: 0.0, w: Arena.W, h: Arena.H, color: Color.rgb(0.07, 0.08, 0.16)),
74
+ Box(w: Arena.W, h: Arena.H, color: Color.rgb(0.07, 0.08, 0.16))
75
- ..Range.until(0, Star.Count).map(|i| Star(index: i, clock: self.clock)),
75
+ ..Range.until(0, Star.Count).map(|i| Star(index: i, clock: self.clock))
76
- ..self.mines,
76
+ ..self.mines
77
- ..self.orbs,
77
+ ..self.orbs
78
- if !self.over then self.ship,
78
+ if !self.over then self.ship
79
- ..self.rings,
79
+ ..self.rings
80
- Label(x: 16.0, y: 12.0, text: "Score {self.score}", size: 28.0),
80
+ Label(x: 16.0, y: 12.0, text: "Score {self.score}", size: 28.0)
81
- Label(x: 16.0, y: 44.0, text: "Best {self.best.max(self.score)}", color: Color.Yellow),
81
+ Label(x: 16.0, y: 44.0, text: "Best {self.best.max(self.score)}", color: Color.Yellow)
82
- ..Range.until(0, self.lives).map(|i| Sprite(x: Arena.W - 40.0 - Float(i) * 36.0, y: 12.0, tex: self.assets.sheet, w: 32.0, h: 32.0, srcX: 0.0, srcY: 0.0, srcW: Sheet.Cell, srcH: Sheet.Cell)),
82
+ ..Range.until(0, self.lives).map(|i| Sprite(x: Arena.W - 40.0 - Float(i) * 36.0, y: 12.0, tex: self.assets.sheet, w: 32.0, h: 32.0, srcX: 0.0, srcY: 0.0, srcW: Sheet.Cell, srcH: Sheet.Cell))
83
- if self.over then Overlay(w: Arena.W, h: Arena.H, children: [
83
+ if self.over then Overlay(w: Arena.W, h: Arena.H) {
84
- Label(x: 300.0, y: 258.0, text: "Game over", size: 48.0, color: Color.Red),
84
+ Label(x: 300.0, y: 258.0, text: "Game over", size: 48.0, color: Color.Red)
85
- Label(x: 270.0, y: 316.0, text: "Press Enter to play again", size: 24.0)])]
85
+ Label(x: 270.0, y: 316.0, text: "Press Enter to play again", size: 24.0)
86
+ }
87
+ ]
86
88
 
87
89
  fun deal(self) -> PlayingScreen =
88
90
  fresh := PlayingScreen(..self, clock: 0.0, ship: Ship.create(self.assets.sheet), orbs: Nil, mines: Nil, rings: Nil)
std/game/Box.plum CHANGED
@@ -17,7 +17,7 @@ import std/game/Touch
17
17
  # A filled `w` by `h` box in `color` (painted at its alpha), its top-left at (x, y), where
18
18
  # its place starts. It is decoration unless `touch: Enabled` (std/game/Touch), and then
19
19
  # hit inside it.
20
- struct Box[View, Sized, Touch](x: Float, y: Float, w: Float, h: Float, color: Color, touch: Touchable = Disabled) =
20
+ struct Box[View, Sized, Touch](x: Float = 0.0, y: Float = 0.0, w: Float, h: Float, color: Color, touch: Touchable = Disabled) =
21
21
  fun place(self) -> Place = Place.at(self.x, self.y)
22
22
 
23
23
  fun bounds(self) -> Aabb = Aabb.of(0.0, 0.0, self.w, self.h)
std/game/Circle.plum CHANGED
@@ -21,7 +21,7 @@ import std/game/Touch
21
21
  # (its bounds are -r to r in its own coordinates), painted at its colour's alpha. It is
22
22
  # decoration unless `touch: Enabled` (std/game/Touch), and then hit inside the circle, not
23
23
  # its whole box.
24
- struct Circle[View, Sized, Touch](x: Float, y: Float, r: Float, color: Color, touch: Touchable = Disabled) =
24
+ struct Circle[View, Sized, Touch](x: Float = 0.0, y: Float = 0.0, r: Float, color: Color, touch: Touchable = Disabled) =
25
25
  fun place(self) -> Place = Place.at(self.x, self.y)
26
26
 
27
27
  fun bounds(self) -> Aabb = Aabb.of(0.0 - self.r, 0.0 - self.r, 2.0 * self.r, 2.0 * self.r)
std/game/Group.plum CHANGED
@@ -8,9 +8,13 @@ import std/game/Touch
8
8
 
9
9
  # A view that paints nothing and is never hit: a parent for others (a layer, a HUD, the
10
10
  # arm of an orbit), at (x, y) (the origin unless given), with the children it is made with,
11
- # its `view`, which are placed in its coordinates:
11
+ # its `view`, which are placed in its coordinates; they are its block (its last field,
12
+ # `children`):
12
13
  #
14
+ # Group(x: 16.0, y: 16.0) {
13
- # Group(x: 16.0, y: 16.0, children: [Label(x: 0.0, y: 0.0, text: "Score", size: 24.0), ..])
15
+ # Label(text: "Score", size: 24.0)
16
+ # ..
17
+ # }
14
18
  #
15
19
  # Its `touch` (std/game/Touch) is `ChildrenOnly` unless given: its children may be hit, it
16
20
  # is not; `touch: Disabled` takes everything under it out of hit testing (a layer of
std/game/Label.plum CHANGED
@@ -37,7 +37,7 @@ enum Align =
37
37
  # again each frame, so its text is read from the state as it is made
38
38
  # (`Label(x: 16.0, y: 12.0, text: "Score {self.score}", size: 28.0)`). Unless given, it is
39
39
  # 20 high, white, `Left` and decoration (`Disabled`).
40
- struct Label[View, Sized, Touch](x: Float, y: Float, text: Str, size: Float = 20.0, color: Color = Color.White, align: Align = Left, touch: Touchable = Disabled) =
40
+ struct Label[View, Sized, Touch](x: Float = 0.0, y: Float = 0.0, text: Str, size: Float = 20.0, color: Color = Color.White, align: Align = Left, touch: Touchable = Disabled) =
41
41
  fun place(self) -> Place = Place.at(self.x, self.y)
42
42
 
43
43
  # How far left of its place its text starts.
std/game/Overlay.plum CHANGED
@@ -21,10 +21,12 @@ import std/game/Label
21
21
 
22
22
  # A panel over a screen: a game over, a pause, a dialog. It is not a screen of its own. It
23
23
  # is an item of the view of the screen it sits on, after (so drawn above) what it covers,
24
- # there while the state says so, with its own children on it (a label, buttons):
24
+ # there while the state says so, with its own children on it (a label, buttons), its
25
+ # block (its last field, `children`):
25
26
  #
26
- # if self.over then Overlay(w: Arena.W, h: Arena.H, children: [
27
+ # if self.over then Overlay(w: Arena.W, h: Arena.H) {
27
- # Label(x: 300.0, y: 258.0, text: "Game over", size: 48.0, color: Color.Red)])
28
+ # Label(x: 300.0, y: 258.0, text: "Game over", size: 48.0, color: Color.Red)
29
+ # }
28
30
  #
29
31
  # It paints a `w` by `h` box at (x, y) (the origin unless given) in its `color` (black at
30
32
  # 0.6 alpha unless given) over what is under it, then its children (its `view`) at their
std/game/Sprite.plum CHANGED
@@ -26,8 +26,8 @@ import std/game/Touch
26
26
  # right of (srcX, srcY). In an actor's `view` (std/game/View), made again at each draw, it
27
27
  # is read from the actor's own clock:
28
28
  #
29
- # Sprite(x: 0.0, y: 0.0, tex: sheet, w: 48.0, h: 48.0, srcX: 0.0, srcY: 0.0, srcW: 16.0, srcH: 16.0, frame: Sprite.frameAt(self.clock, 8.0, 4))
30
- struct Sprite[View, Sized, Touch](x: Float, y: Float, tex: Texture, w: Float, h: Float, srcX: Float, srcY: Float, srcW: Float, srcH: Float, frame: Int = 0, tint: Color = Color.White, touch: Touchable = Disabled) =
29
+ # Sprite(tex: sheet, w: 48.0, h: 48.0, srcX: 0.0, srcY: 0.0, srcW: 16.0, srcH: 16.0, frame: Sprite.frameAt(self.clock, 8.0, 4))
30
+ struct Sprite[View, Sized, Touch](x: Float = 0.0, y: Float = 0.0, tex: Texture, w: Float, h: Float, srcX: Float, srcY: Float, srcW: Float, srcH: Float, frame: Int = 0, tint: Color = Color.White, touch: Touchable = Disabled) =
31
31
  fun place(self) -> Place = Place.at(self.x, self.y)
32
32
 
33
33
  # The frame of a strip of `count` frames played at `fps` frames a second, `clock`
std/game/Tween.plum CHANGED
@@ -12,7 +12,7 @@ import std/collections/List
12
12
  #
13
13
  # MenuScreen(..self, highlight: Tween(from: self.highlight.value(), to: 340.0, secs: 0.15, ease: QuadOut))
14
14
  # Tick(dt) => MenuScreen(..self, highlight: self.highlight.advance(dt))
15
- # Box(x: 0.0, y: self.highlight.value(), ..) # in the view
15
+ # Box(y: self.highlight.value(), ..) # in the view
16
16
  # fun busy(self) -> Bool = !self.highlight.done() # an OnDemand screen ticks while it runs
17
17
  #
18
18
  # Tween(from:, to:, secs:) from `from` to `to` over `secs` along `ease` (`Linear` unless
std/game/View.plum CHANGED
@@ -48,7 +48,7 @@ import std/game/Circle
48
48
  #
49
49
  # struct Walker[Actor](at: Place, speed: Float) =
50
50
  # fun place(self) -> Place = self.at
51
- # fun view(self) -> List<View> = [Box(x: 0.0, y: 0.0, w: 10.0, h: 10.0, color: Color.Red)]
51
+ # fun view(self) -> List<View> = [Box(w: 10.0, h: 10.0, color: Color.Red)]
52
52
  # fun step(self, dt: Float) -> Walker = Walker(..self, at: self.at.moveBy(self.speed * dt, 0.0))
53
53
  #
54
54
  # Beside `View` or `Actor`, a view may be:
tests/examples/games/orbitrunner/actors/Ring.plum CHANGED
@@ -16,7 +16,7 @@ primitive RingTest[UnitTest] =
16
16
  assert !ring.done()
17
17
  c := match ring.view().at(0)
18
18
  Circle as c => c
19
- _ => Circle(x: 0.0, y: 0.0, r: 0.0, color: Color.Black)
19
+ _ => Circle(r: 0.0, color: Color.Black)
20
20
  assert c.r == Ring.Reach / 2.0
21
21
  assert c.color.a == 0.5
22
22
  assert ring.step(0.2).done()
tests/port/game/screens.plum CHANGED
@@ -65,7 +65,7 @@ struct ProbeScreen[ScreenSlice<ProbeAct>](
65
65
  fun create(frames: Frames) -> ProbeScreen =
66
66
  ProbeScreen(
67
67
  box: Box(x: 10.0, y: 10.0, w: 20.0, h: 20.0, color: Color.Red, touch: Enabled),
68
- inner: Box(x: 0.0, y: 0.0, w: 10.0, h: 10.0, color: Color.Red, touch: Enabled),
68
+ inner: Box(w: 10.0, h: 10.0, color: Color.Red, touch: Enabled),
69
69
  under: Box(x: 400.0, y: 400.0, w: 50.0, h: 50.0, color: Color.Red, touch: Enabled),
70
70
  covered: false, hits: Nil, misses: 0, keys: 0, echoes: 0, ticks: 0, left: 0, frames: frames, rng: Random.seeded(5), roll: 0)
71
71
 
@@ -77,15 +77,18 @@ struct ProbeScreen[ScreenSlice<ProbeAct>](
77
77
 
78
78
  fun busy(self) -> Bool = self.left > 0
79
79
 
80
- fun view(self) -> List<View> =
80
+ fun view(self) -> List<View> = [
81
- turned := Group(x: 200.0, y: 100.0, touch: ChildrenOnly, children: [Group(x: 50.0, children: [self.inner])])
82
- base := [
83
- self.box,
81
+ self.box
84
- Screens.turnedBy(turned),
82
+ Screens.turnedBy(Group(x: 200.0, y: 100.0, touch: ChildrenOnly) {
83
+ Group(x: 50.0) { self.inner }
84
+ })
85
- self.under,
85
+ self.under
86
+ Group(touch: Disabled) {
86
- Group(x: 0.0, y: 0.0, touch: Disabled, children: [Box(x: 400.0, y: 400.0, w: 50.0, h: 50.0, color: Color.Red, touch: Enabled)]),
87
+ Box(x: 400.0, y: 400.0, w: 50.0, h: 50.0, color: Color.Red, touch: Enabled)
88
+ }
87
- Label(x: 0.0, y: 560.0, text: "keys {self.keys}", size: 24.0)]
89
+ Label(y: 560.0, text: "keys {self.keys}", size: 24.0)
88
- if self.covered then base.append([Overlay(w: 800.0, h: 600.0, children: Nil)]) else base
90
+ if self.covered then Overlay(w: 800.0, h: 600.0) {}
91
+ ]
89
92
 
90
93
  fun onPress(self, target: View, at: Vec2) -> Option<ProbeAct> = Some(Pressed(on: target))
91
94
 
@@ -179,7 +182,7 @@ struct PlayProbe[ScreenSlice<ProbeAct>](presses: Int, ticks: Int) =
179
182
  struct Walker[Actor](x: Float, speed: Float) =
180
183
  fun place(self) -> Place = Place.at(self.x, 0.0)
181
184
 
182
- fun view(self) -> List<View> = [Box(x: 0.0, y: 0.0, w: 4.0, h: 4.0, color: Color.White)]
185
+ fun view(self) -> List<View> = [Box(w: 4.0, h: 4.0, color: Color.White)]
183
186
 
184
187
  fun step(self, dt: Float) -> Walker = Walker(..self, x: self.x + self.speed * dt)
185
188
 
@@ -274,7 +277,7 @@ primitive ScreensTest[UnitTest] =
274
277
  assert t.count<Box>() == 4
275
278
  assert t.text(t.first<Label>()) == "keys 0"
276
279
  assert t.shown(t.screen.box)
277
- assert !t.shown(Box(x: 0.0, y: 0.0, w: 1.0, h: 1.0, color: Color.Red))
280
+ assert !t.shown(Box(w: 1.0, h: 1.0, color: Color.Red))
278
281
  u := t.press(Key.KeyA).tick()
279
282
  assert u.text(u.first<Label>()) == "keys 1"
280
283
 
tests/std/game/Box.plum CHANGED
@@ -21,6 +21,8 @@ primitive BoxTest[UnitTest] =
21
21
  assert b.hit(Vec2(x: 2.0, y: 1.0))
22
22
  assert !b.hit(Vec2(x: 5.0, y: 1.0))
23
23
  assert b.touch().disabled()
24
- assert Box(x: 0.0, y: 0.0, w: 1.0, h: 1.0, color: Color.White, touch: Enabled).touch().enabled()
24
+ assert Box(w: 1.0, h: 1.0, color: Color.White, touch: Enabled).touch().enabled()
25
25
  assert b.place().x == 1.0
26
+ # at the origin unless placed
27
+ assert Box(w: 1.0, h: 1.0, color: Color.White).x == 0.0 && Box(w: 1.0, h: 1.0, color: Color.White).y == 0.0
26
28
  assert !Box.contains(0.0, 3.0, Vec2(x: 0.0, y: 0.0))
tests/std/game/Circle.plum CHANGED
@@ -20,7 +20,8 @@ import std/Test
20
20
  primitive CircleTest[UnitTest] =
21
21
  # a circle is hit inside its radius, about its centre
22
22
  fun aCircleIsHitInsideItsRadiusAbout() =
23
- c := Circle(x: 0.0, y: 0.0, r: 5.0, color: Color.Red)
23
+ c := Circle(r: 5.0, color: Color.Red)
24
+ assert c.x == 0.0 && c.y == 0.0
24
25
  assert c.hit(Vec2(x: 0.0, y: 0.0))
25
26
  assert c.hit(Vec2(x: 4.0, y: 0.0))
26
27
  assert !c.hit(Vec2(x: -4.5, y: -4.5))
tests/std/game/Label.plum CHANGED
@@ -20,17 +20,18 @@ import std/Test
20
20
  primitive LabelTest[UnitTest] =
21
21
  # a label is as tall as its size and hit over its text
22
22
  fun aLabelIsAsTallAsItsSize() =
23
- l := Label(x: 0.0, y: 0.0, text: "ab", size: 10.0)
23
+ l := Label(text: "ab", size: 10.0)
24
+ assert l.x == 0.0 && l.y == 0.0
24
25
  assert l.hit(Vec2(x: 11.0, y: 9.0))
25
26
  assert !l.hit(Vec2(x: 13.0, y: 9.0))
26
- assert Label(x: 0.0, y: 0.0, text: "abc", size: 10.0).hit(Vec2(x: 13.0, y: 9.0))
27
+ assert Label(text: "abc", size: 10.0).hit(Vec2(x: 13.0, y: 9.0))
27
28
 
28
29
  # a label is placed on its x by its alignment
29
30
  fun aLabelIsPlacedOnItsXBy() =
30
- c := Label(x: 100.0, y: 0.0, text: "abcd", size: 10.0, align: Centre)
31
+ c := Label(x: 100.0, text: "abcd", size: 10.0, align: Centre)
31
32
  assert c.bounds() == Aabb.of(-12.0, 0.0, 24.0, 10.0)
32
33
  assert c.hit(Vec2(x: -11.0, y: 5.0))
33
34
  assert !c.hit(Vec2(x: 13.0, y: 5.0))
34
- r := Label(x: 0.0, y: 0.0, text: "abcd", size: 10.0, align: Right)
35
+ r := Label(text: "abcd", size: 10.0, align: Right)
35
36
  assert r.bounds() == Aabb.of(-24.0, 0.0, 24.0, 10.0)
36
- assert Label(x: 0.0, y: 0.0, text: "abcd", size: 10.0).lead() == 0.0
37
+ assert Label(text: "abcd", size: 10.0).lead() == 0.0
tests/std/game/Overlay.plum CHANGED
@@ -22,13 +22,13 @@ import std/Test
22
22
  primitive OverlayTest[UnitTest] =
23
23
  # an overlay is hit inside its box, after its children, and hides what is under it from presses
24
24
  fun anOverlayIsHitInsideItsBoxAfter() =
25
- under := Box(x: 0.0, y: 0.0, w: 100.0, h: 100.0, color: Color.White, touch: Enabled)
25
+ under := Box(w: 100.0, h: 100.0, color: Color.White, touch: Enabled)
26
26
  button := Box(x: 40.0, y: 40.0, w: 10.0, h: 10.0, color: Color.White, touch: Enabled)
27
- over := Overlay(w: 100.0, h: 100.0, children: [button, Label(x: 0.0, y: 0.0, text: "Paused", size: 24.0)])
27
+ over := Overlay(w: 100.0, h: 100.0) { button, Label(text: "Paused", size: 24.0) }
28
28
  items := [under, over]
29
29
  assert @sameRef(Views.hitIn(items, Vec2(x: 5.0, y: 5.0)).unwrap(), over)
30
30
  assert Views.hitIn(items, Vec2(x: 5000.0, y: -20.0)).isNone()
31
31
  assert @sameRef(Views.hitIn(items, Vec2(x: 45.0, y: 45.0)).unwrap(), button)
32
32
  assert @sameRef(Views.hitIn([under], Vec2(x: 5.0, y: 5.0)).unwrap(), under)
33
- off := Overlay(w: 10.0, h: 10.0, children: Nil, touch: Disabled)
33
+ off := Overlay(w: 10.0, h: 10.0, touch: Disabled) {}
34
34
  assert @sameRef(Views.hitIn([under, off], Vec2(x: 5.0, y: 5.0)).unwrap(), under)
tests/std/game/Sprite.plum CHANGED
@@ -19,7 +19,8 @@ import std/Test
19
19
 
20
20
  primitive SpriteTest[UnitTest] =
21
21
  fun aSpriteShowsItsFrameOfItsStrip() =
22
- s := Sprite(x: 0.0, y: 0.0, tex: Texture(id: 3), w: 48.0, h: 48.0, srcX: 16.0, srcY: 32.0, srcW: 16.0, srcH: 16.0, frame: 2)
22
+ s := Sprite(tex: Texture(id: 3), w: 48.0, h: 48.0, srcX: 16.0, srcY: 32.0, srcW: 16.0, srcH: 16.0, frame: 2)
23
+ assert s.x == 0.0 && s.y == 0.0
23
24
  assert s.frameX() == 48.0
24
25
  assert s.hit(Vec2(x: 47.0, y: 1.0))
25
26
 
tests/std/game/View.plum CHANGED
@@ -51,14 +51,14 @@ primitive ViewTest[UnitTest] =
51
51
  Views.paint(io, [SelfPainted(log: log, shows: false)], Affine.Identity, 1.0)
52
52
  assert log.isEmpty()
53
53
  found := Slice<Drawn>()
54
- Views.drawnIn([SelfPainted(log: log, shows: false), Box(x: 0.0, y: 0.0, w: 1.0, h: 1.0, color: Color.White)], Affine.Identity, 1.0, found, Aabb.of(0.0, 0.0, 0.0, 0.0), false)
54
+ Views.drawnIn([SelfPainted(log: log, shows: false), Box(w: 1.0, h: 1.0, color: Color.White)], Affine.Identity, 1.0, found, Aabb.of(0.0, 0.0, 0.0, 0.0), false)
55
55
  assert found.length() == 1
56
56
 
57
57
  # stepping a list of actors steps each in order; stepping a view's items steps only its actors
58
58
  fun steppingAListOfActorsStepsEachIn() =
59
59
  steppers := Views.stepAll([Stepper(time: 0.0), Stepper(time: 1.0)], 0.5)
60
60
  assert steppers.at(0).time == 0.5 && steppers.at(1).time == 1.5
61
- items := [Stepper(time: 0.0), Box(x: 0.0, y: 0.0, w: 1.0, h: 1.0, color: Color.White), Stepper(time: 2.0)]
61
+ items := [Stepper(time: 0.0), Box(w: 1.0, h: 1.0, color: Color.White), Stepper(time: 2.0)]
62
62
  stepped := Views.stepIn(Views.stepIn(items, 0.5), 0.25)
63
63
  times := stepped.map(|v| match v
64
64
  Stepper as s => s.time
@@ -69,10 +69,10 @@ primitive ViewTest[UnitTest] =
69
69
  fun aPressIsOnTheTopMostItem() =
70
70
  top := Box(x: 10.0, y: 10.0, w: 20.0, h: 20.0, color: Color.White, touch: Enabled)
71
71
  under := Box(x: 10.0, y: 10.0, w: 20.0, h: 20.0, color: Color.White, touch: Enabled)
72
- inner := Box(x: 0.0, y: 0.0, w: 10.0, h: 10.0, color: Color.White, touch: Enabled)
72
+ inner := Box(w: 10.0, h: 10.0, color: Color.White, touch: Enabled)
73
- turned := TurnedGroup(x: 200.0, y: 100.0, children: [Group(x: 50.0, children: [inner])])
73
+ turned := TurnedGroup(x: 200.0, y: 100.0) { Group(x: 50.0) { inner } }
74
- hidden := Group(x: 0.0, y: 0.0, touch: Disabled, children: [Box(x: 400.0, y: 400.0, w: 50.0, h: 50.0, color: Color.White, touch: Enabled)])
74
+ hidden := Group(touch: Disabled) { Box(x: 400.0, y: 400.0, w: 50.0, h: 50.0, color: Color.White, touch: Enabled) }
75
- items := [under, top, turned, hidden, Label(x: 0.0, y: 0.0, text: "deco", size: 24.0)]
75
+ items := [under, top, turned, hidden, Label(text: "deco", size: 24.0)]
76
76
  assert @sameRef(Views.hitIn(items, Vec2(x: 15.0, y: 15.0)).unwrap(), top)
77
77
  # The inner box is 50 along the group's x, which is turned a quarter: 50 down from it.
78
78
  assert @sameRef(Views.hitIn(items, Vec2(x: 195.0, y: 155.0)).unwrap(), inner)
@@ -80,11 +80,11 @@ primitive ViewTest[UnitTest] =
80
80
  assert Views.hitIn(items, Vec2(x: 2.0, y: 2.0)).isNone()
81
81
  c := Views.worldIn(items, inner, Affine.Identity).unwrap().apply(Vec2(x: 0.0, y: 0.0))
82
82
  assert Math.near(c.x, 200.0, 0.001) && Math.near(c.y, 150.0, 0.001)
83
- assert Views.worldIn(items, Box(x: 0.0, y: 0.0, w: 1.0, h: 1.0, color: Color.White), Affine.Identity).isNone()
83
+ assert Views.worldIn(items, Box(w: 1.0, h: 1.0, color: Color.White), Affine.Identity).isNone()
84
84
 
85
85
  # the draw list holds every item and what is under it, and culling leaves out what misses the area
86
86
  fun theDrawListHoldsEveryItemAndWhat() =
87
- items := [Box(x: 0.0, y: 0.0, w: 10.0, h: 10.0, color: Color.White), Group(x: 5000.0, children: [Circle(x: 0.0, y: 0.0, r: 2.0, color: Color.White), Label(x: 0.0, y: 0.0, text: "far", size: 24.0)]), Box(x: 5000.0, y: 0.0, w: 10.0, h: 10.0, color: Color.White)]
87
+ items := [Box(w: 10.0, h: 10.0, color: Color.White), Group(x: 5000.0) { Circle(r: 2.0, color: Color.White), Label(text: "far", size: 24.0) }, Box(x: 5000.0, w: 10.0, h: 10.0, color: Color.White)]
88
88
  all := Slice<Drawn>()
89
89
  Views.drawnIn(items, Affine.Identity, 1.0, all, Aabb.of(0.0, 0.0, 0.0, 0.0), false)
90
90
  assert all.length() == 5
@@ -114,10 +114,11 @@ struct Viewed[View](x: Float, log: Slice<Float>, views: Slice<Int>, lit: Bool, i
114
114
  fun view(self) -> List<View> =
115
115
  self.views.push(1)
116
116
  [
117
- ViewHelpers.probeAt(1.0, self.log),
117
+ ViewHelpers.probeAt(1.0, self.log)
118
- if self.lit then ViewHelpers.probeAt(2.0, self.log),
118
+ if self.lit then ViewHelpers.probeAt(2.0, self.log)
119
- Group(x: 10.0, children: [ViewProbe(x: 4.0, log: self.log, fade: 0.5)]),
119
+ Group(x: 10.0) { ViewProbe(x: 4.0, log: self.log, fade: 0.5) }
120
- if self.inner then Viewed(x: 100.0, log: self.log, views: self.views, lit: true, inner: false)]
120
+ if self.inner then Viewed(x: 100.0, log: self.log, views: self.views, lit: true, inner: false)
121
+ ]
121
122
 
122
123
  # A view that paints itself (-1) and then has its view drawn, and is invisible unless
123
124
  # `shows`.