diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fa3e886..fd4b9f7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -49,7 +49,7 @@ jobs: run: bash -c "$(curl https://fireflyzero.com/install.sh)" - name: Setup MoonBit - uses: hustcer/setup-moonbit@1522f9aef02a8ca0187dfc00a41f5dd6b16750f7 # v1.23 + uses: hustcer/setup-moonbit@87e2bdf5cf20d3b6f5c5f266a8a513f503bb5b76 # v1.25 - name: Update MoonBit package registry run: moon update diff --git a/src/audio/node.mbt b/src/audio/node.mbt index e7eef22..38f1396 100644 --- a/src/audio/node.mbt +++ b/src/audio/node.mbt @@ -38,43 +38,43 @@ pub trait Node { ///| /// Add sine wave oscillator source (`∿`). impl Node with fn add_sine(self, freq : Hz, phase : Float) -> Sine { - Sine::{ id: @ffi.audio_add_sine(self.id(), freq, phase) } + Sine::{ id: @ffi.audio_add_sine(self.id(), freq, phase), } } ///| /// Add square wave oscillator source (`⎍`). impl Node with fn add_square(self, freq : Hz, phase : Float) -> Square { - Square::{ id: @ffi.audio_add_square(self.id(), freq, phase) } + Square::{ id: @ffi.audio_add_square(self.id(), freq, phase), } } ///| /// Add sawtooth wave oscillator source (`╱│`). impl Node with fn add_sawtooth(self, freq : Hz, phase : Float) -> Sawtooth { - Sawtooth::{ id: @ffi.audio_add_sawtooth(self.id(), freq, phase) } + Sawtooth::{ id: @ffi.audio_add_sawtooth(self.id(), freq, phase), } } ///| /// Add triangle wave oscillator source (`╱╲`). impl Node with fn add_triangle(self, freq : Hz, phase : Float) -> Triangle { - Triangle::{ id: @ffi.audio_add_triangle(self.id(), freq, phase) } + Triangle::{ id: @ffi.audio_add_triangle(self.id(), freq, phase), } } ///| /// Add white noise source (amplitude on each tick is random). impl Node with fn add_noise(self, seed : Int) -> Noise { - Noise::{ id: @ffi.audio_add_noise(self.id(), seed) } + Noise::{ id: @ffi.audio_add_noise(self.id(), seed), } } ///| /// Add always stopped source. impl Node with fn add_empty(self) -> Empty { - Empty::{ id: @ffi.audio_add_empty(self.id()) } + Empty::{ id: @ffi.audio_add_empty(self.id()), } } ///| /// Add silent source producing zeros. impl Node with fn add_zero(self) -> Zero { - Zero::{ id: @ffi.audio_add_zero(self.id()) } + Zero::{ id: @ffi.audio_add_zero(self.id()), } } ///| @@ -94,91 +94,91 @@ impl Node with fn add_file(self, path : @firefly.Utf8View) -> File { ///| /// Add node simply mixing all inputs. impl Node with fn add_mix(self) -> Mix { - Mix::{ id: @ffi.audio_add_mix(self.id()) } + Mix::{ id: @ffi.audio_add_mix(self.id()), } } ///| /// Add mixer node that stops if any of the sources stops. impl Node with fn add_all_for_one(self) -> AllForOne { - AllForOne::{ id: @ffi.audio_add_all_for_one(self.id()) } + AllForOne::{ id: @ffi.audio_add_all_for_one(self.id()), } } ///| /// Add gain control node. impl Node with fn add_gain(self, level : Float) -> Gain { - Gain::{ id: @ffi.audio_add_gain(self.id(), level) } + Gain::{ id: @ffi.audio_add_gain(self.id(), level), } } ///| /// Add a loop node that resets the input if it stops. impl Node with fn add_loop(self) -> Loop { - Loop::{ id: @ffi.audio_add_loop(self.id()) } + Loop::{ id: @ffi.audio_add_loop(self.id()), } } ///| /// Add a node that plays the inputs one after the other, in the order as they added. impl Node with fn add_concat(self) -> Concat { - Concat::{ id: @ffi.audio_add_concat(self.id()) } + Concat::{ id: @ffi.audio_add_concat(self.id()), } } ///| /// Add node panning the audio to the left (0.), right (1.), or something in between. impl Node with fn add_pan(self, level : Float) -> Pan { - Pan::{ id: @ffi.audio_add_pan(self.id(), level) } + Pan::{ id: @ffi.audio_add_pan(self.id(), level), } } ///| /// Add node that can be muted using modulation. impl Node with fn add_mute(self) -> Mute { - Mute::{ id: @ffi.audio_add_mute(self.id()) } + Mute::{ id: @ffi.audio_add_mute(self.id()), } } ///| /// Add node that can be paused using modulation. impl Node with fn add_pause(self) -> Pause { - Pause::{ id: @ffi.audio_add_pause(self.id()) } + Pause::{ id: @ffi.audio_add_pause(self.id()), } } ///| /// Add node tracking the elapsed playback time. impl Node with fn add_track_position(self) -> TrackPosition { - TrackPosition::{ id: @ffi.audio_add_track_position(self.id()) } + TrackPosition::{ id: @ffi.audio_add_track_position(self.id()), } } ///| /// Add lowpass filter node. impl Node with fn add_low_pass(self, freq : Hz, q : Float) -> LowPass { - LowPass::{ id: @ffi.audio_add_low_pass(self.id(), freq, q) } + LowPass::{ id: @ffi.audio_add_low_pass(self.id(), freq, q), } } ///| /// Add highpass filter node. impl Node with fn add_high_pass(self, freq : Hz, q : Float) -> HighPass { - HighPass::{ id: @ffi.audio_add_high_pass(self.id(), freq, q) } + HighPass::{ id: @ffi.audio_add_high_pass(self.id(), freq, q), } } ///| /// Add node converting stereo to mono by taking the left channel. impl Node with fn add_take_left(self) -> TakeLeft { - TakeLeft::{ id: @ffi.audio_add_take_left(self.id()) } + TakeLeft::{ id: @ffi.audio_add_take_left(self.id()), } } ///| /// Add node converting stereo to mono by taking the right channel. impl Node with fn add_take_right(self) -> TakeRight { - TakeRight::{ id: @ffi.audio_add_take_right(self.id()) } + TakeRight::{ id: @ffi.audio_add_take_right(self.id()), } } ///| /// Add node swapping left and right channels of the stereo input. impl Node with fn add_swap(self) -> Swap { - Swap::{ id: @ffi.audio_add_swap(self.id()) } + Swap::{ id: @ffi.audio_add_swap(self.id()), } } ///| /// Add node clamping the input amplitude. Can be used for hard distortion. impl Node with fn add_clip(self, low : Float, high : Float) -> Clip { - Clip::{ id: @ffi.audio_add_clip(self.id(), low, high) } + Clip::{ id: @ffi.audio_add_clip(self.id(), low, high), } } ///| diff --git a/src/audio/nodes.mbt b/src/audio/nodes.mbt index 1de4d6e..3029952 100644 --- a/src/audio/nodes.mbt +++ b/src/audio/nodes.mbt @@ -6,9 +6,12 @@ pub impl Node for Out with fn id(_self) -> UInt { return 0 } +///| +pub extend Out with Node::{id} + ///| /// The output audio node. Mixes all inputs and plays them on the device's speaker. -pub let out : Out = Out::{ } +pub let out : Out = Out::{ } ///| /// A marker for a specific node type. See `Node::add_mix`. @@ -21,6 +24,9 @@ pub impl Node for Mix with fn id(self) -> UInt { return self.id } +///| +pub extend Mix with Node::{id} + ///| /// A marker for a specific node type. See `Node::add_all_for_one`. struct AllForOne { @@ -32,6 +38,9 @@ pub impl Node for AllForOne with fn id(self) -> UInt { return self.id } +///| +pub extend AllForOne with Node::{id} + ///| /// A marker for a specific node type. See `Node::add_gain`. struct Gain { @@ -43,6 +52,9 @@ pub impl Node for Gain with fn id(self) -> UInt { return self.id } +///| +pub extend Gain with Node::{id} + ///| /// A marker for a specific node type. See `Node::add_loop`. struct Loop { @@ -54,6 +66,9 @@ pub impl Node for Loop with fn id(self) -> UInt { return self.id } +///| +pub extend Loop with Node::{id} + ///| /// A marker for a specific node type. See `Node::add_concat`. struct Concat { @@ -65,6 +80,9 @@ pub impl Node for Concat with fn id(self) -> UInt { return self.id } +///| +pub extend Concat with Node::{id} + ///| /// A marker for a specific node type. See `Node::add_pan`. struct Pan { @@ -76,6 +94,9 @@ pub impl Node for Pan with fn id(self) -> UInt { return self.id } +///| +pub extend Pan with Node::{id} + ///| /// A marker for a specific node type. See `Node::add_mute`. struct Mute { @@ -87,6 +108,9 @@ pub impl Node for Mute with fn id(self) -> UInt { return self.id } +///| +pub extend Mute with Node::{id} + ///| /// A marker for a specific node type. See `Node::add_pause`. struct Pause { @@ -98,6 +122,9 @@ pub impl Node for Pause with fn id(self) -> UInt { return self.id } +///| +pub extend Pause with Node::{id} + ///| /// A marker for a specific node type. See `Node::add_track_position`. struct TrackPosition { @@ -109,6 +136,9 @@ pub impl Node for TrackPosition with fn id(self) -> UInt { return self.id } +///| +pub extend TrackPosition with Node::{id} + ///| /// A marker for a specific node type. See `Node::add_low_pass`. struct LowPass { @@ -120,6 +150,9 @@ pub impl Node for LowPass with fn id(self) -> UInt { return self.id } +///| +pub extend LowPass with Node::{id} + ///| /// A marker for a specific node type. See `Node::add_high_pass`. struct HighPass { @@ -131,6 +164,9 @@ pub impl Node for HighPass with fn id(self) -> UInt { return self.id } +///| +pub extend HighPass with Node::{id} + ///| /// A marker for a specific node type. See `Node::add_take_left`. struct TakeLeft { @@ -142,6 +178,9 @@ pub impl Node for TakeLeft with fn id(self) -> UInt { return self.id } +///| +pub extend TakeLeft with Node::{id} + ///| /// A marker for a specific node type. See `Node::add_take_right`. struct TakeRight { @@ -153,6 +192,9 @@ pub impl Node for TakeRight with fn id(self) -> UInt { return self.id } +///| +pub extend TakeRight with Node::{id} + ///| /// A marker for a specific node type. See `Node::add_swap`. struct Swap { @@ -164,6 +206,9 @@ pub impl Node for Swap with fn id(self) -> UInt { return self.id } +///| +pub extend Swap with Node::{id} + ///| /// A marker for a specific node type. See `Node::add_clip`. struct Clip { @@ -175,6 +220,9 @@ pub impl Node for Clip with fn id(self) -> UInt { return self.id } +///| +pub extend Clip with Node::{id} + ///| /// Modulate the gain level. pub fn[Mod : Modulator] Gain::modulate( diff --git a/src/audio/source_nodes.mbt b/src/audio/source_nodes.mbt index 5a43151..d0f3510 100644 --- a/src/audio/source_nodes.mbt +++ b/src/audio/source_nodes.mbt @@ -9,6 +9,9 @@ pub impl SourceNode for Sine with fn id(self) -> UInt { return self.id } +///| +pub extend Sine with SourceNode::{id} + ///| /// A marker for a specific node type. See `Node::add_square`. struct Square { @@ -20,6 +23,9 @@ pub impl SourceNode for Square with fn id(self) -> UInt { return self.id } +///| +pub extend Square with SourceNode::{id} + ///| /// A marker for a specific node type. See `Node::add_sawtooth`. struct Sawtooth { @@ -31,6 +37,9 @@ pub impl SourceNode for Sawtooth with fn id(self) -> UInt { return self.id } +///| +pub extend Sawtooth with SourceNode::{id} + ///| /// A marker for a specific node type. See `Node::add_triangle`. struct Triangle { @@ -42,6 +51,9 @@ pub impl SourceNode for Triangle with fn id(self) -> UInt { return self.id } +///| +pub extend Triangle with SourceNode::{id} + ///| /// A marker for a specific node type. See `Node::add_noise`. struct Noise { @@ -53,6 +65,9 @@ pub impl SourceNode for Noise with fn id(self) -> UInt { return self.id } +///| +pub extend Noise with SourceNode::{id} + ///| /// A marker for a specific node type. See `Node::add_empty`. struct Empty { @@ -64,6 +79,9 @@ pub impl SourceNode for Empty with fn id(self) -> UInt { return self.id } +///| +pub extend Empty with SourceNode::{id} + ///| /// A marker for a specific node type. See `Node::add_zero`. struct Zero { @@ -75,6 +93,9 @@ pub impl SourceNode for Zero with fn id(self) -> UInt { return self.id } +///| +pub extend Zero with SourceNode::{id} + ///| /// A marker for a specific node type. See `Node::add_file`. struct File { @@ -86,6 +107,9 @@ pub impl SourceNode for File with fn id(self) -> UInt { return self.id } +///| +pub extend File with SourceNode::{id} + ///| /// Modulate oscillation frequency. pub fn[Mod : Modulator] Sine::modulate( diff --git a/src/graphics_angle.mbt b/src/graphics_angle.mbt index 1cad8e7..1313a4f 100644 --- a/src/graphics_angle.mbt +++ b/src/graphics_angle.mbt @@ -4,7 +4,7 @@ struct Angle(Float) derive(Debug, Eq, Compare, Hash, Default) ///| pub impl Show for Angle with fn output(self : Angle, logger : &Logger) -> Unit { - self.to_deg().to_int().output(logger) + Show::output(self.to_deg().to_int(), logger) logger.write_char('°') } diff --git a/src/graphics_color.mbt b/src/graphics_color.mbt index 3870cbf..66551a0 100644 --- a/src/graphics_color.mbt +++ b/src/graphics_color.mbt @@ -64,11 +64,17 @@ pub impl Show for Color with fn to_string(self : Color) -> String { } } +///| +pub extend Color with Show::{output, to_string} + ///| pub impl Default for Color with fn default() -> Color { Color::None } +///| +pub extend Color with Default::{default} + ///| pub fn Color::to_byte(color : Color) -> Byte { match color { diff --git a/src/graphics_linestyle.mbt b/src/graphics_linestyle.mbt index a09f00b..d579425 100644 --- a/src/graphics_linestyle.mbt +++ b/src/graphics_linestyle.mbt @@ -9,7 +9,7 @@ pub(all) struct LineStyle { ///| /// Shorthand for creating a new LineStyle. pub fn LineStyle::new(color : Color, width? : Int = 1) -> LineStyle { - { color, width } + { color, width, } } ///| diff --git a/src/graphics_point.mbt b/src/graphics_point.mbt index db6f779..59e61c7 100644 --- a/src/graphics_point.mbt +++ b/src/graphics_point.mbt @@ -11,7 +11,7 @@ pub(all) struct Point { ///| /// Shortcut for creating a `Point`. pub fn Point::new(x : Int, y : Int) -> Point { - Point::{ x, y } + Point::{ x, y, } } ///| @@ -27,13 +27,13 @@ pub fn Point::new_screen() -> Point { /// Note that a `Size` does not allow negative values. /// Any negative values are clamped to zero. pub fn Point::to_size(self : Point) -> Size { - Size::{ w: self.x, h: self.y } + Size::{ w: self.x, h: self.y, } } ///| /// Convert the `Point` to a `Pad`. pub fn Point::as_pad(self : Point) -> Pad { - Pad::{ x: self.x, y: self.y } + Pad::{ x: self.x, y: self.y, } } ///| @@ -64,7 +64,7 @@ test "azimuth" { /// Returns a new `Point` where both `x` and `y` are set to the minimum /// of their respective values between both points. pub fn Point::component_min(self : Point, other : Point) -> Point { - Point::{ x: @cmp.minimum(self.x, other.x), y: @cmp.minimum(self.y, other.y) } + Point::{ x: @cmp.minimum(self.x, other.x), y: @cmp.minimum(self.y, other.y), } } ///| @@ -99,7 +99,7 @@ test "Point.component_min" { /// Returns a new `Point` where both `x` and `y` are set to the maximum /// of their respective values between both points. pub fn Point::component_max(self : Point, other : Point) -> Point { - Point::{ x: @cmp.maximum(self.x, other.x), y: @cmp.maximum(self.y, other.y) } + Point::{ x: @cmp.maximum(self.x, other.x), y: @cmp.maximum(self.y, other.y), } } ///| @@ -133,31 +133,31 @@ test "Point.component_max" { ///| /// Returns a `Point` with absolute (non-negative) `x` and `y` values. pub fn Point::abs(self : Point) -> Point { - Point::{ x: self.x.abs(), y: self.y.abs() } + Point::{ x: self.x.abs(), y: self.y.abs(), } } ///| /// Add together two points. pub impl Add for Point with fn add(self : Point, other : Point) -> Point { - { x: self.x + other.x, y: self.y + other.y } + { x: self.x + other.x, y: self.y + other.y, } } ///| /// Subtract one point from another. pub impl Sub for Point with fn sub(self : Point, other : Point) -> Point { - { x: self.x - other.x, y: self.y - other.y } + { x: self.x - other.x, y: self.y - other.y, } } ///| /// Negate a Point. pub impl Neg for Point with fn neg(self : Point) -> Point { - { x: -self.x, y: -self.y } + { x: -self.x, y: -self.y, } } ///| /// Divide a point by a scalar. pub fn Point::scale_down(self : Point, divisor : Int) -> Point { - { x: self.x / divisor, y: self.y / divisor } + { x: self.x / divisor, y: self.y / divisor, } } ///| diff --git a/src/graphics_rgb.mbt b/src/graphics_rgb.mbt index 6761b23..f7f6a12 100644 --- a/src/graphics_rgb.mbt +++ b/src/graphics_rgb.mbt @@ -10,5 +10,5 @@ pub(all) struct RGB { ///| /// Shorthand for creating a new RGB. pub fn RGB::new(r : Byte, g : Byte, b : Byte) -> RGB { - { r, g, b } + { r, g, b, } } diff --git a/src/graphics_size.mbt b/src/graphics_size.mbt index 8de467e..c6fed62 100644 --- a/src/graphics_size.mbt +++ b/src/graphics_size.mbt @@ -19,7 +19,7 @@ pub(all) struct Size { ///| /// Shortcut for creating a Size. pub fn Size::new(w : Int, h : Int) -> Size { - Size::{ w, h } + Size::{ w, h, } } ///| @@ -32,14 +32,14 @@ pub fn Size::new_screen() -> Size { ///| /// Convert the `Size` to a `Point`. pub fn Size::to_point(self : Size) -> Point { - Point::{ x: self.w, y: self.h } + Point::{ x: self.w, y: self.h, } } ///| /// Returns a new `Size` where both `w` and `h` are set to the minimum /// of their respective values between both sizes. pub fn Size::component_min(self : Size, other : Size) -> Size { - Size::{ w: @cmp.minimum(self.w, other.w), h: @cmp.minimum(self.h, other.h) } + Size::{ w: @cmp.minimum(self.w, other.w), h: @cmp.minimum(self.h, other.h), } } ///| @@ -74,7 +74,7 @@ test "Size.component_min" { /// Returns a new `Size` where both `x` and `h` are set to the maximum /// of their respective values between both sizes. pub fn Size::component_max(self : Size, other : Size) -> Size { - Size::{ w: @cmp.maximum(self.w, other.w), h: @cmp.maximum(self.h, other.h) } + Size::{ w: @cmp.maximum(self.w, other.w), h: @cmp.maximum(self.h, other.h), } } ///| @@ -108,11 +108,11 @@ test "Size.component_max" { ///| /// Add together two sizes. pub impl Add for Size with fn add(self : Size, other : Size) -> Size { - { w: self.w + other.w, h: self.h + other.h } + { w: self.w + other.w, h: self.h + other.h, } } ///| /// Subtract one size from another. pub impl Sub for Size with fn sub(self : Size, other : Size) -> Size { - { w: self.w - other.w, h: self.h - other.h } + { w: self.w - other.w, h: self.h - other.h, } } diff --git a/src/graphics_style.mbt b/src/graphics_style.mbt index b3e722b..299a3ab 100644 --- a/src/graphics_style.mbt +++ b/src/graphics_style.mbt @@ -14,17 +14,17 @@ pub fn Style::new( stroke? : Color = None, stroke_width? : Int = 1, ) -> Style { - Style::{ fill, stroke, stroke_width } + Style::{ fill, stroke, stroke_width, } } ///| /// Create a style for a solid shape (without stroke). pub fn Style::new_solid(color : Color) -> Style { - Style::{ fill: color, stroke: None, stroke_width: 0 } + Style::{ fill: color, stroke: None, stroke_width: 0, } } ///| /// Create a style for an outlined shape (without fill). pub fn Style::new_outlined(color : Color, width? : Int = 1) -> Style { - Style::{ fill: None, stroke: color, stroke_width: width } + Style::{ fill: None, stroke: color, stroke_width: width, } } diff --git a/src/input_pad.mbt b/src/input_pad.mbt index 163c6dd..2335109 100644 --- a/src/input_pad.mbt +++ b/src/input_pad.mbt @@ -41,7 +41,7 @@ pub(all) struct Pad { ///| /// Shorthand for creating a new `Pad`. pub fn Pad::new(x : Int, y : Int) -> Pad { - Pad::{ x, y } + Pad::{ x, y, } } ///| @@ -59,7 +59,7 @@ pub fn Pad::read(peer? : Peer = Peer::default()) -> Pad? { ///| /// Convert the `Pad` to a `Point`. pub fn Pad::as_point(self : Pad) -> Point { - Point::{ x: self.x, y: self.y } + Point::{ x: self.x, y: self.y, } } ///| @@ -144,23 +144,23 @@ pub fn Pad::radius_squared(self : Pad) -> Int { ///| /// Returns a `Pad` with absolute (non-negative) `x` and `y` values. pub fn Pad::abs(self : Pad) -> Pad { - Pad::{ x: self.x.abs(), y: self.y.abs() } + Pad::{ x: self.x.abs(), y: self.y.abs(), } } ///| /// Add together two Pads. pub impl Add for Pad with fn add(self : Pad, other : Pad) -> Pad { - { x: self.x + other.x, y: self.y + other.y } + { x: self.x + other.x, y: self.y + other.y, } } ///| /// Subtract one Pad from another. pub impl Sub for Pad with fn sub(self : Pad, other : Pad) -> Pad { - { x: self.x - other.x, y: self.y - other.y } + { x: self.x - other.x, y: self.y - other.y, } } ///| /// Negate a Pad. pub impl Neg for Pad with fn neg(self : Pad) -> Pad { - { x: -self.x, y: -self.y } + { x: -self.x, y: -self.y, } } diff --git a/src/misc.mbt b/src/misc.mbt index 5de01ef..dce5650 100644 --- a/src/misc.mbt +++ b/src/misc.mbt @@ -78,7 +78,7 @@ pub fn get_random() -> UInt { ///| pub fn get_time() -> Duration { - { us: @ffi.get_time() } + { us: @ffi.get_time(), } } ///| diff --git a/src/misc_duration.mbt b/src/misc_duration.mbt index 8d6c407..83f0588 100644 --- a/src/misc_duration.mbt +++ b/src/misc_duration.mbt @@ -10,18 +10,18 @@ pub fn Duration::from_microseconds(us : Int64) -> Duration { ///| pub fn Duration::from_milliseconds(ms : Int64) -> Duration { - { us: ms * 1000 } + { us: ms * 1000, } } ///| pub fn Duration::from_seconds(s : Int64) -> Duration { - { us: s * 1_000_000 } + { us: s * 1_000_000, } } ///| /// Add two durations. pub fn Duration::add(self : Duration, rhs : Duration) -> Duration { - Duration::{ us: self.us + rhs.us } + Duration::{ us: self.us + rhs.us, } } ///| @@ -44,5 +44,5 @@ pub fn Duration::to_seconds(self : Duration) -> Int64 { ///| pub impl Neg for Duration with fn neg(self) -> Duration { - { us: -self.us } + { us: -self.us, } } diff --git a/src/misc_language.mbt b/src/misc_language.mbt index 7523b73..18a9499 100644 --- a/src/misc_language.mbt +++ b/src/misc_language.mbt @@ -33,6 +33,9 @@ pub impl Default for Language with fn default() -> Language { Language::English } +///| +pub extend Language with Default::{default} + ///| pub fn Language::from_raw(raw : UInt16) -> Language? { match raw { diff --git a/src/misc_theme.mbt b/src/misc_theme.mbt index 72b10a1..29bef19 100644 --- a/src/misc_theme.mbt +++ b/src/misc_theme.mbt @@ -22,3 +22,6 @@ pub impl Default for Theme with fn default() -> Theme { bg: Color::White, } } + +///| +pub extend Theme with Default::{default} diff --git a/src/net.mbt b/src/net.mbt index fa7ec1f..5e9a986 100644 --- a/src/net.mbt +++ b/src/net.mbt @@ -40,22 +40,10 @@ pub impl AnyPeer for Peer with fn to_int(self : Peer) -> Int { } ///| -pub impl Show for Peer with fn to_string(self) -> String { +pub impl Debug for Peer with fn to_repr(self) -> Repr { match self.raw { - 0xFF => "Peer(*)" - _ => "Peer(\{self.raw})" - } -} - -///| -pub impl Show for Peer with fn output(self, logger : &Logger) -> Unit { - match self.raw { - 0xFF => logger.write_string("Peer(*)") - _ => { - logger.write_string("Peer(") - logger.write_char((self.raw + '0').to_char().unwrap_or('?')) - logger.write_char(')') - } + 0xFF => Repr::opaque_("Peer", Repr::literal("any")) + _ => Repr::opaque_("Peer", Repr::integer(self.raw.to_string())) } } @@ -64,7 +52,7 @@ pub impl Show for Peer with fn output(self, logger : &Logger) -> Unit { /// /// Useful for single-player games that don't have any special logic for multiplayer. pub fn Peer::combined() -> Peer { - Peer::{ raw: 0xFF } + Peer::{ raw: 0xFF, } } ///| @@ -74,6 +62,9 @@ pub impl Default for Peer with fn default() -> Peer { Peer::combined() } +///| +pub extend Peer with Default::{default} + ///| /// The map of peers online. /// @@ -102,9 +93,9 @@ pub fn Peers::to_fixed_array(self : Peers) -> FixedArray[Peer] { ///| pub fn Peers::to_array(self : Peers) -> Array[Peer] { - let res : Array[Peer] = Array::new() + let res : Array[Peer] = Array() for peer in 0..<32 { - let peer = Peer::{ raw: peer } + let peer = Peer::{ raw: peer, } if self.contains(peer) { res.push(peer) } @@ -112,24 +103,58 @@ pub fn Peers::to_array(self : Peers) -> Array[Peer] { res } +///| +test "peer debug" { + debug_inspect( + Peer::{ raw: 0xff, }, + content=( + #| + ), + ) + debug_inspect( + Peer::{ raw: 1, }, + content=( + #| + ), + ) +} + ///| test "peers to array" { - inspect(Peers::{ raw: 0b0000_0000 }.to_array(), content="[]") - inspect(Peers::{ raw: 0b0000_0001 }.to_array(), content="[Peer(0)]") - inspect( - Peers::{ raw: 0b0010_1101 }.to_array(), - content="[Peer(0), Peer(2), Peer(3), Peer(5)]", + debug_inspect(Peers::{ raw: 0b0000_0000, }.to_array(), content="[]") + debug_inspect( + Peers::{ raw: 0b0000_0001, }.to_array(), + content=( + #|[] + ), + ) + debug_inspect( + Peers::{ raw: 0b0010_1101, }.to_array(), + content=( + #|[, , , ] + ), ) - inspect( - Peers::{ raw: 0b1111_1111 }.to_array(), - content="[Peer(0), Peer(1), Peer(2), Peer(3), Peer(4), Peer(5), Peer(6), Peer(7)]", + debug_inspect( + Peers::{ raw: 0b1111_1111, }.to_array(), + content=( + #|[ + #| , + #| , + #| , + #| , + #| , + #| , + #| , + #| , + #|] + ), ) } ///| /// Get the `Peer` representing the local device. pub fn get_me() -> Me { - Me::{ raw: @ffi.get_me() } + Me::{ raw: @ffi.get_me(), } } ///| @@ -140,7 +165,7 @@ pub fn get_me() -> Me { /// It can be used to detect if multiplayer is active: /// if there is more than 1 peer, you're playing with friends. pub fn get_peers() -> Peers { - Peers::{ raw: @ffi.get_peers() } + Peers::{ raw: @ffi.get_peers(), } } ///| diff --git a/src/random/moon.pkg b/src/random/moon.pkg index c856a09..2bd6aa0 100644 --- a/src/random/moon.pkg +++ b/src/random/moon.pkg @@ -1,5 +1,4 @@ import { - "moonbitlang/core/cmp", "moonbitlang/core/uint", "moonbitlang/core/int", "firefly/firefly", diff --git a/src/shapes/circle.mbt b/src/shapes/circle.mbt index 3837787..6a0c2a7 100644 --- a/src/shapes/circle.mbt +++ b/src/shapes/circle.mbt @@ -20,7 +20,7 @@ pub impl Shape for Circle with fn draw(self : Circle) -> Unit { pub fn Circle::as_ellipse(self : Circle) -> Ellipse { Ellipse::{ point: self.point, - size: Size::{ w: self.diameter, h: self.diameter }, + size: Size::{ w: self.diameter, h: self.diameter, }, style: self.style, } } diff --git a/src/shapes/ellipse.mbt b/src/shapes/ellipse.mbt index ca07175..1d7432a 100644 --- a/src/shapes/ellipse.mbt +++ b/src/shapes/ellipse.mbt @@ -21,5 +21,5 @@ pub fn Ellipse::as_circle( self : Ellipse, diameter? : Int = @cmp.maximum(self.size.w, self.size.h), ) -> Circle { - Circle::{ point: self.point, diameter, style: self.style } + Circle::{ point: self.point, diameter, style: self.style, } } diff --git a/src/shapes/rect.mbt b/src/shapes/rect.mbt index ba6175d..f48c33d 100644 --- a/src/shapes/rect.mbt +++ b/src/shapes/rect.mbt @@ -21,5 +21,10 @@ pub fn Rect::as_rect( self : Rect, corner? : Size = Size::default(), ) -> RoundedRect { - RoundedRect::{ point: self.point, size: self.size, corner, style: self.style } + RoundedRect::{ + point: self.point, + size: self.size, + corner, + style: self.style, + } } diff --git a/src/shapes/rounded_rect.mbt b/src/shapes/rounded_rect.mbt index 05bfef7..1c86952 100644 --- a/src/shapes/rounded_rect.mbt +++ b/src/shapes/rounded_rect.mbt @@ -19,5 +19,5 @@ pub impl Shape for RoundedRect with fn draw(self : RoundedRect) -> Unit { /// /// The corner size information is dropped in this conversion. pub fn RoundedRect::as_rect(self : RoundedRect) -> Rect { - Rect::{ point: self.point, size: self.size, style: self.style } + Rect::{ point: self.point, size: self.size, style: self.style, } } diff --git a/src/stats.mbt b/src/stats.mbt index 2d3e5e6..61f0a4e 100644 --- a/src/stats.mbt +++ b/src/stats.mbt @@ -52,7 +52,7 @@ pub fn get_score(peer : Peer, board : Board) -> Int16 { ///| fn Progress::parse(result : UInt) -> Progress { - Progress::{ done: (result >> 16).to_uint16(), goal: result.to_uint16() } + Progress::{ done: (result >> 16).to_uint16(), goal: result.to_uint16(), } } ///|