예제 #1
0
        public bool IsConnected(IPluggable connection)
        {
            Grid grid;

            IsPluggedIn(connection, out grid);
            return(grid != null && grid.HasAnyProducer());
        }
예제 #2
0
        /// <summary>
        /// Plugs the IPluggable into this grid.
        /// </summary>
        /// <returns><c>true</c>, if in was plugged, <c>false</c> otherwise.</returns>
        /// <param name="connection">IPluggable to be plugged in.</param>
        public bool PlugIn(IPluggable connection)
        {
            if (connection == null)
            {
                throw new ArgumentNullException("connection");
            }

            if (!CanPlugIn(connection))
            {
                UnityDebugger.Debugger.LogWarning("Grid", "Can't Plugin");
                return(false);
            }

            if (UtilityType == string.Empty)
            {
                UtilityType = connection.UtilityType;
            }

            if (SubType == string.Empty)
            {
                SubType = connection.SubType;
            }
            else if (connection.SubType == string.Empty)
            {
                connection.SubType = SubType;
            }

            connections.Add(connection);
            return(true);
        }
예제 #3
0
        public bool HasPower(IPluggable connection)
        {
            Grid grid;

            IsPluggedIn(connection, out grid);
            return(grid != null && grid.IsOperating);
        }
예제 #4
0
        public UUebViewCore(IUUebView uuebView, IPluggable plugin = null, ResourceLoader.MyHttpRequestHeaderDelegate requestHeader = null, ResourceLoader.MyHttpResponseHandlingDelegate httpResponseHandlingDelegate = null, Action <List <ParseError> > onParseFailed = null)
        {
            if (plugin == null)
            {
                plugin = new DefaultBehaviour();
            }

            this.view = uuebView;

            resLoader = new ResourceLoader(this.LoadParallel, requestHeader, httpResponseHandlingDelegate);
            this.view.AddChild(resLoader.cacheBox.transform);

            layoutMachine      = new LayoutMachine(resLoader, plugin);
            materializeMachine = new MaterializeMachine(resLoader, plugin);

            if (onParseFailed != null)
            {
                this.onParseFailed = onParseFailed;
            }
            else
            {
                this.onParseFailed = errors =>
                {
                    Debug.LogError("parse errors:" + errors.Count);
                    foreach (var error in errors)
                    {
                        Debug.LogError("code:" + error.code + " reason:" + error.reason);
                    }
                };
            }
        }
예제 #5
0
        public static GameObject GenerateSingleViewFromHTML(
            GameObject eventReceiverScrollViewGameObj,
            string source,
            Vector2 viewRect,
            ResourceLoader.MyHttpRequestHeaderDelegate requestHeader = null,
            ResourceLoader.MyHttpResponseHandlingDelegate httpResponseHandlingDelegate = null,
            string viewName = ConstSettings.ROOTVIEW_NAME,
            Action <List <ParseError> > onParseFailed = null,
            IPluggable plugin = null
            )
        {
            var viewObj = new GameObject("UUebView");

            viewObj.AddComponent <RectTransform>();
            viewObj.name = viewName;

            // viewObjにUUebViewComponentを追加し、UUebViewComponentにコアを追加する。
            // viewObjのUUebViewComponentはuuebViewCoreインスタンスを持っているので、そのコアに外部からさらにイベントを追加することができる。
            var uuebView     = viewObj.AddComponent <UUebViewComponent>();
            var uuebViewCore = new UUebViewCore(uuebView, plugin, requestHeader, httpResponseHandlingDelegate, onParseFailed);

            uuebView.SetCore(uuebViewCore);
            uuebViewCore.LoadHtml(source, viewRect, 0f, eventReceiverScrollViewGameObj);

            return(viewObj);
        }
예제 #6
0
        public void Run()
        {
            CSharpCodeProvider cs = new CSharpCodeProvider(new Dictionary <string, string> {
                { "CompilerVersion", "v3.5" }
            });

            if (this.tRun != null)
            {
                this.tRun.Abort();
            }
            CompilerParameters cp = new CompilerParameters();

            // Generate an executable instead of
            // a class library.
            cp.GenerateInMemory = true;
            // Specify the assembly file name to generate.
            //cp.OutputAssembly = "Scripting.dll";
            cp.CompilerOptions         = "/t:library";
            cp.IncludeDebugInformation = false;
            // Set whether to treat all warnings as errors.
            cp.TreatWarningsAsErrors = false;
            cp.ReferencedAssemblies.Add("mscorlib.dll");
            cp.ReferencedAssemblies.Add("System.Drawing.dll");
            cp.ReferencedAssemblies.Add("System.dll");
            cp.ReferencedAssemblies.Add("DrawEngine.Renderer.dll");
            cp.ReferencedAssemblies.Add("DrawEngine.Renderer.Animator.dll");
            cp.ReferencedAssemblies.Add("DrawEngine.PluginEngine.dll");
            cp.ReferencedAssemblies.Add("WeifenLuo.WinFormsUI.Docking.dll");
            cp.ReferencedAssemblies.Add("System.Windows.Forms.dll");
            cp.ReferencedAssemblies.Add("SharpTracing.exe");
            // Invoke compilation of the source file.
            CompilerResults cr = cs.CompileAssemblyFromSource(cp, this.syntaxBoxControl1.Document.Text);

            if (cr.Errors.Count > 0)
            {
                StringBuilder sb = new StringBuilder();
                foreach (CompilerError ce in cr.Errors)
                {
                    sb.AppendFormat("Linha: {0}, Coluna: {1} - {2}" + Environment.NewLine, ce.Line, ce.Column,
                                    ce.ErrorText);
                }
                MessageBox.Show(sb.ToString());
            }
            else
            {
                //Assembly loadeInDomain = domain.Load(File.ReadAllBytes("Scripting.dll"));
                //IPluggable pluggable = loadeInDomain.CreateInstance("ScriptingTemplate") as IPluggable;
                //this.TabText = pluggable.Name;
                //tRun = new Thread(new ThreadStart(pluggable.Run));
                //tRun.Start();
                Type[]     types     = cr.CompiledAssembly.GetExportedTypes();
                var        result    = types.First(t => ((Type)t).GetInterface("IPluggable") != null);
                IPluggable pluggable = cr.CompiledAssembly.CreateInstance(result.FullName) as IPluggable;
                this.TabText = pluggable.Name;
                this.tRun    = new Thread(pluggable.Run);
                this.tRun.Start();
            }
        }
예제 #7
0
        /// <summary>
        /// Determines whether the connection is plugged into this Grid.
        /// </summary>
        /// <returns><c>true</c> if the connection is plugged into this Grid; otherwise, <c>false</c>.</returns>
        public bool IsPluggedIn(IPluggable connection)
        {
            if (connection == null)
            {
                throw new ArgumentNullException("connection");
            }

            return(connections.Contains(connection));
        }
예제 #8
0
        private float GetOutputRate(IPluggable connection, float outputRate = 0.0f)
        {
            if (outputRate.IsZero())
            {
                outputRate = connection.OutputRate;
            }

            return(connection.StoredAmount - outputRate < 0.0f ? connection.StoredAmount : outputRate);
        }
예제 #9
0
        public bool CanPlugIn(IPluggable connection)
        {
            if (connection == null)
            {
                throw new ArgumentNullException("connection");
            }

            return(powerGrids.Any(grid => grid.CanPlugIn(connection)));
        }
예제 #10
0
        /// <summary>
        /// Unplug the specified IPluggable from this Grid.
        /// </summary>
        /// <param name="connection">IPluggable to be unplugged.</param>
        public void Unplug(IPluggable connection)
        {
            if (connection == null)
            {
                throw new ArgumentNullException("connection");
            }

            connections.Remove(connection);
        }
예제 #11
0
 public void MouseDown()
 {
     if (Select() != null)
     {
         _pluggable = new SingleMode();
     }
     else
     {
         _pluggable = new MultiShapeSelectionMode();
     }
 }
예제 #12
0
        public static void LoadPlugins()
        {
            GameEngine.SayToServer(" - Scanning for plugins...");
            foreach (string dll in Directory.GetFiles(".", "*.dll"))
            {
                // Prevent snagging on self when running as deployed executable
                if (dll.Contains(System.Reflection.Assembly.GetExecutingAssembly().GetName().Name))
                {
                    continue;
                }

                Assembly asm = Assembly.LoadFrom(dll);
                foreach (Type type in asm.GetTypes())
                {
                    if (type.GetInterface("IPluggable") == typeof(IPluggable))
                    {
                        IPluggable thisPlugin = Activator.CreateInstance(type) as IPluggable;
                        GameEngine.SayToServer($"{thisPlugin.Name}...");
                        AllPlugins.Add(thisPlugin);
                        if (type.GetInterface("IMappable") == typeof(IMappable))
                        {
                            IMappable mapPlugin = Activator.CreateInstance(type) as IMappable;
                            Mappers.Add(mapPlugin);
                        }
                        if (type.GetInterface("ISpawnable") == typeof(ISpawnable))
                        {
                            ISpawnable spawnPlugin = Activator.CreateInstance(type) as ISpawnable;
                            Spawners.Add(spawnPlugin);
                        }
                        if (type.GetInterface("IPlayerModifiable") == typeof(IPlayerModifiable))
                        {
                            IPlayerModifiable playerPlugin = Activator.CreateInstance(type) as IPlayerModifiable;
                            PlayerMods.Add(playerPlugin);
                        }
                        if (type.GetInterface("ICanOverrideAttackMethod") == typeof(ICanOverrideAttackMethod))
                        {
                            ICanOverrideAttackMethod combatPlugin = Activator.CreateInstance(type) as ICanOverrideAttackMethod;
                            AttackMod = combatPlugin;
                        }
                        if (type.GetInterface("ISpeakable") == typeof(ISpeakable))
                        {
                            ISpeakable speechMod = Activator.CreateInstance(type) as ISpeakable;
                            SpeechMods.Add(speechMod);
                        }
                        if (type.GetInterface("IFabricable") == typeof(IFabricable))
                        {
                            IFabricable templateMod = Activator.CreateInstance(type) as IFabricable;
                            TemplateMods.Add(templateMod);
                        }
                    }
                }
            }
            GameEngine.SayToServer("done.\n");
        }
예제 #13
0
 private void SeekConnection()
 {
     // try to reconnect furniture if present and compatible
     if (Tile != null && Tile.Furniture != null)
     {
         IPluggable pluggableComponent = Tile.Furniture.GetPluggable(typeTags);
         if (pluggableComponent != null)
         {
             // plug in
             pluggableComponent.Reconnect();
         }
     }
 }
예제 #14
0
        public float GetEfficiency(IPluggable connection)
        {
            float efficiency = 0f;
            Grid  grid;

            IsPluggedIn(connection, out grid);
            if (grid != null)
            {
                efficiency = grid.Efficiency;
            }

            return(efficiency);
        }
예제 #15
0
        public bool PlugIn(IPluggable connection, Grid grid)
        {
            if (connection == null)
            {
                throw new ArgumentNullException("connection");
            }

            if (!powerGrids.Contains(grid))
            {
                powerGrids.Add(grid);
            }

            return(grid != null && grid.PlugIn(connection));
        }
예제 #16
0
        public void Unplug(IPluggable connection, Grid grid)
        {
            if (connection == null)
            {
                throw new ArgumentNullException("connection");
            }

            if (grid == null)
            {
                throw new ArgumentNullException("grid");
            }

            grid.Unplug(connection);
        }
예제 #17
0
    public IPluggable GetPluggable(HashSet <string> utilityTags)
    {
        if (components != null)
        {
            foreach (BuildableComponent component in components)
            {
                IPluggable pluggable = component as IPluggable;
                if (pluggable != null && utilityTags.Contains(pluggable.UtilityType))
                {
                    return(pluggable);
                }
            }
        }

        return(null);
    }
예제 #18
0
        public bool IsPluggedIn(IPluggable connection, out Grid grid)
        {
            if (connection == null)
            {
                throw new ArgumentNullException("connection");
            }

            if (IsEmpty)
            {
                grid = null;
                return(false);
            }

            grid = powerGrids.FirstOrDefault(powerGrid => powerGrid.IsPluggedIn(connection));
            return(grid != null);
        }
예제 #19
0
        public bool PlugIn(IPluggable connection)
        {
            if (connection == null)
            {
                throw new ArgumentNullException("connection");
            }

            if (IsEmpty)
            {
                powerGrids.Add(new Grid());
            }

            Grid powerGrid = powerGrids.First(grid => grid.CanPlugIn(connection));

            return(PlugIn(connection, powerGrid));
        }
예제 #20
0
        public bool IsPluggedIn(IPluggable connection, out UtilityGrid grid)
        {
            if (connection == null)
            {
                throw new ArgumentNullException("connection");
            }

            if (IsEmpty)
            {
                grid = null;
                return(false);
            }

            grid = fluidGrids.First(fluidGrid => fluidGrid.IsPluggedIn(connection));
            return(grid != null);
        }
예제 #21
0
        public void Unplug(IPluggable connection)
        {
            if (connection == null)
            {
                throw new ArgumentNullException("connection");
            }

            Grid grid;

            IsPluggedIn(connection, out grid);
            if (grid == null)
            {
                return;
            }

            Unplug(connection, grid);
        }
예제 #22
0
        public bool PlugIn(IPluggable connection)
        {
            if (connection == null)
            {
                throw new ArgumentNullException("connection");
            }

            if (IsEmpty || !fluidGrids.Any(grid => grid.CanPlugIn(connection)))
            {
                fluidGrids.Add(new Grid());
                UnityDebugger.Debugger.LogWarning("FluidNetwork", "Adding new Fluid Grid");
            }

            // TODO: Currently, this will create a "Universal" Fluid system... that is not ideal.
            // In theory at this point there should either be a grid that can be plugged in, or there should be new grid added... that can be plugged in.
            Grid fluidGrid = fluidGrids.FirstOrDefault(grid => grid.CanPlugIn(connection));

            return(PlugIn(connection, fluidGrid));
        }
예제 #23
0
        /// <summary>
        /// Determines whether the connection can plug into this grid.
        /// </summary>
        /// <returns><c>true</c> if the connection can plug into this grid; otherwise, <c>false</c>.</returns>
        public bool CanPlugIn(IPluggable connection)
        {
            if (connection == null)
            {
                throw new ArgumentNullException("connection");
            }

            if (UtilityType != string.Empty && UtilityType != connection.UtilityType)
            {
                UnityDebugger.Debugger.LogWarning("Grid", "UtilityType isn't null and doesn't match, no plugin");
                return(false);
            }

            if (SubType != string.Empty && connection.SubType != string.Empty && SubType != connection.SubType)
            {
                UnityDebugger.Debugger.LogWarning("Grid", "Neither SubType is empty, and they don't match, no plugin");
                return(false);
            }

            return(true);
        }
예제 #24
0
        public static GameObject GenerateSingleViewFromUrl(
            GameObject eventReceiverGameObj,
            string url,
            Vector2 viewRect,
            ResourceLoader.MyHttpRequestHeaderDelegate requestHeader = null,
            ResourceLoader.MyHttpResponseHandlingDelegate httpResponseHandlingDelegate = null,
            string viewName = ConstSettings.ROOTVIEW_NAME,
            Action <List <ParseError> > onParseFailed = null,
            IPluggable plugin = null
            )
        {
            var viewObj = new GameObject("UUebView");

            viewObj.AddComponent <RectTransform>();
            viewObj.name = viewName;

            var uuebView     = viewObj.AddComponent <UUebViewComponent>();
            var uuebViewCore = new UUebViewCore(uuebView, plugin, requestHeader, httpResponseHandlingDelegate, onParseFailed);

            uuebView.SetCore(uuebViewCore);
            uuebViewCore.DownloadHtml(url, viewRect, eventReceiverGameObj);

            return(viewObj);
        }
 public void ATimer(IPluggable pluggable)
 {
     Console.WriteLine(pluggable.Grounded);
     Console.WriteLine(pluggable.Voltage);
     return;
 }
예제 #26
0
 public MaterializeMachine(ResourceLoader resLoader, IPluggable pluggable)
 {
     this.resLoader = resLoader;
     this.pluggable = pluggable;
 }