Exemple #1
0
 /// <summary>
 /// Gets the levels for each world
 /// </summary>
 /// <param name="settings">The game settings</param>
 /// <returns>The levels</returns>
 public override GameInfo_Volume[] GetLevels(GameSettings settings) => Directory.GetDirectories(settings.GameDirectory + "/" + GetDataPath(), "???", SearchOption.TopDirectoryOnly).Select(Path.GetFileName).Select(vol => new GameInfo_Volume(vol, WorldHelpers.GetR1Worlds().Select(w => new GameInfo_World((int)w, Directory.EnumerateFiles(settings.GameDirectory + GetVolumePath(vol), $"{GetShortWorldName(w)}??.LEV", SearchOption.TopDirectoryOnly)
                                                                                                                                                                                                                                                                                                              .Select(FileSystem.GetFileNameWithoutExtensions)
                                                                                                                                                                                                                                                                                                              .Select(x => Int32.Parse(x.Substring(3)))
                                                                                                                                                                                                                                                                                                              .ToArray())).Append(new GameInfo_World(7, new []
 {
     0
 })).ToArray())).ToArray();
Exemple #2
0
 /// <summary>
 /// Gets the levels for each world
 /// </summary>
 /// <param name="settings">The game settings</param>
 /// <returns>The levels</returns>
 public override GameInfo_Volume[] GetLevels(GameSettings settings) => GameInfo_Volume.SingleVolume(WorldHelpers.GetR1Worlds().Select(w => new GameInfo_World((int)w, Directory.EnumerateFiles(settings.GameDirectory + GetWorldFolderPath(w), $"*.XMP", SearchOption.TopDirectoryOnly)
                                                                                                                                                              .Select(FileSystem.GetFileNameWithoutExtensions)
                                                                                                                                                              .Select(x => Int32.Parse(x.Substring(5)))
                                                                                                                                                              .ToArray())).Select(x => x.Index == 1 ? new GameInfo_World(x.Index, x.Maps.Append(140).ToArray()) : x).Append(new GameInfo_World(7, new int[]
 {
     0
 })).ToArray());
Exemple #3
0
 /// <summary>
 /// Gets the levels for each world
 /// </summary>
 /// <param name="settings">The game settings</param>
 /// <returns>The levels</returns>
 public override GameInfo_Volume[] GetLevels(GameSettings settings) => GameInfo_Volume.SingleVolume(WorldHelpers.GetR1Worlds().Select(w => new GameInfo_World((int)w, Directory.EnumerateDirectories(settings.GameDirectory + GetWorldFolderPath(w), "MAP*", SearchOption.TopDirectoryOnly)
                                                                                                                                                              .Select(Path.GetFileName)
                                                                                                                                                              .Where(x => x.Length < 7)
                                                                                                                                                              .Select(x => Int32.Parse(x.Replace("_", String.Empty).Substring(3)))
                                                                                                                                                              .ToArray())).ToArray());
 /// <summary>
 /// Gets the levels for each world
 /// </summary>
 /// <param name="settings">The game settings</param>
 /// <returns>The levels</returns>
 public override GameInfo_Volume[] GetLevels(GameSettings settings) => GameInfo_Volume.SingleVolume(WorldHelpers.GetR1Worlds().Where(w => Directory.Exists(settings.GameDirectory + GetWorldFolderPath(w)))
                                                                                                    .Select(w => new GameInfo_World((int)w, Directory.EnumerateFiles(settings.GameDirectory + GetWorldFolderPath(w), $"{GetWorldName(w)}**.XXX", SearchOption.TopDirectoryOnly)
                                                                                                                                    .Select(FileSystem.GetFileNameWithoutExtensions)
                                                                                                                                    .Where(x => x.Length == 5)
                                                                                                                                    .Select(x => Int32.Parse(x.Substring(3)))
                                                                                                                                    .ToArray())).Where(x => x.Maps.Any()).Append(new GameInfo_World(7, new int[]
 {
     0     // Worldmap
 })).ToArray());
 /// <summary>
 /// Gets the levels for each world
 /// </summary>
 /// <param name="settings">The game settings</param>
 /// <returns>The levels</returns>
 public override GameInfo_Volume[] GetLevels(GameSettings settings) => GameInfo_Volume.SingleVolume(WorldHelpers.GetR1Worlds().Select(w => new GameInfo_World((int)w, Directory.EnumerateFiles(settings.GameDirectory, $"{GetWorldName(w)}*.MAP", SearchOption.TopDirectoryOnly)
                                                                                                                                                              .Select(FileSystem.GetFileNameWithoutExtensions)
                                                                                                                                                              .Select(x => Int32.Parse(x.Substring(3)))
                                                                                                                                                              .ToArray())).ToArray());
Exemple #6
0
        /// <summary>
        /// Reads the event info data from a .csv file
        /// </summary>
        /// <param name="fileStream">The file stream to read from</param>
        /// <param name="sort">Indicates if the items should be sorted</param>
        /// <returns>The read data</returns>
        public static GeneralEventInfoData[] ReadCSV(Stream fileStream, bool sort = true)
        {
            // Use a reader
            using (var reader = new StreamReader(fileStream))
            {
                // Create the output
                var output = new List <GeneralEventInfoData>();

                // Skip header
                reader.ReadLine();

                // Read every line
                while (!reader.EndOfStream)
                {
                    // Read the line
                    var line = reader.ReadLine()?.Split(',');

                    // Make sure we read something
                    if (line == null)
                    {
                        break;
                    }

                    // Keep track of the value index
                    var index = 0;

                    try
                    {
                        // Helper methods for parsing values
                        string nextValue() => line[index++];
                        bool nextBoolValue() => Boolean.Parse(line[index++]);
                        ushort nextUShortValue() => UInt16.Parse(nextValue());
                        uint nextUIntValue() => UInt32.Parse(nextValue());
                        byte nextByteValue() => Byte.Parse(nextValue());

                        //T? nextEnumValue<T>() where T : struct => Enum.TryParse(nextValue(), out T parsedEnum) ? (T?)parsedEnum : null;
                        ushort[] next16ArrayValue() => nextValue().Split('-').Where(x => !String.IsNullOrWhiteSpace(x)).Select(UInt16.Parse).ToArray();

                        int?[] next32NullableArrayValue() => nextValue().Split('-').Select(x => String.IsNullOrWhiteSpace(x) ? null : (int?)Int32.Parse(x)).ToArray();

                        int[] next32ArrayValue() => nextValue().Split('-').Select(Int32.Parse).ToArray();

                        byte[] next8ArrayValue() => nextValue().Split('-').Where(x => !String.IsNullOrWhiteSpace(x)).Select(Byte.Parse).ToArray();

                        string[] nextStringArrayValue() => nextValue().Split('-').ToArray();

                        IDictionary <R1_World, T> toDictionary <T>(IList <T> values)
                        {
                            var dict = WorldHelpers.GetR1Worlds().ToDictionary(x => x, x => default(T));

                            for (int i = 1; i < values.Count + 1; i++)
                            {
                                dict[(R1_World)i] = values[i - 1];
                            }

                            return(dict);
                        }

                        // Add the item to the output
                        output.Add(new GeneralEventInfoData(name: nextValue(), codeNames: nextStringArrayValue(),
                                                            type: nextUShortValue(), typeName: nextValue(),
                                                            etat: nextByteValue(), subEtat: nextByteValue(),
                                                            des: nextValue(), eta: nextValue(),
                                                            worlds: next32ArrayValue().Select(x => (R1_World)x).ToArray(), engines: nextStringArrayValue().Select(x => (Engine)Enum.Parse(typeof(Engine), x)).ToArray(),
                                                            offsetBx: nextByteValue(), offsetBy: nextByteValue(), offsetHy: nextByteValue(),
                                                            followSprite: nextByteValue(), hitPoints: nextUIntValue(), hitSprite: nextByteValue(), followEnabled: nextBoolValue(),
                                                            connectedEvents: nextStringArrayValue(),
                                                            labelOffsets: next16ArrayValue(), commands: next8ArrayValue()));
                    }
                    catch (Exception ex)
                    {
                        Debug.LogError($"Failed to parse event info. Index: {index}, items: {String.Join(" - ", line)} , exception: {ex.Message}");
                        throw;
                    }
                }

                // Return the output
                return(sort ? output.OrderBy(x => x.Name).ThenBy(x => x.Type).ToArray() : output.ToArray());
            }
        }