Example #1
0
        private IEnumerator LoadCoroutine()
        {
            yield return(LoadAnimation());

            _isLoaded  = true;
            _isLoading = false;
            OnLoad();
            OnLoadEvent?.Invoke();
        }
Example #2
0
        public void Transfer(Warehouse location, Warehouse destination, int transferTime, IReadOnlyList <Cargo> cargos)
        {
            Location     = location;
            Destination  = destination;
            TransferTime = transferTime;
            Cargos       = cargos;

            if (cargos.Any())
            {
                var loadTask = new TransportTask("Load", LoadTime);
                if (0 < LoadTime)
                {
                    loadTask.OnStartedEvent += () => OnLoadEvent?.Invoke(new LoadEvent(this, location, LoadTime, cargos));
                }
                AddTask(loadTask);
            }

            var transferTask = new TransportTask("Transfer", transferTime);

            transferTask.OnStartedEvent   += () => OnDepartEvent?.Invoke(new DepartEvent(this, location, destination, cargos));
            transferTask.OnCompletedEvent += () =>
            {
                Location    = destination;
                Destination = null;
                OnArriveEvent?.Invoke(new ArriveEvent(this, destination, cargos));
            };
            AddTask(transferTask);

            if (cargos.Any())
            {
                var unloadTask = new TransportTask("Unload", UnloadTime);
                unloadTask.OnStartedEvent += () =>
                {
                    if (0 < UnloadTime)
                    {
                        OnUnloadEvent?.Invoke(new UnloadEvent(this, location, UnloadTime, cargos));
                    }
                };
                unloadTask.OnCompletedEvent += () =>
                {
                    destination.Cargos.AddRange(Cargos);
                    Cargos = new List <Cargo>();
                    Transfer(destination, location, transferTime, new List <Cargo>());
                };
                AddTask(unloadTask);
            }
        }
Example #3
0
 public void OnLoad(bool isLoaded)
 {
     OnLoadEvent?.Invoke(this, isLoaded);
 }
Example #4
0
        public void LoadDir(string dir, OnLoadEvent handler = null)
        {
            foreach (string imgPath in Directory.EnumerateFiles(dir))
            {
            #if false
                if (handler != null)
                {
                    handler("Loading " + imgPath);
                }
            #endif

                try
                {
                    using (Bitmap img = Bitmap.FromFile(imgPath) as Bitmap)
                    {
                        images.Insert(new ImageDatabase.Element(imgPath, AverageColor(img)));
                    }
                }
                catch (Exception e)
                {
                    if (handler != null)
                    {
                        handler("Error loading " + imgPath + ": " + e.ToString());
                    }
                }
            }
        }