Skip to content

Commit

Permalink
Fix incorrect map keys in root parse method
Browse files Browse the repository at this point in the history
  • Loading branch information
soir20 committed Aug 13, 2023
1 parent 75ccbca commit da50c89
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public Map<ResourceLocation, MetadataView> parse(ResourceLocation metadataLocati
@Override
public Map<? extends RootResourceName, ? extends Map<? extends RootResourceName, ? extends MetadataView>> parse(
ResourceRepository.Pack pack) {
Map<RootResourceName, MetadataView> anims = new HashMap<>();
Map<RootResourceName, Map<RootResourceName, MetadataView>> anims = new HashMap<>();
int index = 0;

while (true) {
Expand Down Expand Up @@ -118,11 +118,11 @@ public Map<ResourceLocation, MetadataView> parse(ResourceLocation metadataLocati
new PropertiesMetadataView.Value(imageStream))
);

anims.put(animName, readAnimationFile(metadata, props));
anims.put(animName, ImmutableMap.of(new RootResourceName("pack.png"), readAnimationFile(metadata, props)));
index++;
}

return ImmutableMap.of(new RootResourceName("pack.png"), anims);
return anims;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -752,7 +752,7 @@ public void parse_UsesAllAnimationProperties_AllParsed() throws InvalidMetadataE

@Test
public void parse_ToPackPngUsesAllAnimationProperties_AllParsed() {
Map<? extends RootResourceName, ? extends MetadataView> views = PARSER.parse(
Map<? extends RootResourceName, ? extends Map<? extends RootResourceName, ? extends MetadataView>> views = PARSER.parse(
new ResourceRepository.Pack() {
@Override
public Optional<InputStream> resource(ResourceLocation location) {
Expand Down Expand Up @@ -790,9 +790,10 @@ public ResourceLocation locateRootResource(RootResourceName rootResourceName) {
return new ResourceLocation("root/" + rootResourceName);
}
}
).get(new RootResourceName("pack.png"));
);

MetadataView animationView = views.get(new RootResourceName("pack_anim0.properties"))
.get(new RootResourceName("pack.png"))
.subView("animation").orElseThrow()
.subView("parts").orElseThrow()
.subView(0).orElseThrow();
Expand Down Expand Up @@ -868,7 +869,7 @@ public ResourceLocation locateRootResource(RootResourceName rootResourceName) {

@Test
public void parse_ToPackPngUsesMultipleAnimations_AllParsed() {
Map<? extends RootResourceName, ? extends MetadataView> views = PARSER.parse(
Map<? extends RootResourceName, ? extends Map<? extends RootResourceName, ? extends MetadataView>> views = PARSER.parse(
new ResourceRepository.Pack() {
@Override
public Optional<InputStream> resource(ResourceLocation location) {
Expand Down Expand Up @@ -907,9 +908,10 @@ public ResourceLocation locateRootResource(RootResourceName rootResourceName) {
return new ResourceLocation("root/" + rootResourceName);
}
}
).get(new RootResourceName("pack.png"));
);

MetadataView animationView1 = views.get(new RootResourceName("pack_anim0.properties"))
.get(new RootResourceName("pack.png"))
.subView("animation").orElseThrow()
.subView("parts").orElseThrow()
.subView(0).orElseThrow();
Expand All @@ -925,6 +927,7 @@ public ResourceLocation locateRootResource(RootResourceName rootResourceName) {
assertEquals(30, (int) animationView1.integerValue("height").orElseThrow());

MetadataView animationView2 = views.get(new RootResourceName("pack_anim1.properties"))
.get(new RootResourceName("pack.png"))
.subView("animation").orElseThrow()
.subView("parts").orElseThrow()
.subView(0).orElseThrow();
Expand All @@ -938,7 +941,7 @@ public ResourceLocation locateRootResource(RootResourceName rootResourceName) {

@Test
public void parse_ToPackPngAnimationMissingTexture_AllParsed() {
Map<? extends RootResourceName, ? extends MetadataView> views = PARSER.parse(
Map<? extends RootResourceName, ? extends Map<? extends RootResourceName, ? extends MetadataView>> views = PARSER.parse(
new ResourceRepository.Pack() {
@Override
public Optional<InputStream> resource(ResourceLocation location) {
Expand Down Expand Up @@ -976,9 +979,10 @@ public ResourceLocation locateRootResource(RootResourceName rootResourceName) {
return new ResourceLocation("root/" + rootResourceName);
}
}
).get(new RootResourceName("pack.png"));
);

MetadataView animationView1 = views.get(new RootResourceName("pack_anim0.properties"))
.get(new RootResourceName("pack.png"))
.subView("animation").orElseThrow()
.subView("parts").orElseThrow()
.subView(0).orElseThrow();
Expand All @@ -994,6 +998,7 @@ public ResourceLocation locateRootResource(RootResourceName rootResourceName) {
assertEquals(30, (int) animationView1.integerValue("height").orElseThrow());

MetadataView animationView2 = views.get(new RootResourceName("pack_anim1.properties"))
.get(new RootResourceName("pack.png"))
.subView("animation").orElseThrow()
.subView("parts").orElseThrow()
.subView(0).orElseThrow();
Expand All @@ -1010,7 +1015,7 @@ public void parse_ToPackPngBadAnimationFile_StopsAtBadFile() throws IOException
InputStream badStream = InputStream.nullInputStream();
badStream.close();

Map<? extends RootResourceName, ? extends MetadataView> views = PARSER.parse(
Map<? extends RootResourceName, ? extends Map<? extends RootResourceName, ? extends MetadataView>> views = PARSER.parse(
new ResourceRepository.Pack() {
@Override
public Optional<InputStream> resource(ResourceLocation location) {
Expand Down Expand Up @@ -1049,9 +1054,10 @@ public ResourceLocation locateRootResource(RootResourceName rootResourceName) {
return new ResourceLocation("root/" + rootResourceName);
}
}
).get(new RootResourceName("pack.png"));
);

MetadataView animationView1 = views.get(new RootResourceName("pack_anim0.properties"))
.get(new RootResourceName("pack.png"))
.subView("animation").orElseThrow()
.subView("parts").orElseThrow()
.subView(0).orElseThrow();
Expand All @@ -1067,6 +1073,7 @@ public ResourceLocation locateRootResource(RootResourceName rootResourceName) {
assertEquals(30, (int) animationView1.integerValue("height").orElseThrow());

MetadataView animationView2 = views.get(new RootResourceName("pack_anim1.properties"))
.get(new RootResourceName("pack.png"))
.subView("animation").orElseThrow()
.subView("parts").orElseThrow()
.subView(0).orElseThrow();
Expand Down

0 comments on commit da50c89

Please sign in to comment.