예제 #1
0
        public ShaderCommand(TreeDict dict)
        {
            ReferenceName = Trees.At(dict, "_ref");
            if (ReferenceName == null)
            {
                ReferenceName = "Error";
            }

            ID = Trees.At(dict, "_id");
            if (ID == null)
            {
                ID = ReferenceName;
            }

            dynamic tmp = Trees.At(dict, "_clearAfterDone");

            if (tmp != null && tmp.GetType() == typeof(bool))
            {
                ClearAfterLastPropIsDone = tmp;
            }

            //Logger.log.Debug("ShaderCommand: _id: " + ID + " _ref:" + Reference);

            object        ret = Trees.At(dict, "_props");
            List <object> props;

            if (ret != null)
            {
                props = ret as List <object>;
            }
            else
            {
                props = new List <object>();
            }

            Properties = new ShaderPropertiesCommand(props, this);

            ShaderProperty longest = null;

            Properties.getProps().ForEach(sp => {
                if (sp.Duration > (longest?.Duration ?? 0))
                {
                    longest = sp;
                }
            });
            if (longest != null)
            {
                longest.IsLast = true;
            }
        }
예제 #2
0
        public ShaderPropertiesCommand(List <object> list, ShaderCommand parent)
        {
            _propList = new List <ShaderProperty>();

            foreach (TreeDict d in list)
            {
                string property = "" + Trees.At(d, "_prop");

                float duration;

                dynamic value = Trees.At(d, "_value");

                dynamic tmp = Trees.At(d, "_duration");

                try
                {
                    duration = (float)tmp;
                }
                catch (Exception)
                {
                    duration = -1;
                }


                Functions easing = Functions.easeLinear;

                string easingString = Trees.At(d, "_easing");
                if (easingString != null)
                {
                    easing = (Functions)Enum.Parse(typeof(Functions), easingString);
                }

                //Logger.log.Debug("ShaderPropertiesCommand: p:" + property + " d: " + duration + " e: " + easing + " v:" + value);

                _propList.Add(new ShaderProperty(property, duration, value, easing, parent));
            }
        }
        private void ShaderEventCallback(CustomEventData customEventData)
        {
            if (customEventData.data == null)
            {
                return;
            }
            try
            {
                TreeDict eventData;
                switch (customEventData.type)
                {
                case EventTypeShader:
                    //Logger.log?.Debug("Shader event received!");

                    eventData = new Dictionary <string, object>(customEventData.data as TreeDict);

                    object        res = Trees.At(eventData, "_shaders");
                    List <object> shaders;
                    if (res != null)
                    {
                        shaders = res as List <object>;
                    }
                    else
                    {
                        shaders = new List <object>();
                    }

                    List <ShaderCommand> scList = new List <ShaderCommand>();

                    foreach (TreeDict shader in shaders)
                    {
                        scList.Add(new ShaderCommand(shader));
                    }

                    foreach (ShaderCommand sc in scList)
                    {
                        ShaderEffectData sfx = _shaderManager.GetShaderEffectByReferenceName(sc.ReferenceName);

                        if (sfx != null)
                        {
                            sc.ShaderEffectData = sfx;

                            Material mat = _shaderManager.GetMaterial(sc.ID, sfx);

                            if (mat == null)
                            {
                                mat = _shaderManager.AddMaterial(sc.ID, sfx);
                            }

                            sc.Material = mat;

                            StartEventCoroutine(sc, customEventData.time);
                        }
                        else
                        {
                            Logger.log.Error($"Unknown Shader reference used: '{sc.ReferenceName}'!");
                        }
                    }
                    break;

                case EventTypeShaderClear:
                    string clearId;
                    string refName;
                    eventData = new Dictionary <string, object>(customEventData.data as TreeDict);
                    clearId   = Trees.At(eventData, "_clearID");
                    if (clearId == null)
                    {
                        clearId = Trees.At(eventData, "_clearId");
                    }
                    refName = Trees.At(eventData, "_ref");
                    Logger.log.Debug($"ShaderClear at : {customEventData.time / 60 * _beatmapObjectSpawnController.currentBpm}");
                    Logger.log.Debug($"_clearId : {clearId}");
                    Logger.log.Debug($"_ref : {refName}");
                    if (clearId != null)
                    {
                        if (clearId.Equals("*"))
                        {
                            List <Material> removedMats = _shaderManager.ClearAllMaterials();
                            if (removedMats.Count > 0)
                            {
                                Logger.log.Debug($"Clearing all {removedMats.Count} Materials!");
                                StopAllCoroutinesModifyingMaterials(removedMats);
                            }
                            break;
                        }
                        ShaderEffectData sfx = _shaderManager.GetShaderEffectByReferenceName(refName);

                        Logger.log.Debug($"sfx reference Name : {sfx?.ReferenceName}");

                        if (sfx != null)
                        {
                            if (!_shaderManager.RemoveMaterial(clearId, sfx))
                            {
                                Logger.log.Notice($"Tried to remove a Shader with an ID that doesn't exist: '{clearId}' at time (in beats) {customEventData.time / 60 * _beatmapObjectSpawnController.currentBpm}!");
                            }
                        }
                        else
                        {
                            Logger.log.Debug($"trying to remove all with clearId");
                            List <Material> removedMats = _shaderManager.RemoveAllMaterialsStartingWithId(clearId);
                            if (removedMats.Count == 0)
                            {
                                Logger.log.Notice($"Tried to remove all Shaders starting with an ID that doesn't exist: '{clearId}' at time (in beats) {customEventData.time / 60 * _beatmapObjectSpawnController.currentBpm}!");
                            }
                            else
                            {
                                Logger.log.Debug($"Clearing {removedMats.Count} Materials with starting ID {clearId}!");
                                StopAllCoroutinesModifyingMaterials(removedMats);
                            }
                        }
                    }
                    break;

                default:
                    break;
                }
            }
            catch (Exception ex)
            {
                Logger.log.Error($"{nameof(ShaderEventManager)} encountered an exception at time (in beats) {customEventData.time / 60 * _beatmapObjectSpawnController.currentBpm}: {ex.Message}");
                Logger.log.Error(ex.StackTrace);
            }
        }