-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
81 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using System.IO.Compression; | ||
using Pack3r.Extensions; | ||
using Pack3r.IO; | ||
using Pack3r.Models; | ||
|
||
namespace Pack3r.Parsers; | ||
|
||
public class SkinParser(ILineReader reader) : IReferenceParser | ||
{ | ||
public bool CanParse(ReadOnlyMemory<char> resource) => resource.EndsWithF(".skin"); | ||
|
||
public Task<HashSet<Resource>?> Parse(string path, CancellationToken cancellationToken) | ||
{ | ||
return ParseCore(reader.ReadLines(path, default, cancellationToken))!; | ||
} | ||
|
||
public Task<HashSet<Resource>?> Parse(ZipArchiveEntry entry, string archivePath, CancellationToken cancellationToken) | ||
{ | ||
return ParseCore(reader.ReadLines(archivePath, entry, default, cancellationToken))!; | ||
} | ||
|
||
private static async Task<HashSet<Resource>> ParseCore(IAsyncEnumerable<Line> lines) | ||
{ | ||
var result = new HashSet<Resource>(); | ||
|
||
await foreach (var line in lines) | ||
{ | ||
int comma = line.Value.Span.IndexOf(','); | ||
|
||
if (comma >= 0) | ||
{ | ||
result.Add( | ||
new Resource(line.Value[(comma + 1)..].Trim().Trim('"'), IsShader: true)); | ||
} | ||
} | ||
|
||
return result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Pack3r.Parsers; | ||
|
||
namespace Pack3r.Tests; | ||
|
||
public static class SkinParserTests | ||
{ | ||
[Fact] | ||
public static async Task Should_Parse_Skin() | ||
{ | ||
var reader = new StringLineReader(""" | ||
head, "models/players/hud/allied_field" | ||
teeth,"models/players/hud/teeth01" | ||
eye1, "models/players/hud/eye02" | ||
eye2, "models/players/hud/eye02" | ||
"""); | ||
|
||
var parser = new SkinParser(reader); | ||
|
||
Assert.True(parser.CanParse("test.skin".AsMemory())); | ||
Assert.False(parser.CanParse("test.md3".AsMemory())); | ||
|
||
var result = await parser.Parse("", default); | ||
|
||
Assert.NotNull(result); | ||
Assert.Equal( | ||
[ | ||
"models/players/hud/allied_field", | ||
"models/players/hud/teeth01", | ||
"models/players/hud/eye02", | ||
], | ||
result.Select(s => s.Value.ToString())); | ||
} | ||
} |