protected override void EmitSetPropertyValidator(CodeStatementCollection stmts, CodeTypeDeclaration type, CodeSnippetExpression storage, CodeTypeReference interfaceType, bool changed, string name) { FloatCompression[] ac = Decorator.PropertyType.Compression; for (int i = 0; i < ac.Length; ++i) { FloatCompression c = ac[i]; if (c.Enabled) { char axis = (char)(120 + i); #if DEBUG stmts.If("value.{2} < {0}f || value.{2} > {1}f".Expr(c.MinValue, c.MaxValue, axis), ifBody => { ifBody.Expr( "Ascension.Networking.NetLog.Warn(\"Axis '{3}' of property '{0}' is being set to a value larger than the compression settings, it will be clamped to [{1}f, {2}f]\")", Decorator.Definition.Name, c.MinValue.ToStringSigned(), c.MaxValue.ToStringSigned(), axis); }); #endif stmts.Expr("value.{2} = UnityEngine.Mathf.Clamp(value.{2}, {0}, {1})", c.MinValue, c.MaxValue, axis); } } }
protected void EmitAllowedCheck(CodeStatementCollection stmts) { #if DEBUG string error = null; switch (Decorator.Definition.ReplicationMode) { case ReplicationMode.EveryoneExceptController: error = @"var en = this.RootState.Entity; if(!en.IsOwner && !en.HasControl) {{ Ascension.Networking.NetLog.Error(""Only the owner and controller can modify: '{0}'""); return; }}"; break; case ReplicationMode.Everyone: error = @"var en = this.RootState.Entity; if(!en.IsOwner) {{ Ascension.Networking.NetLog.Error(""Only the owner can modify: '{0}'""); return; }}"; break; case ReplicationMode.OnlyOwnerAndController: error = @"var en = this.RootState.Entity; if(!en.IsOwner && en.HasControl) {{ Ascension.Networking.NetLog.Error(""Controller is not allowed to modify '{0}'""); return; }}"; break; } if (error != null) { stmts.Expr(error, Decorator.Definition.Name); } #endif }
protected override void EmitSetPropertyValidator(CodeStatementCollection stmts, CodeTypeDeclaration type, CodeSnippetExpression storage, CodeTypeReference interfaceType, bool changed, string name) { PropertyTypeInteger p = Decorator.PropertyType; if (p.CompressionEnabled && p.BitsRequired < 32) { #if DEBUG stmts.If("value < {0} || value > {1}".Expr(p.MinValue, p.MaxValue), ifBody => { ifBody.Expr( "Ascension.Networking.NetLog.Warn(\"Property '{0}' is being set to a value larger than the compression settings, it will be clamped to [{1}, {2}]\")", Decorator.Definition.Name, p.MinValue.ToStringSigned(), p.MaxValue.ToStringSigned()); }); #endif stmts.Expr("value = UnityEngine.Mathf.Clamp(value, {0}, {1})", p.MinValue, p.MaxValue); } }
public static CodeVariableReferenceExpression Var(this CodeStatementCollection stmts, string type, string name) { stmts.Expr("{0} {1}", type, name); return(new CodeVariableReferenceExpression(name)); }