Beispiel #1
0
 /// <summary>
 /// Converts one or more arguments of any type to string in the best way possible.
 /// </summary>
 /// <param name="what">Arguments that will converted to string.</param>
 /// <returns>The string formed by the given arguments.</returns>
 public static string Str(params Variant[] what)
 {
     using var whatGodot = new Godot.Collections.Array(what);
     NativeFuncs.godotsharp_str((godot_array)whatGodot.NativeValue, out godot_string ret);
     using (ret)
         return(Marshaling.ConvertStringToManaged(ret));
 }
Beispiel #2
0
 public ConnectAttribute(string nodePath, string signal, Godot.Collections.Array binds, ConnectFlags flags)
 {
     path = nodePath;
     sig  = signal;
     f    = (uint)flags;
     b    = binds;
 }
Beispiel #3
0
 public override void InitModule()
 {
     if (excludeBodies == null)
     {
         excludeBodies = new Godot.Collections.Array();
     }
 }
Beispiel #4
0
        public override void _Ready()
        {
            GetPopup().AddCheckItem("Show Inspector");
            GetPopup().AddCheckItem("Show Binder");
            GetPopup().AddCheckItem("Show Dock");
            GetPopup().AddCheckItem("Big Icons");

            Array         inspectorActionList = InputMap.GetActionList("inspector_toggle");
            InputEventKey inspectorKey        = (InputEventKey)inspectorActionList[0];

            GetPopup().SetItemAccelerator(0, inspectorKey.GetScancodeWithModifiers());

            Array         binderActionList = InputMap.GetActionList("binder_toggle");
            InputEventKey binderKey        = (InputEventKey)binderActionList[0];

            GetPopup().SetItemAccelerator(1, binderKey.GetScancodeWithModifiers());

            Array         dockActionList = InputMap.GetActionList("dock_toggle");
            InputEventKey dockKey        = (InputEventKey)dockActionList[0];

            GetPopup().SetItemAccelerator(2, dockKey.GetScancodeWithModifiers());

            GetPopup().Connect("index_pressed", this, nameof(OnItemPressed));

            CallDeferred(nameof(SetValues));
        }
Beispiel #5
0
        /// <summary>Sets the current inventory for a given <see cref="GridInventory"/>.</summary>
        /// <param name="inventory"><see cref="GridInventory"/> to set the inventory</param>
        /// <param name="hero">Is this being set for the <see cref="Hero"/>?</param>
        internal static void SetInventoryFromGrid(GridInventory inventory, bool hero = true)
        {
            Godot.Collections.Array allSlots = inventory.GetChild(0).GetChildren();
            List <Item>             allItems = new List <Item>();

            foreach (ItemSlot slot in allSlots)
            {
                if (slot?.Item?.Item != new Item() && slot.Item.Item.Name != "Fists")
                {
                    allItems.Add(slot?.Item?.Item);
                }
                else if (slot?.Item?.Item?.Name == "Fists")
                {
                    slot.RemoveChild(slot.GetChild(1));
                    slot.Item = new InventoryItem();
                }
            }
            if (hero)
            {
                CurrentHero.Inventory = allItems;
            }
            else
            {
                CurrentEnemy.Inventory = allItems;
            }
        }
Beispiel #6
0
        private void FillMesh(ref ArrayMesh mesh, bool calculateBounds, bool autoIndexFormat)
        {
            if (vertexCount > 65535)
            {
                if (autoIndexFormat)
                {
                    //FIXME
                    //mesh.indexFormat = IndexFormat.UInt32;
                }
                else
                {
                    // BEGIN: Modified by Microsoft Corporation for generic logging purposes.
                    API.MREAPI.Logger.LogError("A mesh can't have more than 65535 vertices with 16 bit index buffer. Vertex count: " + vertexCount);
                    // END: Modified by Microsoft Corporation for generic logging purposes.

                    //FIXME
                    //mesh.indexFormat = IndexFormat.UInt16;
                }
            }
            else
            {
                //FIXME
                //mesh.indexFormat = IndexFormat.UInt16;
            }
            //mesh.Name = name;
            var array = new Godot.Collections.Array();

            array.Resize((int)ArrayMesh.ArrayType.Max);

            if (vertices.Count > 0)
            {
                array[(int)ArrayMesh.ArrayType.Vertex] = vertices.ToArray();
            }
            if (normals.Count > 0)
            {
                array[(int)ArrayMesh.ArrayType.Normal] = normals.ToArray();
            }
            if (tangents.Count > 0)
            {
                array[(int)ArrayMesh.ArrayType.Tangent] = tangents.ToArray();
            }
            if (uv.Count > 0)
            {
                array[(int)ArrayMesh.ArrayType.TexUv] = uv.ToArray();
            }
            if (uv2.Count > 0)
            {
                array[(int)ArrayMesh.ArrayType.TexUv2] = uv2.ToArray();
            }
            if (colors.Count > 0)
            {
                array[(int)ArrayMesh.ArrayType.Color] = colors.ToArray();
            }
            if (triangles.Count > 0)
            {
                array[(int)ArrayMesh.ArrayType.Index] = triangles.ToArray();
            }

            mesh.AddSurfaceFromArrays(Godot.ArrayMesh.PrimitiveType.Triangles, array);
        }
Beispiel #7
0
        private static Node FindNode(Node Instance, string PathToNode)
        {
            // First, if we have an explicit node path, try that
            Node BoundNode = Instance.GetNodeOrNull(PathToNode);

            if (BoundNode != null)
            {
                return(BoundNode);
            }

            // Check if we have a child with the same name
            Godot.Collections.Array Children = Instance.GetChildren();
            foreach (Node Child in Children)
            {
                if (Child != null && Child.Name == PathToNode)
                {
                    return(Child);
                }
            }

            // Then check if a child has the node instead
            foreach (Node Child in Children)
            {
                BoundNode = FindNode(Child, PathToNode);
                if (BoundNode != null)
                {
                    return(BoundNode);
                }
            }

            return(null);
        }
Beispiel #8
0
        public static object WasEmittedWithArgs(Object emitter, string signal, Array arguments, string context)
        {
            var passed     = $"Signal {signal} was emitted from {emitter} with arguments {arguments}";
            var failed     = $"Signal {signal} was not emitted from {emitter} with arguments {arguments}";
            var altFailure = $"Signal {signal} was not emitted from {emitter}";

            var success = false;
            var result  = "";
            var watcher = (Object)emitter.GetMeta("watcher");
            var data    = (IDictionary)watcher.Call("get_data", signal);

            if ((int)data["emit_count"] <= 0)
            {
                success = false;
                result  = altFailure;
            }
            else if (FoundMatchingCall(arguments, (IEnumerable)data["calls"]))
            {
                success = true;
                result  = passed;
            }
            else
            {
                success = false;
                result  = failed;
            }

            return(Result(success, passed, result, context));
        }
Beispiel #9
0
 public override void UpdateModule(float delta)
 {
     if (excludeBodies == null)
     {
         excludeBodies = new Godot.Collections.Array();
     }
 }
Beispiel #10
0
		// Convert an AnatomyEngine mesh to a Godot mesh:
		public GodotMeshConverter(UVMesh mesh)
		{
			// Initialize the arrays that are needed:
			Godot.Collections.Array arrays = new Godot.Collections.Array();
			arrays.Resize((int)Mesh.ArrayType.Max);
			
			int vertexCount = mesh.VertexList.Count;
			
			Godot.Vector3[] normal_array = new Godot.Vector3[vertexCount];
			Godot.Vector3[] vertex_array = new Godot.Vector3[vertexCount];
			
			// Populate the arrays from the input mesh data:
			for (int i = 0; i < vertexCount; i++)
			{
				Numerics.Vector3 vertex = mesh.VertexList[i].Position;
				Numerics.Vector3 normal = mesh.VertexList[i].Normal;
				vertex_array[i] = new Godot.Vector3(vertex.X, vertex.Y, vertex.Z);
				normal_array[i] = new Godot.Vector3(normal.X, normal.Y, normal.Z);
			}
			
			// The index list doesn't need to be converted:
			int[] index_array = mesh.IndexList.ToArray();
			
			// Put the data arrays in a larger array for Godot to understand what the arrays represent:
			arrays[(int)Mesh.ArrayType.Vertex] = vertex_array;
			arrays[(int)Mesh.ArrayType.Normal] = normal_array;
			arrays[(int)Mesh.ArrayType.Index] = index_array;
			
			// Finally, upload the mesh to GPU:
			this.AddSurfaceFromArrays(Mesh.PrimitiveType.Triangles, arrays);
		}
Beispiel #11
0
        //Workaround to get initial focus
        public void GuiCollectFocusGroup()
        {
            _focusGroup.Clear();
            _focusGroup = GetTree().GetNodesInGroup("FocusGroup");

            //Save references to call main buttons in sections
            foreach (Button button in _focusGroup)
            {
                var groups = button.GetGroups();

                if (groups.Contains("MainMenu"))
                {
                    _buttonsSections["MainMenu"] = button;
                }

                if (groups.Contains("Pause"))
                {
                    _buttonsSections["Pause"] = button;
                }

                if (groups.Contains("OptionsMain"))
                {
                    _buttonsSections["OptionsMain"] = button;
                }

                if (groups.Contains("OptionsControls"))
                {
                    _buttonsSections["OptionsControls"] = button;
                }
            }
        }
        public static string CallNetworkEvent(object networkeventclass, string eventKey, object[] args)
        {
            var fields = new Godot.Collections.Dictionary();

            // if (((NetworkClass)obj.GetType().GetCustomAttribute(typeof(NetworkClass))).key)
            // fields.Add("ObjectType", ((NetworkClass)obj.GetType().GetCustomAttribute(typeof(NetworkClass))).key);
            fields.Add("EventType", networkeventclass.GetType().AssemblyQualifiedName);
            foreach (var field in networkeventclass.GetType().GetMethods())
            {
                if (Attribute.IsDefined(field, typeof(NetworkEventProperty)) &&
                    !((NetworkEventProperty)field.GetCustomAttribute(typeof(NetworkEventProperty))).key.Equals("EventType") &&
                    !((NetworkEventProperty)field.GetCustomAttribute(typeof(NetworkEventProperty))).key.Equals("args") &&
                    !((NetworkEventProperty)field.GetCustomAttribute(typeof(NetworkEventProperty))).key.Equals("event") &&
                    ((NetworkEventProperty)field.GetCustomAttribute(typeof(NetworkEventProperty))).key.Equals(eventKey))
                {
                    // fields.Add(((NetworkProperty)field.GetCustomAttribute(typeof(NetworkProperty))).key, field.GetValue(obj));
                    fields.Add("event", ((NetworkEventProperty)field.GetCustomAttribute(typeof(NetworkEventProperty))).key);
                    break;
                }
            }
            var eventargs = new Godot.Collections.Array();

            foreach (var arg in args)
            {
                eventargs.Add(arg);
            }
            fields.Add("args", eventargs);
            return(JSON.Print(fields));
        }
        public override void OnReady <T>(T node, MemberInfo memberInfo)
        {
            var connectNode = node.GetNode(NodePath);

            if (connectNode == null)
            {
                return;
            }
            if (!connectNode.HasSignal(SignalName))
            {
                GD.PushError($"'{connectNode.GetPath()}' does not have a signal '{SignalName}'");
                return;
            }
            GArray binds     = null;
            var    lastParam = ((MethodInfo)memberInfo).GetParameters().LastOrDefault();

            if (lastParam?.ParameterType == typeof(ulong) && lastParam.Name == "_triggerId")
            {
                binds = new GArray {
                    connectNode.GetInstanceId()
                }
            }
            ;
            connectNode.Connect(SignalName, node, memberInfo.Name, binds, (uint)Flags);
        }
    }
Beispiel #14
0
 /// <summary>
 /// Is called by the main process 60x per second, calls the LIDAR detector to collect data, and then resets the LIDAR's oritentation
 /// </summary>
 public override void _PhysicsProcess(float delta)
 {
     LIDAR_DRIVER();
     Godot.Collections.Array cams = GetTree().GetNodesInGroup("liCams");
     foreach (Camera Cam in cams)
     {
         Cam.Orthonormalize();
     }
 }
Beispiel #15
0
        /// <summary>
        /// Drives the LIDAR process, writes to file, closes file, handles interpolation logic and  LIDAR camera movement control
        /// </summary>
        public void LIDAR_DRIVER()
        {
            Godot.Collections.Array gridSpace = gridding();
            GetTree().CallGroup("liCams", "RotateObjectLocal", new Godot.Collections.Array {
                Vector3.Left, maxLR
            });
            GetTree().CallGroup("liCams", "RotateObjectLocal", new Godot.Collections.Array {
                Vector3.Up, _maxAng
            });
            string largerSide = (string)gridSpace[3];
            int    topside    = 0;
            int    sideSide   = 0;

            switch (largerSide)
            {
            case "lr":
                sideSide = (int)gridSpace[1];
                topside  = (int)gridSpace[2];
                break;

            case "ud":
                sideSide = (int)gridSpace[2];
                topside  = (int)gridSpace[1];
                break;

            default:
                break;
            }

            for (int i = 0; i < topside; i++)
            {
                if (i > 0)
                {
                    camResetTop();
                }
                for (int j = 0; j < sideSide; j++)
                {
                    var result = imaging();
                    if (!result.Equals(new Vector3(0, 0, 0)))
                    {
                        var   collisionLoc  = result;
                        float collisionDist = distancing(result);
                        pointCloud.Add(collisionLoc);
                        distCloud.Add(collisionDist);
                    }
                    camMovement((float)gridSpace[0], "down");
                }
                camMovement((float)gridSpace[0], "left");
            }

            if (_resolution < 1)
            {
                interp();
            }

            writeFile();
        }
Beispiel #16
0
 /// <summary>
 /// This gets all the defined tile graphics from the world tilemap and maps their names to their indices.
 /// </summary>
 private void CreateTileDictionary()
 {
     Godot.Collections.Array tileIDs = tileMap.TileSet.GetTilesIds();
     for (int i = 0; i < tileIDs.Count; i++)
     {
         int tileID = (int)tileIDs[i];
         tileIndexMap.Add(tileMap.TileSet.TileGetName(tileID), tileID);
     }
 }
 public static Godot.Collections.Array ArrayFrom(params object[] objects)
 {
     Godot.Collections.Array result = new Godot.Collections.Array();
     foreach (object obj in objects)
     {
         result.Add(obj);
     }
     return(result);
 }
Beispiel #18
0
 /// <summary>
 /// This gets all the defined object graphics from the installed object tilemap and maps their names to their indices.
 /// </summary>
 private void CreateFurnitureDictionary()
 {
     Godot.Collections.Array installedObjectIDs = furnitureMap.TileSet.GetTilesIds();
     for (int i = 0; i < installedObjectIDs.Count; i++)
     {
         int tileID = (int)installedObjectIDs[i];
         furnitureIndexMap.Add(furnitureMap.TileSet.TileGetName(tileID), tileID);
     }
 }
        public ArrayTraverse(System.Array array)
        {
            this.maxLengths = new int[array.Rank];
            for (int i = 0; i < array.Rank; ++i)
            {
                this.maxLengths[i] = array.GetLength(i) - 1;
            }

            this.Position = new int[array.Rank];
        }
Beispiel #20
0
        public ICollection <T> GetCollectionFromArray <T>(Array array)
        {
            List <T> data = new List <T>();

            foreach (var d in array)
            {
                data.Add(this.GetValueFromProperty <T>(d));
            }

            return(data);
        }
Beispiel #21
0
        private void _ConnectGUIElements()
        {
            var startingWorld = (PackedScene)ResourceLoader.Load(StartWorldPath);
            var newGameParams = new Godot.Collections.Array
            {
                this._main,
                startingWorld
            };

            this._newGameBtn.Connect("pressed", this._newGameBtn, nameof(NewGameBtn.OnPressed), newGameParams);
        }
Beispiel #22
0
        private void OnSkuDetailsQueryCompleted(Godot.Collections.Array arrSkuDetails)
        {
            ShowAlert(JSON.Print(arrSkuDetails));

            var skuDetails = GooglePlayBillingUtils.ConvertSkuDetailsDictionaryArray(arrSkuDetails);

            foreach (var skuDetail in skuDetails)
            {
                GD.Print($"Sku {skuDetail.Sku}");
            }
        }
 private void setWaveDirection(Godot.Collections.Array <float> new_wave_directions)
 {
     _wave_directions = new_wave_directions;
     if (waves.Count != wave_directions.Count)
     {
         GD.PrintErr("new wave directions size not equal to waves size");
     }
     else
     {
         update_waves();
     }
 }
Beispiel #24
0
        private static Button AddButton(string text, Control parent, DebugMenuAction action)
        {
            Button btn = new Button();

            btn.Text = text;
            btn.SizeFlagsHorizontal = (int)SizeFlags.Expand + (int)SizeFlags.Fill;
            Instance.ActionList.Add(action);
            Godot.Collections.Array parameters = new Godot.Collections.Array();
            parameters.Add(Instance.ActionList.Count - 1);
            btn.Connect("pressed", Instance, nameof(ButtonPressed), parameters);
            parent.AddChild(btn);
            return(btn);
        }
Beispiel #25
0
 public override void _Ready()
 {
     slots = new SkillButton[TOTAL_SPELLS];
     for (int k = 0; k < TOTAL_SPELLS; k++)
     {
         SkillButton             skill = GetNode <SkillButton>("Skill-" + (k + 1));
         Godot.Collections.Array bind  = Global.ArrayFrom(k);
         skill.Connect("pressed", this, nameof(on_SkillActivated), bind);
         skill.Connect("mouse_entered", this, nameof(on_SkillHovered), bind);
         skill.Connect("mouse_exited", this, nameof(on_SkillUnHovered), bind);
         slots[k] = skill;
     }
 }
Beispiel #26
0
        private void OnGooglePlayBilling_SkuDetailsQueryCompleted(Godot.Collections.Array arrSkuDetails)
        {
            var skuDetails = GooglePlayBillingUtils.ConvertSkuDetailsDictionaryArray(arrSkuDetails);

            foreach (var sku in skuDetails)
            {
                switch (sku.Sku)
                {
                // our fake potion
                case "android.test.purchased":
                    _buyPotionButton.Text = $"Buy {sku.Price}";
                    _buyPotionButton.Show();
                    break;
                }
            }
        }
Beispiel #27
0
 public GroundNode(MeshInstance meshInstance) : base()
 {
     this.meshInstance = meshInstance;
     Godot.Collections.Array children = meshInstance.GetChildren();
     foreach (var child in children)
     {
         if (child is CollisionObject collider)
         {
             collider.Connect("input_event", this, nameof(this.onInputEvent));
             collider.Connect("mouse_entered", this, nameof(this.onMouseEntered));
             collider.Connect("mouse_exited", this, nameof(this.onMouseExited));
             break;
         }
     }
     // meshInstance.MaterialOverride = new
 }
Beispiel #28
0
        public override void _PhysicsProcess(float delta)
        {
            _collidingBodies = GetCollidingBodies();
            if (_collidingBodies.Count != 0 || _currentBulletTimeLeft <= 0)
            {
                if (_collidingBodies.Count != 0)
                {
                    SpawnBulletExplosion();
                    NotifyCollider((Object)_collidingBodies[0]);
                }

                RemoveBulletFromTree();
            }

            _currentBulletTimeLeft -= delta;
        }
Beispiel #29
0
        private static string FindSelectedXcode()
        {
            var outputWrapper = new Godot.Collections.Array();

            int exitCode = Godot.OS.Execute("xcode-select", new string[] { "--print-path" }, blocking: true, output: outputWrapper);

            if (exitCode == 0)
            {
                string output = (string)outputWrapper[0];
                return(output.Trim());
            }

            Console.Error.WriteLine($"'xcode-select --print-path' exited with code: {exitCode}");

            return(null);
        }
Beispiel #30
0
        private void OnGooglePlayBilling_PurchasesUpdated(Godot.Collections.Array arrPurchases)
        {
            _panel.Show();
            _processLabel.Show();
            _thanksLabel.Hide();

            var purchases = GooglePlayBillingUtils.ConvertPurchaseDictionaryArray(arrPurchases);

            foreach (var purchase in purchases)
            {
                _purchases.Add(purchase.PurchaseToken, purchase.Sku);
                // We only expect this SKU
                if (purchase.Sku == "android.test.purchased")
                {
                    _googlePlayBilling.AcknowledgePurchase(purchase.PurchaseToken);
                }
            }
        }