示例#1
0
        private static NgParameterRange ReadNgParameterRange(XmlNode node)
        {
            var listKind = (NgParameterKind)Enum.Parse(typeof(NgParameterKind), node.Name);

            switch (listKind)
            {
            case NgParameterKind.FixedEnumeration:
                var fixedList = new SortedList <ushort, TriggerParameterUshort>(node.ChildNodes.Count);
                foreach (XmlNode objectNode in node.ChildNodes)
                {
                    var key  = ushort.Parse(objectNode.Attributes["K"].Value, CultureInfo.InvariantCulture);
                    var name = objectNode.Attributes["V"].Value;
                    fixedList.Add(key, new TriggerParameterUshort(key, name));
                }
                return(new NgParameterRange(fixedList));

            case NgParameterKind.LinearModel:
                var linearParameters = new List <NgLinearParameter>(node.ChildNodes.Count);
                foreach (XmlNode objectNode in node.ChildNodes)
                {
                    switch (objectNode.Name)
                    {
                    case "Fixed":
                        linearParameters.Add(new NgLinearParameter {
                            FixedStr = objectNode.InnerText
                        });
                        break;

                    case "Linear":
                        linearParameters.Add(new NgLinearParameter
                        {
                            Add    = decimal.Parse(objectNode.Attributes["Add"].Value),
                            Factor = decimal.Parse(objectNode.Attributes["Factor"].Value)
                        });
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }
                }
                NgLinearModel linearModel = new NgLinearModel
                {
                    Parameters   = linearParameters,
                    Start        = ushort.Parse(node.Attributes["Start"].Value),
                    EndInclusive = ushort.Parse(node.Attributes["End"].Value)
                };
                return(new NgParameterRange(linearModel));

            case NgParameterKind.Choice:
                var choices = new List <NgParameterRange>(node.ChildNodes.Count);
                foreach (XmlNode objectNode in node.ChildNodes)
                {
                    choices.Add(ReadNgParameterRange(objectNode));
                }
                return(new NgParameterRange(choices));

            default:
                return(new NgParameterRange(listKind));
            }
        }
示例#2
0
 public NgParameterRange(NgLinearModel linearModel)
 {
     Choices          = null;
     FixedEnumeration = null;
     Kind             = NgParameterKind.LinearModel;
     LinearModel      = linearModel;
 }
示例#3
0
        public IEnumerable <ITriggerParameter> BuildList(Level level)
        {
            Func <int, int, TriggerParameterUshort> formatSounds = (add, i) =>
            {
                WadSoundInfo info = level?.Settings?.WadTryGetSoundInfo(add + i);
                if (info != null)
                {
                    return(new TriggerParameterUshort((ushort)i, (add + i) + ": " + info.Name));
                }
                else
                {
                    return(new TriggerParameterUshort((ushort)i, (add + i) + ": --- Not present ---"));
                }
            };
            Func <int, TriggerParameterUshort> formatSounds1 = i => formatSounds(0, i);
            Func <int, TriggerParameterUshort> formatSounds2 = i => formatSounds(256, i);

            switch (Kind)
            {
            case NgParameterKind.Empty:
                return(new ITriggerParameter[0]);

            case NgParameterKind.AnyNumber:
                return(null);

            case NgParameterKind.FixedEnumeration:
                return(FixedEnumeration.Values);

            case NgParameterKind.LinearModel:
                NgLinearModel linearModel = LinearModel.Value;
                return(Enumerable.Range(linearModel.Start, linearModel.EndInclusive + 1 - linearModel.Start)
                       .Select(i => new TriggerParameterUshort((ushort)i, linearModel.ToString((ushort)i))));

            case NgParameterKind.Choice:
                return(Choices.Aggregate(
                           Enumerable.Empty <ITriggerParameter>(),
                           (last, newChoice) => last.Concat(newChoice.BuildList(level))));

            case NgParameterKind.MoveablesInLevel:
                return(level.Rooms.Where(room => room != null).SelectMany(room => room.Objects).OfType <MoveableInstance>());

            case NgParameterKind.StaticsInLevel:
                return(level.Rooms.Where(room => room != null).SelectMany(room => room.Objects).OfType <StaticInstance>());

            case NgParameterKind.CamerasInLevel:
                return(level.Rooms.Where(room => room != null).SelectMany(room => room.Objects).OfType <CameraInstance>());

            case NgParameterKind.SinksInLevel:
                return(level.Rooms.Where(room => room != null).SelectMany(room => room.Objects).OfType <SinkInstance>());

            case NgParameterKind.FlybyCamerasInLevel:
                return(level.Rooms.Where(room => room != null).SelectMany(room => room.Objects).OfType <FlybyCameraInstance>());

            case NgParameterKind.Rooms255:
                return(level.Rooms.Where(room => room != null));

            case NgParameterKind.SoundEffectsA:
                return(Enumerable.Range(0, 256).Select(formatSounds1));

            case NgParameterKind.SoundEffectsB:
                return(Enumerable.Range(0, 114).Select(formatSounds2));

            case NgParameterKind.Sfx1024:
                return(Enumerable.Range(0, 1024).Select(formatSounds1));

            case NgParameterKind.PcStringsList:
                return(LoadStringsFromTxt(level, "PCStrings"));

            case NgParameterKind.PsxStringsList:
                return(LoadStringsFromTxt(level, "PSXStrings"));

            case NgParameterKind.NgStringsList255:
                return(LoadStringsFromTxt(level, "ExtraNG", 256, 1));

            case NgParameterKind.NgStringsAll:
                return(LoadStringsFromTxt(level, "ExtraNG", 1));

            case NgParameterKind.StringsList255:
                return(LoadStringsFromTxt(level, "Strings", 256));

            case NgParameterKind.WadSlots:
                if (level?.Settings == null)
                {
                    return(new ITriggerParameter[0]);
                }
                return(level.Settings.WadGetAllMoveables().Select(p =>
                                                                  new TriggerParameterUshort(
                                                                      checked ((ushort)p.Key.TypeId),
                                                                      p.Value.ToString(level.Settings.GameVersion.Native()))));

            case NgParameterKind.StaticsSlots:
                if (level?.Settings == null)
                {
                    return(new ITriggerParameter[0]);
                }
                return(level.Settings.WadGetAllStatics().Select(p =>
                                                                new TriggerParameterUshort(
                                                                    checked ((ushort)p.Key.TypeId),
                                                                    p.Value.ToString(level.Settings.GameVersion.Native()))));

            case NgParameterKind.LaraStartPosOcb:
                return(level.Rooms.Where(room => room != null)
                       .SelectMany(room => room.Objects)
                       .OfType <MoveableInstance>().Where(obj => obj.WadObjectId.TypeId == 406) // Lara start pos
                       .Select(obj => new TriggerParameterUshort(unchecked ((ushort)obj.Ocb), obj)));

            default:
                throw new ArgumentException("Unknown NgListKind \"" + Kind + "\"");
            }
        }