Пример #1
0
        public ProgramDef GetProgram(int floorWidth, int floorHeight)
        {
            if ((randomFromList?.Count ?? 0) > 0)
            {
                return(randomFromList.RandomElement());
            }

            if (randomFromGroup != null)
            {
                return(ProgramDef.GetAllInGroup(randomFromGroup).RandomElementByWeight(item => item.GroupWeight));
            }

            if (program == null)
            {
                return(null);
            }

            if (!usePreferred || program.prefer == null)
            {
                return(program);
            }

            foreach (var preferred in program.prefer)
            {
                if (preferred.CanRunOn(floorWidth, floorHeight))
                {
                    return(preferred);
                }
            }
            return(program);
        }
Пример #2
0
        private static IEnumerable <ProgramDef> GenerateValidDefs()
        {
            if (customFiles == null)
            {
                yield break;
            }

            foreach (var file in customFiles)
            {
                if (file == null)
                {
                    continue;
                }
                if (!file.Exists)
                {
                    Core.Warn($"Ignoring {file.FilePath}, file does not exist!");
                    continue;
                }

                if (!file.IsValidFormat)
                {
                    Core.Warn($"Ignoring {file.FilePath}, invalid format!");
                    continue;
                }

                var    info    = new FileInfo(file.FilePath);
                string defName = info.Name;
                defName = defName.Replace(info.Extension, "");
                defName = defName.Replace(" ", "_");
                defName = "CUSTOM_" + defName;

                var def = new ProgramDef();
                def.modContentPack = Core.ContentPack;
                def.defName        = defName;
                def.label          = $"Autogenerated song def for {info.Name}";
                def.description    = "Nothing to see here";
                def.GroupWeight    = file.Weight;
                def.programClass   = typeof(SongPlayer);
                def.groups         = new List <string>()
                {
                    "Songs"
                };
                def.inputs = new DiscoDict();
                def.inputs.Add("volume", "1");
                def.inputs.Add("format", file.Format.ToString());
                def.inputs.Add("filePath", file.FilePath);
                def.inputs.Add("credits", info.Name.Replace(info.Extension, ""));

                yield return(def);
            }
        }