rewrote counter constructor
@@ -27,31 +27,32 @@ impl @counter {
@counter::new(5i) // creates a new counter that uses item ID 5
@counter::new(true) // creates a new counter with a starting value of true (1)
")] (
- #[desc("Source (can be a number, item ID or boolean)")] source: @number | @item | @bool = 0,
+ #[desc("Source (can be a number, item ID or boolean)")] source: @number | @item | @counter | @bool = 0,
#[desc(
"Defines the maximum stable size of the counter. If the counter goes outside of the range from 0 to 2^size, it's behavior will be undefined. Smaller sizes are more group effective."
)] bits: @number = DEFAULT_BITS,
#[desc("Resets the counter in case the item has been used before. This only applies if the `source` argument is not an item.")] reset: @bool = true,
) -> @counter {
- let out = null
- if source.type == @number {
+ return switch source.type {
+ @number: (){
id = ?i
- if source != 0 {
- id.add(source)
- }
+ if source != 0 { id.add(source) }
out = @counter::{
item: id,
- bits
+ bits,
}
if reset && $.trigger_fn_context() != 0g {
reset_counter(out) // in case the item has been used before
}
- } else if source.type == @item {
- out = @counter::{
+ return out
+ }(),
+ @item: (){
+ return @counter::{
item: source,
- bits
+ bits,
}
- } else if source.type == @bool {
+ }(),
+ @bool: (){
if bits != DEFAULT_BITS && bits != 1 {
throw "A boolean counter can only have size = 1"
}
@@ -67,10 +68,13 @@ impl @counter {
if reset && $.trigger_fn_context() != 0g {
reset_counter(out) // in case the item has been used before
}
- }
-
-
return out
+ }(),
+ @counter: (){
+ return source.clone()
+ }(),
+ else: @counter::{ item: ?i, bits: bits, },
+ }
}
}
impl @counter {
