// Attempt to resubmit the scoress
 public void resubmitSotredScores()
 {
     if (GKLocalPlayer.LocalPlayer.Authenticated && storedScores.Count != 0)
     {
         int index = (int)storedScores.Count - 1;
         while (index >= 0)
         {
             GKScore score = new GKScore(storedScores.ValueAt((uint)index));
             score.ShouldSetDefaultLeaderboard = true;
             if (score == null)
             {
                 return;
             }
             score.ReportScore(new GKNotificationHandler((error) =>
             {
                 if (error == null)
                 {
                     new UIAlertView("Score Submitted", "Score submitted successfully ", null, "OK", null).Show();
                 }
                 else
                 {
                     this.storeScore(score);
                     new UIAlertView("Score Stored", "Score Stored ", null, "OK", null).Show();
                 }
             }));
             storedScores.RemoveObject(index);
             index--;
         }
     }
 }
		public override void SetupSlide (PresentationViewController presentationViewController)
		{
			// Create a node to own the "sign" model, make it to be close to the camera, rotate by 90 degree because it's oriented with z as the up axis
			var intermediateNode = SCNNode.Create ();
			intermediateNode.Position = new SCNVector3 (0, 0, 7);
			intermediateNode.Rotation = new SCNVector4 (1, 0, 0, -(float)(Math.PI / 2));
			GroundNode.AddChildNode (intermediateNode);

			// Load the "sign" model
			var signNode = Utils.SCAddChildNode (intermediateNode, "sign", "Scenes/intersection/intersection", 30);
			signNode.Position = new SCNVector3 (4, -2, 0.05f);

			// Re-parent every node that holds a camera otherwise they would inherit the scale from the "sign" model.
			// This is not a problem except that the scale affects the zRange of cameras and so it would be harder to get the transition from one camera to another right
			var cameraNodes = new NSMutableArray ();
			foreach (SCNNode child in signNode) {
				if (child.Camera != null)
					cameraNodes.Add (child);
			}

			for (nuint i = 0; i < cameraNodes.Count; i++) {
				var cameraNode = new SCNNode (cameraNodes.ValueAt ((uint)i));
				var previousWorldTransform = cameraNode.WorldTransform;
				intermediateNode.AddChildNode (cameraNode); // re-parent
				cameraNode.Transform = intermediateNode.ConvertTransformFromNode (previousWorldTransform, null);
				cameraNode.Scale = new SCNVector3 (1, 1, 1);
			}
		}
Beispiel #3
0
        public override void SetupSlide(PresentationViewController presentationViewController)
        {
            // Create a node to own the "sign" model, make it to be close to the camera, rotate by 90 degree because it's oriented with z as the up axis
            var intermediateNode = SCNNode.Create();

            intermediateNode.Position = new SCNVector3(0, 0, 7);
            intermediateNode.Rotation = new SCNVector4(1, 0, 0, -(float)(Math.PI / 2));
            GroundNode.AddChildNode(intermediateNode);

            // Load the "sign" model
            var signNode = Utils.SCAddChildNode(intermediateNode, "sign", "Scenes/intersection/intersection", 30);

            signNode.Position = new SCNVector3(4, -2, 0.05f);

            // Re-parent every node that holds a camera otherwise they would inherit the scale from the "sign" model.
            // This is not a problem except that the scale affects the zRange of cameras and so it would be harder to get the transition from one camera to another right
            var cameraNodes = new NSMutableArray();

            foreach (SCNNode child in signNode)
            {
                if (child.Camera != null)
                {
                    cameraNodes.Add(child);
                }
            }

            for (nuint i = 0; i < cameraNodes.Count; i++)
            {
                var cameraNode             = new SCNNode(cameraNodes.ValueAt((uint)i));
                var previousWorldTransform = cameraNode.WorldTransform;
                intermediateNode.AddChildNode(cameraNode);                  // re-parent
                cameraNode.Transform = intermediateNode.ConvertTransformFromNode(previousWorldTransform, null);
                cameraNode.Scale     = new SCNVector3(1, 1, 1);
            }
        }
Beispiel #4
0
        static NSExpression ToExpression(NSArray array)
        {
            var objects   = SubArray(array, 0);
            var @operator = objects[0].ToString();
            var arguments = SubArray(objects, 1);

            if (OperatorMap.TryGetValue(@operator, out var functionName))
            {
                var subexpressions = ToSubexpressions(arguments);
                switch (functionName)
                {
                case "+":
                    if (subexpressions.Count > 2)
                    {
                        var sumArguments = NSExpression.FromAggregate(subexpressions.ToArray());

                        return(NSExpression.FromFunction("sum:", new[] { sumArguments }));
                    }

                    break;

                case "^":
                    if (arguments[0].ToString() == "e")
                    {
                        functionName   = @"exp:";
                        subexpressions = SubArray(subexpressions, 1);
                    }

                    break;

                default:
                    break;
                }

                return(NSExpression.FromFunction(functionName, subexpressions.ToArray()));
            }
            else
            {
                switch (@operator)
                {
                case "collator":
                    return(NSExpression.FromFunction("MGL_FUNCTION", ToSubexpressions(objects).ToArray()));

                case "literal":
                    if (arguments[0] is NSArray literalArray)
                    {
                        return(NSExpression.FromConstant(literalArray));
                        // WARNING This may be wrong
                        //var expressions = ToSubexpressions(SubArray(literalArray, 0));
                        //return NSExpression.FromAggregate(expressions.ToArray());
                    }

                    return(ToExpression(arguments[0]));

                case "to-boolean": {
                    var operand = ToExpression(arguments[0]);
                    return(NSExpression.FromFunction(operand, "boolValue", new NSExpression[0]));
                }

                case "to-number":
                case "number": {
                    var operand = ToExpression(arguments[0]);
                    if (arguments.Count == 1)
                    {
                        if (arguments[0] is NSNumber number)
                        {
                            return(NSExpression.FromFormat("%@", new NSObject[] { arguments[0] }));
                        }
                        return(NSExpression.FromFormat("CAST(%@, 'NSNumber')", new NSObject[] { operand }));
                    }
                    else
                    {
                        var innerArguments = SubArray(arguments, 1);
                        return(NSExpression.FromFunction(operand, "mgl_numberWithFallbackValues",
                                                         ToSubexpressions(innerArguments).ToArray()));
                    }
                }

                case "to-string":
                case "string": {
                    var operand = ToExpression(arguments[0]);
                    return(NSExpression.FromFormat("CAST(%@, 'NSString')", new NSObject[] { operand }));
                }

                case "to-color":
                case "color": {
                    var operand = ToExpression(arguments[0]);

                    if (arguments.Count == 1)
                    {
#if __IOS__
                        return(NSExpression.FromFormat("CAST(%@, 'UIColor')", new NSObject[] { operand }));
#else
                        return(NSExpression.FromFormat("CAST(%@, 'NSColor')", new NSObject[] { operand }));
#endif
                    }

                    return(NSExpression.FromFunction("MGL_FUNCTION", ToSubexpressions(objects).ToArray()));
                }

                case "to-rgba": {
                    var operand = ToExpression(arguments[0]);
                    return(NSExpression.FromFormat("CAST(noindex(%@), 'NSArray')", new NSObject[] { operand }));
                }

                case "get": {
                    if (arguments.Count == 2)
                    {
                        var operand = ToExpression(arguments[arguments.Count - 1]);

                        if (arguments[0] is NSString value)
                        {
                            return(NSExpression.FromFormat("%@.%K", new NSObject[] { operand, value }));
                        }

                        var keyExpression = ToExpression(arguments[0]);
                        return(NSExpression.FromFormat("%@.%@", new NSObject[] { operand, keyExpression }));
                    }

                    return(NSExpression.FromKeyPath(arguments[0].ToString()));
                }

                case "length": {
                    var subexpressions = ToSubexpressions(arguments);
                    var function       = @"count:";

                    if (subexpressions[0].ExpressionType == NSExpressionType.ConstantValue &&
                        subexpressions[0].ConstantValue is NSString value)
                    {
                        function = "length:";
                    }

                    return(NSExpression.FromFunction(function, new NSExpression[] { subexpressions[0] }));
                }
                    ;

                case "rgb": {
                    var subexpressions = ToSubexpressions(arguments);

                    return(UIColorAdditions.FromRgb(subexpressions.ToArray()));
                }

                case "rgba": {
                    var subexpressions = ToSubexpressions(arguments);

                    return(UIColorAdditions.FromRgba(subexpressions.ToArray()));
                }

                case "min":
                case "max": {
                    var subexpressions = ToSubexpressions(arguments);
                    var subexpression  = NSExpression.FromAggregate(subexpressions.ToArray());
                    return(NSExpression.FromFunction(@operator, new[] { subexpression }));
                }

                case "e": {
                    return(NSExpression.FromConstant(NSNumber.FromDouble(Math.E)));
                }

                case "pi": {
                    return(NSExpression.FromConstant(NSNumber.FromDouble(Math.PI)));
                }

                case "concat": {
                    var subexpressions = ToSubexpressions(arguments);
                    var subexpression  = NSExpression.FromAggregate(subexpressions.ToArray());
                    return(NSExpression.FromFunction("mgl_join:", new[] { subexpression }));
                }

                case "at": {
                    var subexpressions = ToSubexpressions(arguments);

                    return(NSExpression.FromFunction("objectFrom:withIndex:",
                                                     new[] { subexpressions[1], subexpressions[0] }));
                }

                case "has": {
                    var subexpressions = ToSubexpressions(arguments);
                    var operand        = subexpressions.Count > 1
                                ? subexpressions[1]
                                : NSExpression.ExpressionForEvaluatedObject;
                    var key = subexpressions[0];
                    return(NSExpression.FromFunction("mgl_does:have:", new[] { operand, key }));
                }

                case "interpolate": {
                    var firstObject = arguments[0];
                    if (firstObject is NSArray == false)
                    {
                        return(null);
                    }

                    var interpolationOptions = SubArray((NSArray)firstObject);

                    var      curveType           = interpolationOptions[0].ToString();
                    var      curveTypeExpression = ToExpression(interpolationOptions[0]);
                    NSObject curveParameters;
                    switch (curveType)
                    {
                    case "linear": {
                        var temp = new NSMutableArray(2);
                        temp.Add((NSString)"literal");
                        temp.Add(NSNumber.FromDouble(1.0));
                        curveParameters = temp.Copy();
                        temp.Dispose();
                        break;
                    }

                    case "exponential":
                        curveParameters = interpolationOptions[1];
                        break;

                    case "cubic-bezier": {
                        var temp = new NSMutableArray(5);
                        temp.Add((NSString)"literal");
                        temp.Add(interpolationOptions[1]);
                        temp.Add(interpolationOptions[2]);
                        temp.Add(interpolationOptions[3]);
                        temp.Add(interpolationOptions[4]);
                        curveParameters = temp.Copy();
                        temp.Dispose();
                        break;
                    }

                    default:
                        curveParameters = NSNull.Null;
                        break;
                    }

                    var curveParameterExpression = ToExpression(curveParameters);
                    arguments = SubArray(arguments, 1);

                    var inputExpression = ToExpression(arguments[0]);
                    var stopExpressions = SubArray(arguments, 1);
                    var stops           = new NSMutableDictionary();
                    for (int i = 0; i < stopExpressions.Count; i++)
                    {
                        var keyExpression   = stopExpressions[i++];
                        var valueExpression = ToExpression(stopExpressions[i]);

                        stops[keyExpression] = valueExpression;
                    }

                    var stopExpression = NSExpression.FromConstant(stops);

                    return(NSExpression.FromFunction("mgl_interpolate:withCurveType:parameters:stops:", new[]
                        {
                            inputExpression,
                            curveTypeExpression,
                            curveParameterExpression,
                            stopExpression
                        }));
                }

                case "step": {
                    var          inputExpression  = ToExpression(arguments[0]);
                    var          stopExpressions  = SubArray(arguments, 1);
                    NSExpression miniumExpression = null;

                    if (stopExpressions.Count % 2 == 1)
                    {
                        miniumExpression = ToExpression(stopExpressions[0]);
                        stopExpressions  = SubArray(stopExpressions, 1);
                    }

                    var stops = new NSMutableDictionary();
                    for (int i = 0; i < stopExpressions.Count; i++)
                    {
                        var keyExpression   = stopExpressions[i++];
                        var valueExpression = ToExpression(stopExpressions[i]);

                        if (miniumExpression == null)
                        {
                            miniumExpression = valueExpression;
                            continue;
                        }

                        stops[keyExpression] = valueExpression;
                    }

                    if (miniumExpression == null)
                    {
                        return(null);
                    }

                    var stopExpression = NSExpression.FromConstant(stops);

                    return(NSExpression.FromFunction("mgl_step:from:stops:", new[]
                        {
                            inputExpression,
                            miniumExpression,
                            stopExpression
                        }));
                }

                case "zoom": {
                    return(NSExpression_MGLAdditions.ZoomLevelVariableExpression(null));
                }

                case "heatmap-density": {
                    return(NSExpression_MGLAdditions.HeatmapDensityVariableExpression(null));
                }

                case "line-progress": {
                    return(NSExpression_MGLAdditions.LineProgressVariableExpression(null));
                }

                case "geometry-type": {
                    return(NSExpression_MGLAdditions.GeometryTypeVariableExpression(null));
                }

                case "id": {
                    return(NSExpression_MGLAdditions.FeatureIdentifierVariableExpression(null));
                }

                case "properties": {
                    return(NSExpression_MGLAdditions.FeatureAttributesVariableExpression(null));
                }

                case "var": {
                    return(NSExpression.FromVariable(arguments[0].ToString()));
                }

                case "case": {
                    var args = new NSMutableArray();

                    for (int i = 0; i < arguments.Count; i++)
                    {
                        if (i % 2 == 0 & i != arguments.Count - 1)
                        {
                            var predicate = ToPredicate(arguments[i]);
                            var arg       = NSExpression.FromConstant(predicate);
                            args.Add(arg);
                        }
                        else
                        {
                            args.Add(ToExpression(arguments[i]));
                        }
                    }

                    if (args.Count == 3)
                    {
                        return(NSExpression.FromConditional(
                                   (NSPredicate)ObjCRuntime.Runtime.GetNSObject <NSExpression>(args.ValueAt(0))
                                   .ConstantValue,
                                   ObjCRuntime.Runtime.GetNSObject <NSExpression>(args.ValueAt(1)),
                                   ObjCRuntime.Runtime.GetNSObject <NSExpression>(args.ValueAt(2))));
                    }

                    return(NSExpression.FromFunction("MGL_IF",
                                                     NSArray.FromArray <NSExpression>((NSArray)args.Copy())));
                }

                case "match": {
                    var optionsArray = new NSMutableArray();

                    for (int i = 0; i < arguments.Count; i++)
                    {
                        NSExpression option = ToExpression(arguments[i]);

                        if (i > 0 && i < arguments.Count - 1 && !(i % 2 == 0) && arguments[i] is NSArray sub)
                        {
                            option = NSExpression.FromAggregate(ToSubexpressions(SubArray(sub)).ToArray());
                        }

                        optionsArray.Add(option);
                    }

                    return(NSExpression.FromFunction("MGL_MATCH",
                                                     NSArray.FromArray <NSExpression>((NSArray)optionsArray.Copy())));
                }

                case "format": {
                    var attributedExpressions = new List <NSExpression>();

                    for (int i = 0; i < arguments.Count; i += 2)
                    {
                        var expression = ToExpression(arguments[i]);
                        var attrs      = new NSMutableDictionary();

                        if (i + 1 < arguments.Count)
                        {
                            attrs = NSMutableDictionary.FromDictionary(arguments[i + 1] as NSDictionary);
                        }

                        foreach (var key in attrs.Keys)
                        {
                            attrs[key] = ToExpression(attrs[key]);
                        }

                        var attributedExpression = new MGLAttributedExpression(expression, attrs);

                        attributedExpressions.Add(NSExpression.FromConstant(attributedExpression));
                    }

                    return(NSExpression.FromFunction("mgl_attributed:", attributedExpressions.ToArray()));
                }

                case "coalesce": {
                    var subexpressions = ToSubexpressions(arguments);
                    return(NSExpression.FromFormat("mgl_coalesce(%@)", subexpressions.ToArray()));
                }

                default: {
                    var subexpressions = ToSubexpressions(objects);
                    return(NSExpression.FromFunction(@"MGL_FUNCTION", subexpressions.ToArray()));
                }
                }
            }
        }