2023-06-25 04:39:12 +02:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.IO;
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
|
2023-06-26 01:03:14 +02:00
|
|
|
namespace VertexColor.ScenePartition
|
2023-06-25 04:39:12 +02:00
|
|
|
{
|
|
|
|
public class SceneIdComparer : IComparer<ScenePartition>
|
|
|
|
{
|
|
|
|
public int Compare(ScenePartition x, ScenePartition y)
|
|
|
|
{
|
|
|
|
if (x.id == y.id)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (x.id < y.id)
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[System.Serializable]
|
|
|
|
public class ScenePartition
|
|
|
|
{
|
2023-07-03 23:35:29 +02:00
|
|
|
public ulong id = 0;
|
|
|
|
//public ulong classId = 0;
|
|
|
|
public string filePath = null; // TODO: Only store relative path.
|
2023-06-26 01:03:14 +02:00
|
|
|
//public string[] data = null;
|
2023-06-30 03:28:44 +02:00
|
|
|
public LongSortedSet references = new LongSortedSet();
|
2023-06-25 04:39:12 +02:00
|
|
|
|
|
|
|
public ScenePartition(string filePath)
|
|
|
|
{
|
|
|
|
this.filePath = filePath;
|
|
|
|
|
2023-06-26 01:03:14 +02:00
|
|
|
string[] data = File.ReadAllLines(filePath);
|
2023-06-25 04:39:12 +02:00
|
|
|
|
|
|
|
if (data == null || data.Length == 0) return;
|
|
|
|
|
|
|
|
{ // Get id.
|
|
|
|
string pattern = @"&(\d+)";
|
|
|
|
|
|
|
|
// Find all matches using regex
|
|
|
|
Match match = Regex.Match(data[0], pattern);
|
|
|
|
|
|
|
|
if (!match.Success) return;
|
2023-07-03 23:35:29 +02:00
|
|
|
if (!ulong.TryParse(match.Groups[1].Value, out id)) return;
|
2023-06-25 04:39:12 +02:00
|
|
|
}
|
|
|
|
|
2023-06-30 03:28:44 +02:00
|
|
|
//{ // Get class id.
|
|
|
|
// string pattern = @"!u!(\d+)";
|
|
|
|
|
|
|
|
// // Find all matches using regex
|
|
|
|
// Match match = Regex.Match(data[0], pattern);
|
|
|
|
|
|
|
|
// if (!match.Success) return;
|
|
|
|
// if (!long.TryParse(match.Groups[1].Value, out classId)) return;
|
|
|
|
//}
|
|
|
|
|
2023-06-25 04:39:12 +02:00
|
|
|
{ // Get references.
|
|
|
|
string pattern = @"fileID:\s(\d+)";
|
|
|
|
|
|
|
|
for (int i = 0; i < data.Length; i++)
|
|
|
|
{
|
|
|
|
// Find the match using regex
|
|
|
|
Match match = Regex.Match(data[i], pattern);
|
|
|
|
|
|
|
|
if (!match.Success) continue;
|
|
|
|
|
2023-07-03 23:35:29 +02:00
|
|
|
if (ulong.TryParse(match.Groups[1].Value, out ulong fileNumber))
|
2023-06-25 04:39:12 +02:00
|
|
|
{
|
|
|
|
if (fileNumber == 0) continue; // 0 == nothing.
|
|
|
|
|
|
|
|
references.Add(fileNumber);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|