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 void _ExportBeginImpl(string[] features, bool isDebug, string path, int flags) { // TODO Right now there is no way to stop the export process with an error if (File.Exists(GodotSharpDirs.ProjectSlnPath)) { string buildConfig = isDebug ? "Debug" : "Release"; string scriptsMetadataPath = Path.Combine(GodotSharpDirs.ResMetadataDir, $"scripts_metadata.{(isDebug ? "debug" : "release")}"); CSharpProject.GenerateScriptsMetadata(GodotSharpDirs.ProjectCsProjPath, scriptsMetadataPath); AddFile(scriptsMetadataPath, scriptsMetadataPath); // Turn export features into defines var godotDefines = features; if (!GodotSharpBuilds.BuildProjectBlocking(buildConfig, godotDefines)) { GD.PushError("Failed to build project"); return; } // Add dependency assemblies var dependencies = new Godot.Collections.Dictionary <string, string>(); var projectDllName = (string)ProjectSettings.GetSetting("application/config/name"); if (projectDllName.Empty()) { projectDllName = "UnnamedProject"; } string projectDllSrcDir = Path.Combine(GodotSharpDirs.ResTempAssembliesBaseDir, buildConfig); string projectDllSrcPath = Path.Combine(projectDllSrcDir, $"{projectDllName}.dll"); dependencies[projectDllName] = projectDllSrcPath; { string templatesDir = Internal.FullTemplatesDir; string androidBclDir = Path.Combine(templatesDir, "android-bcl"); string customLibDir = features.Contains("Android") && Directory.Exists(androidBclDir) ? androidBclDir : string.Empty; GetExportedAssemblyDependencies(projectDllName, projectDllSrcPath, buildConfig, customLibDir, dependencies); } string apiConfig = isDebug ? "Debug" : "Release"; string resAssembliesDir = Path.Combine(GodotSharpDirs.ResAssembliesBaseDir, apiConfig); foreach (var dependency in dependencies) { string dependSrcPath = dependency.Value; string dependDstPath = Path.Combine(resAssembliesDir, dependSrcPath.GetFile()); AddFile(dependSrcPath, dependDstPath); } } // Mono specific export template extras (data dir) ExportDataDirectory(features, isDebug, path); }
private void PerformHits() { Console.WriteLine($"Performing {_hits.Count} melee hits"); TouchData touch = new TouchData(); touch.damage = _damage; touch.teamId = _source.team; touch.touchType = TouchType.Melee; for (int i = 0; i < _hits.Count; ++i) { IActor a = _hits[i]; Vector3 origin = _source.ignoreBody.GlobalTransform.origin; Vector3 dest = a.GetTransformForTarget().origin; Godot.Collections.Dictionary hit = ZqfGodotUtils.CastRay(this, origin, dest, uint.MaxValue, _source.ignoreBody); if (hit.Keys.Count == 0) { continue; } touch.hitPos = (Vector3)hit["position"]; touch.hitNormal = (Vector3)hit["normal"]; Console.WriteLine($"Hitting actor {a.actorId}"); TouchResponseData response = Game.TouchGameObject(touch, hit["collider"]); //a.ActorTouch(touch); } _hits.Clear(); }
/// <summary> /// Sets all the class variables according to the config file /// </summary> /// <param name="JsonString"> /// JSON formatted string of the settings.cfg file /// </param> public void PopulateSettings(string JsonString) { // Parse the config file and quick sanity check to // make sure its a dictionary. var setting = JSON.Parse(JsonString).Result; if (!(setting is Godot.Collections.Dictionary)) { return; } // Go through the JSON file and add the necessary items Godot.Collections.Dictionary nsetting = (Godot.Collections.Dictionary)setting; foreach (System.Collections.Generic.KeyValuePair <object, object> entry in nsetting) { switch (entry.Key) { case "enabled_plugins": AddEnabledPluginsSetting(entry.Value); break; case "disabled_plugins": AddDisabledPluginsSetting(entry.Value); break; default: break; } } }
public override void UnSerializeModule(Godot.Collections.Dictionary data) { tex = (Texture)data["tex"]; normalMap = (Texture)data["normalMap"]; mesh = (Mesh)data["mesh"]; material = (Material)data["material"]; }
private static void LoadCatalog() { if (_loaded) { return; } var f = new File(); var err = f.Open("res://addons/fontawesome/assets/fontawesome-icons.json", File.ModeFlags.Read); if (err != Error.Ok) { GD.PrintErr("Error while loading fontawesome file: ", err); return; } var result = JSON.Parse(f.GetAsText()); if (result.Error != Error.Ok) { GD.PrintErr("Error while parsing fontawesome data: ", err); return; } _catalog = (Dictionary)result.Result; _loaded = true; }
private void AddI18NAssemblies(Godot.Collections.Dictionary <string, string> assemblies, string bclDir) { var codesets = (I18NCodesets)ProjectSettings.GetSetting("mono/export/i18n_codesets"); if (codesets == I18NCodesets.None) { return; } void AddI18NAssembly(string name) => assemblies.Add(name, Path.Combine(bclDir, $"{name}.dll")); AddI18NAssembly("I18N"); if ((codesets & I18NCodesets.CJK) != 0) { AddI18NAssembly("I18N.CJK"); } if ((codesets & I18NCodesets.MidEast) != 0) { AddI18NAssembly("I18N.MidEast"); } if ((codesets & I18NCodesets.Other) != 0) { AddI18NAssembly("I18N.Other"); } if ((codesets & I18NCodesets.Rare) != 0) { AddI18NAssembly("I18N.Rare"); } if ((codesets & I18NCodesets.West) != 0) { AddI18NAssembly("I18N.West"); } }
public virtual Godot.Collections.Dictionary GetDataArray() { var dict = new Godot.Collections.Dictionary(); dict.Add("id", networkId); return(dict); }
public ISaveable FromData(Godot.Collections.Dictionary data) { Type type = Type.GetType((string)data["type"]); ISaveable saveable = (ISaveable)Activator.CreateInstance(type); DecodeObject(saveable, data); return(saveable); }
public override Godot.Collections.Dictionary SerializeModule() { Godot.Collections.Dictionary data = new Godot.Collections.Dictionary(); data["rate"] = rate; return(data); }
public override Godot.Collections.Dictionary SerializeModule() { Godot.Collections.Dictionary data = new Godot.Collections.Dictionary(); data["gradient"] = gradient; return(data); }
public override Godot.Collections.Dictionary SerializeModule() { Godot.Collections.Dictionary data = new Godot.Collections.Dictionary(); data["curve"] = curve; data["sizeMultiplier"] = sizeMultiplier; return(data); }
public override Godot.Collections.Dictionary SerializeModule() { Godot.Collections.Dictionary data = new Godot.Collections.Dictionary(); data.Add("sizeScale", sizeScale); data.Add("bounciness", bounciness); data.Add("margin", margin); return(data); }
public Resource FromKey(int key) { if (!objects.ContainsKey(key)) { Godot.Collections.Dictionary data = encoded_resources[key]; Type type = Type.GetType((string)data["type"]); objects[key] = (Godot.Resource)CreateAndDeserialize(type, data); } return(objects[key]); }
private static void CreateTextures(string type, Godot.Collections.Dictionary<string, string> foods, ICollection<FoodItem> foodItemTexturess, string assetPath) { foreach(var food in foods) { var imageTexture = (Texture) GD.Load($"{assetPath}/{food.Value}"); imageTexture.Flags = (int) Texture.FlagsEnum.Mipmaps; foodItemTexturess.Add(new FoodItem(food.Key, type, imageTexture)); } }
public Resource FromKey(int key) { if (!objects.ContainsKey(key)) { Godot.Collections.Dictionary data = encoded_resources[key]; Type type = Type.GetType((string)data["type"]); objects[key] = (Resource)Activator.CreateInstance(type); DecodeObject(objects[key], data); } return(objects[key]); }
public override Godot.Collections.Dictionary SerializeModule() { Godot.Collections.Dictionary data = new Godot.Collections.Dictionary(); data["tex"] = tex; data["normalMap"] = normalMap; data["mesh"] = mesh; data["material"] = material; return(data); }
private Godot.Collections.Dictionary EncodeObject(object obj) { Type type = obj.GetType(); var data = new Godot.Collections.Dictionary(); data["type"] = type.FullName; foreach (FieldInfo field in type.GetSaveableFields()) { data[field.Name] = Encode(field.GetValue(obj)); } return(data); }
public override void UnSerializeModule(Godot.Collections.Dictionary data) { Curve newCurve = (Curve)data["curve"]; curve = new Curve(); for (int i = 0; i < newCurve.GetPointCount(); i++) { curve.AddPoint( newCurve.GetPointPosition(i), newCurve.GetPointLeftTangent(i), newCurve.GetPointRightTangent(i), newCurve.GetPointLeftMode(i), newCurve.GetPointRightMode(i) ); } sizeMultiplier = (float)data["sizeMultiplier"]; }
public void WriteModulesData() { if (Engine.EditorHint || forceModulesSerializationInGame) { modulesData.Clear(); foreach (ParticleSystem2DModule module in modules) { Godot.Collections.Dictionary serializedDictionary = module.SerializeModule(); if (serializedDictionary != null) { serializedDictionary.Add("Type", module.GetType().ToString()); modulesData.Add(serializedDictionary); } } } }
public static string Deconstruct(object obj) { 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("ObjectType", obj.GetType().AssemblyQualifiedName); foreach (var field in obj.GetType().GetFields()) { if (Attribute.IsDefined(field, typeof(NetworkProperty)) && !((NetworkProperty)field.GetCustomAttribute(typeof(NetworkProperty))).key.Equals("ObjectType")) { // fields.Add(((NetworkProperty)field.GetCustomAttribute(typeof(NetworkProperty))).key, field.GetValue(obj)); fields.Add(field.Name, field.GetValue(obj)); } } return(JSON.Print(fields)); }
public Godot.Collections.Dictionary GetDictionary() { var o = new Godot.Collections.Dictionary(); o.Add("hz", hz); o.Add("base_hz", base_hz); o.Add("tuned_hz", tuned_hz); o.Add("fixedFreq", fixedFreq); o.Add("mult", mult); o.Add("coarse", coarse); o.Add("fine", fine); o.Add("detune", Detune); //NOT the raw value, but the value PhaseEngine UI expects to map the raw value from -1 to 1. o.Add("detune_randomness", detune_randomness); o.Add("increment_offset", increment_offset); return(o); }
private object CreateAndDeserialize(Type type, Godot.Collections.Dictionary data) { object obj = Activator.CreateInstance(type); foreach (FieldInfo field in type.GetSaveableFields()) { var value = Deserialize(field.FieldType, data[field.Name]); if (value == null) { continue; } try { field.SetValue(obj, value); } catch (Exception e) { GD.PrintErr($"{type}.{field.Name} = {value} failed"); throw e; } } return(obj); }
public override void UnSerializeModule(Godot.Collections.Dictionary data) { lifetimeMode = (RandomNumberEditor.Mode)data["lifetimeMode"]; minLifetime = (float)data["minLifetime"]; maxLifetime = (float)data["maxLifetime"]; speedMode = (RandomNumberEditor.Mode)data["speedMode"]; minSpeed = (float)data["minSpeed"]; maxSpeed = (float)data["maxSpeed"]; sizeMode = (RandomNumberEditor.Mode)data["sizeMode"]; minSize = (float)data["minSize"]; maxSize = (float)data["maxSize"]; rotationMode = (RandomNumberEditor.Mode)data["rotationMode"]; minRotation = (float)data["minRotation"]; maxRotation = (float)data["maxRotation"]; startColor = (Color)data["startColor"]; }
private void AddI18NAssemblies(Godot.Collections.Dictionary <string, string> assemblies, string platform) { var codesets = (I18NCodesets)ProjectSettings.GetSetting("mono/export/i18n_codesets"); if (codesets == I18NCodesets.None) { return; } string bclDir = DeterminePlatformBclDir(platform) ?? typeof(object).Assembly.Location.GetBaseDir(); void AddI18NAssembly(string name) => assemblies.Add(name, Path.Combine(bclDir, $"{name}.dll")); AddI18NAssembly("I18N"); if ((codesets & I18NCodesets.CJK) != 0) { AddI18NAssembly("I18N.CJK"); } if ((codesets & I18NCodesets.MidEast) != 0) { AddI18NAssembly("I18N.MidEast"); } if ((codesets & I18NCodesets.Other) != 0) { AddI18NAssembly("I18N.Other"); } if ((codesets & I18NCodesets.Rare) != 0) { AddI18NAssembly("I18N.Rare"); } if ((codesets & I18NCodesets.West) != 0) { AddI18NAssembly("I18N.West"); } }
public override Godot.Collections.Dictionary SerializeModule() { Godot.Collections.Dictionary data = new Godot.Collections.Dictionary(); data["lifetimeMode"] = (int)lifetimeMode; data["minLifetime"] = minLifetime; data["maxLifetime"] = maxLifetime; data["speedMode"] = (int)speedMode; data["minSpeed"] = minSpeed; data["maxSpeed"] = maxSpeed; data["sizeMode"] = (int)sizeMode; data["minSize"] = minSize; data["maxSize"] = maxSize; data["rotationMode"] = (int)rotationMode; data["minRotation"] = minRotation; data["maxRotation"] = maxRotation; data["startColor"] = startColor; return(data); }
/// <summary> /// Convert a Godot dictionary into a standard dictionary. /// </summary> public static Dictionary <TKey, TValue> ToDict <TKey, TValue>(this Godot.Collections.Dictionary <TKey, TValue> dict) { return(new Dictionary <TKey, TValue>(dict)); }
private void _ExportBeginImpl(string[] features, bool isDebug, string path, int flags) { if (!File.Exists(GodotSharpDirs.ProjectSlnPath)) { return; } string platform = DeterminePlatformFromFeatures(features); if (platform == null) { throw new NotSupportedException("Target platform not supported"); } string outputDir = new FileInfo(path).Directory?.FullName ?? throw new FileNotFoundException("Base directory not found"); string buildConfig = isDebug ? "ExportDebug" : "ExportRelease"; string scriptsMetadataPath = Path.Combine(GodotSharpDirs.ResMetadataDir, $"scripts_metadata.{(isDebug ? "debug" : "release")}"); CsProjOperations.GenerateScriptsMetadata(GodotSharpDirs.ProjectCsProjPath, scriptsMetadataPath); AddFile(scriptsMetadataPath, scriptsMetadataPath); // Turn export features into defines var godotDefines = features; if (!BuildManager.BuildProjectBlocking(buildConfig, godotDefines)) { throw new Exception("Failed to build project"); } // Add dependency assemblies var dependencies = new Godot.Collections.Dictionary <string, string>(); var projectDllName = (string)ProjectSettings.GetSetting("application/config/name"); if (projectDllName.Empty()) { projectDllName = "UnnamedProject"; } string projectDllSrcDir = Path.Combine(GodotSharpDirs.ResTempAssembliesBaseDir, buildConfig); string projectDllSrcPath = Path.Combine(projectDllSrcDir, $"{projectDllName}.dll"); dependencies[projectDllName] = projectDllSrcPath; if (platform == OS.Platforms.Android) { string godotAndroidExtProfileDir = GetBclProfileDir("godot_android_ext"); string monoAndroidAssemblyPath = Path.Combine(godotAndroidExtProfileDir, "Mono.Android.dll"); if (!File.Exists(monoAndroidAssemblyPath)) { throw new FileNotFoundException("Assembly not found: 'Mono.Android'", monoAndroidAssemblyPath); } dependencies["Mono.Android"] = monoAndroidAssemblyPath; } var initialDependencies = dependencies.Duplicate(); internal_GetExportedAssemblyDependencies(initialDependencies, buildConfig, DeterminePlatformBclDir(platform), dependencies); AddI18NAssemblies(dependencies, platform); string outputDataDir = null; if (PlatformHasTemplateDir(platform)) { outputDataDir = ExportDataDirectory(features, platform, isDebug, outputDir); } string apiConfig = isDebug ? "Debug" : "Release"; string resAssembliesDir = Path.Combine(GodotSharpDirs.ResAssembliesBaseDir, apiConfig); bool assembliesInsidePck = (bool)ProjectSettings.GetSetting("mono/export/export_assemblies_inside_pck") || outputDataDir == null; if (!assembliesInsidePck) { string outputDataGameAssembliesDir = Path.Combine(outputDataDir, "Assemblies"); if (!Directory.Exists(outputDataGameAssembliesDir)) { Directory.CreateDirectory(outputDataGameAssembliesDir); } } foreach (var dependency in dependencies) { string dependSrcPath = dependency.Value; if (assembliesInsidePck) { string dependDstPath = Path.Combine(resAssembliesDir, dependSrcPath.GetFile()); AddFile(dependSrcPath, dependDstPath); } else { string dependDstPath = Path.Combine(outputDataDir, "Assemblies", dependSrcPath.GetFile()); File.Copy(dependSrcPath, dependDstPath); } } // AOT if ((bool)ProjectSettings.GetSetting("mono/export/aot/enabled")) { AotCompileDependencies(features, platform, isDebug, outputDir, outputDataDir, dependencies); } }
private static extern void internal_GetExportedAssemblyDependencies(Godot.Collections.Dictionary <string, string> initialAssemblies, string buildConfig, string customBclDir, Godot.Collections.Dictionary <string, string> dependencyAssemblies);
private void _ExportBeginImpl(string[] features, bool isDebug, string path, int flags) { if (!File.Exists(GodotSharpDirs.ProjectSlnPath)) { return; } string platform = DeterminePlatformFromFeatures(features); if (platform == null) { throw new NotSupportedException("Target platform not supported"); } string outputDir = new FileInfo(path).Directory?.FullName ?? throw new FileNotFoundException("Base directory not found"); string buildConfig = isDebug ? "ExportDebug" : "ExportRelease"; string scriptsMetadataPath = Path.Combine(GodotSharpDirs.ResMetadataDir, $"scripts_metadata.{(isDebug ? "debug" : "release")}"); CsProjOperations.GenerateScriptsMetadata(GodotSharpDirs.ProjectCsProjPath, scriptsMetadataPath); AddFile(scriptsMetadataPath, scriptsMetadataPath); // Turn export features into defines var godotDefines = features; if (!BuildManager.BuildProjectBlocking(buildConfig, godotDefines)) { throw new Exception("Failed to build project"); } // Add dependency assemblies var assemblies = new Godot.Collections.Dictionary <string, string>(); string projectDllName = GodotSharpEditor.ProjectAssemblyName; string projectDllSrcDir = Path.Combine(GodotSharpDirs.ResTempAssembliesBaseDir, buildConfig); string projectDllSrcPath = Path.Combine(projectDllSrcDir, $"{projectDllName}.dll"); assemblies[projectDllName] = projectDllSrcPath; if (platform == OS.Platforms.Android) { string godotAndroidExtProfileDir = GetBclProfileDir("godot_android_ext"); string monoAndroidAssemblyPath = Path.Combine(godotAndroidExtProfileDir, "Mono.Android.dll"); if (!File.Exists(monoAndroidAssemblyPath)) { throw new FileNotFoundException("Assembly not found: 'Mono.Android'", monoAndroidAssemblyPath); } assemblies["Mono.Android"] = monoAndroidAssemblyPath; } string bclDir = DeterminePlatformBclDir(platform); var initialAssemblies = assemblies.Duplicate(); internal_GetExportedAssemblyDependencies(initialAssemblies, buildConfig, bclDir, assemblies); AddI18NAssemblies(assemblies, bclDir); string outputDataDir = null; if (PlatformHasTemplateDir(platform)) { outputDataDir = ExportDataDirectory(features, platform, isDebug, outputDir); } string apiConfig = isDebug ? "Debug" : "Release"; string resAssembliesDir = Path.Combine(GodotSharpDirs.ResAssembliesBaseDir, apiConfig); bool assembliesInsidePck = (bool)ProjectSettings.GetSetting("mono/export/export_assemblies_inside_pck") || outputDataDir == null; if (!assembliesInsidePck) { string outputDataGameAssembliesDir = Path.Combine(outputDataDir, "Assemblies"); if (!Directory.Exists(outputDataGameAssembliesDir)) { Directory.CreateDirectory(outputDataGameAssembliesDir); } } foreach (var assembly in assemblies) { void AddToAssembliesDir(string fileSrcPath) { if (assembliesInsidePck) { string fileDstPath = Path.Combine(resAssembliesDir, fileSrcPath.GetFile()); AddFile(fileSrcPath, fileDstPath); } else { Debug.Assert(outputDataDir != null); string fileDstPath = Path.Combine(outputDataDir, "Assemblies", fileSrcPath.GetFile()); File.Copy(fileSrcPath, fileDstPath); } } string assemblySrcPath = assembly.Value; string assemblyPathWithoutExtension = Path.ChangeExtension(assemblySrcPath, null); string pdbSrcPath = assemblyPathWithoutExtension + ".pdb"; AddToAssembliesDir(assemblySrcPath); if (File.Exists(pdbSrcPath)) { AddToAssembliesDir(pdbSrcPath); } } // AOT compilation bool aotEnabled = platform == OS.Platforms.iOS || (bool)ProjectSettings.GetSetting("mono/export/aot/enabled"); if (aotEnabled) { string aotToolchainPath = null; if (platform == OS.Platforms.Android) { aotToolchainPath = (string)ProjectSettings.GetSetting("mono/export/aot/android_toolchain_path"); } if (aotToolchainPath == string.Empty) { aotToolchainPath = null; // Don't risk it being used as current working dir } // TODO: LLVM settings are hard-coded and disabled for now var aotOpts = new AotOptions { EnableLLVM = false, LLVMOnly = false, LLVMPath = "", LLVMOutputPath = "", FullAot = platform == OS.Platforms.iOS || (bool)(ProjectSettings.GetSetting("mono/export/aot/full_aot") ?? false), UseInterpreter = (bool)ProjectSettings.GetSetting("mono/export/aot/use_interpreter"), ExtraAotOptions = (string[])ProjectSettings.GetSetting("mono/export/aot/extra_aot_options") ?? new string[] { }, ExtraOptimizerOptions = (string[])ProjectSettings.GetSetting("mono/export/aot/extra_optimizer_options") ?? new string[] { }, ToolchainPath = aotToolchainPath }; AotBuilder.CompileAssemblies(this, aotOpts, features, platform, isDebug, bclDir, outputDir, outputDataDir, assemblies); } }