diff --git a/sjscript/src/sjscript/ParametersBlock.d b/sjscript/src/sjscript/ParametersBlock.d index bb91003..29d083b 100644 --- a/sjscript/src/sjscript/ParametersBlock.d +++ b/sjscript/src/sjscript/ParametersBlock.d @@ -34,6 +34,7 @@ struct Period { enum ParameterType { Assign, AddAssign, + OnceAssign, } /// diff --git a/sjscript/src/sjscript/Token.d b/sjscript/src/sjscript/Token.d index 529d3d9..8c54899 100644 --- a/sjscript/src/sjscript/Token.d +++ b/sjscript/src/sjscript/Token.d @@ -73,6 +73,7 @@ enum TokenType { @TextCompleteMatcher!"=" Assign, @TextCompleteMatcher!"+=" AddAssign, + @TextCompleteMatcher!":=" ColonAssign, @TextCompleteMatcher!"+" Add, @TextCompleteMatcher!"-" Sub, diff --git a/sjscript/src/sjscript/parse.d b/sjscript/src/sjscript/parse.d index c43fb93..df578d3 100644 --- a/sjscript/src/sjscript/parse.d +++ b/sjscript/src/sjscript/parse.d @@ -94,6 +94,14 @@ private class RuleSet { return Parameter( ident.text, ParameterType.AddAssign, expr, CreateTokenPos(ident, semicolon)); } + static Parameter ParseOnceAssignParameter( + @(TokenType.Ident) Token ident, + @(TokenType.ColonAssign) Token, + Expression expr, + @(TokenType.SemiColon) Token semicolon) { + return Parameter( + ident.text, ParameterType.OnceAssign, expr, CreateTokenPos(ident, semicolon)); + } static Expression ParseExpressionFromFirstTerm(Term term) { return Expression([term]); diff --git a/sjscript/test/test01.sj b/sjscript/test/test01.sj index 07c7661..931f608 100644 --- a/sjscript/test/test01.sj +++ b/sjscript/test/test01.sj @@ -1,16 +1,34 @@ // this is comment +$define sinwave { + translate_x = $sinwave_add_x + sin(rtime * $sinwave_hz) * $sinwave_amp_x; + translate_y = $sinwave_add_y + cos(rtime * $sinwave_hz) * $sinwave_amp_y; +} $define horming { translate_x += cos(atan(player_y, player_x)) * $horming_speed; translate_y += sin(atan(player_y, player_x)) * $horming_speed; } +$define shoot { + __dir_x := cos(atan(player_y, player_x)) * $shoot_speed; + __dir_y := sin(atan(player_y, player_x)) * $shoot_speed; -A [0..10] { - translate_x = 0.5 + sin(rtime)*0.5; - translate_y = 0.5 + cos(rtime)*0.5; + translate_x += __dir_x; + translate_y += __dir_y; } -B [5..15] { +A [0..10] { + $define sinwave_add_x {0.5} + $define sinwave_add_y {0.5} + $define sinwave_amp_x {0.5} + $define sinwave_amp_y {0.5} + $define sinwave_hz {2} + $sinwave +} +B [10..20] { $define horming_speed {0.1} $horming } +C [20..30] { + $define shoot_speed {0.1} + $shoot +}