更新默认皮肤 (#2943)

* 更新默认皮肤

* update

* update

* update

* update

* update

* update
This commit is contained in:
Glavo
2024-03-22 16:09:25 +08:00
committed by GitHub
parent 127938fa38
commit abec1abcff
43 changed files with 76 additions and 135 deletions

View File

@@ -18,6 +18,7 @@
package org.jackhuang.hmcl.auth.offline;
import com.google.gson.annotations.SerializedName;
import javafx.scene.image.Image;
import org.jackhuang.hmcl.auth.yggdrasil.TextureModel;
import org.jackhuang.hmcl.task.FetchTask;
import org.jackhuang.hmcl.task.GetTask;
@@ -39,7 +40,6 @@ import java.util.Collections;
import java.util.Locale;
import java.util.Map;
import java.util.Optional;
import java.util.function.Function;
import static org.jackhuang.hmcl.util.Lang.mapOf;
import static org.jackhuang.hmcl.util.Lang.tryCast;
@@ -99,12 +99,6 @@ public class Skin {
}
}
private static Function<Type, InputStream> defaultSkinLoader = null;
public static void registerDefaultSkinLoader(Function<Type, InputStream> defaultSkinLoader0) {
defaultSkinLoader = defaultSkinLoader0;
}
private final Type type;
private final String cslApi;
private final TextureModel textureModel;
@@ -128,7 +122,7 @@ public class Skin {
}
public TextureModel getTextureModel() {
return textureModel == null ? TextureModel.STEVE : textureModel;
return textureModel == null ? TextureModel.WIDE : textureModel;
}
public String getLocalSkinPath() {
@@ -152,11 +146,14 @@ public class Skin {
case STEVE:
case SUNNY:
case ZURI:
if (defaultSkinLoader == null) {
return Task.supplyAsync(() -> null);
}
TextureModel model = type == Type.ALEX ? TextureModel.ALEX : TextureModel.STEVE;
return Task.supplyAsync(() -> new LoadedSkin(model, Texture.loadTexture(defaultSkinLoader.apply(type)), null));
TextureModel model = this.textureModel != null ? this.textureModel : type == Type.ALEX ? TextureModel.SLIM : TextureModel.WIDE;
String resource = (model == TextureModel.SLIM ? "/assets/img/skin/slim/" : "/assets/img/skin/wide/") + type.name().toLowerCase(Locale.ROOT) + ".png";
return Task.supplyAsync(() -> new LoadedSkin(
model,
Texture.loadTexture(new Image(resource)),
null
));
case LOCAL_FILE:
return Task.supplyAsync(() -> {
Texture skin = null, cape = null;
@@ -227,16 +224,7 @@ public class Skin {
String localSkinPath = tryCast(storage.get("localSkinPath"), String.class).orElse(null);
String localCapePath = tryCast(storage.get("localCapePath"), String.class).orElse(null);
TextureModel model;
if ("default".equals(textureModel)) {
model = TextureModel.STEVE;
} else if ("slim".equals(textureModel)) {
model = TextureModel.ALEX;
} else {
model = TextureModel.STEVE;
}
return new Skin(type, cslApi, model, localSkinPath, localCapePath);
return new Skin(type, cslApi, "slim".equals(textureModel) ? TextureModel.SLIM : TextureModel.WIDE, localSkinPath, localCapePath);
}
private static class FetchBytesTask extends FetchTask<InputStream> {
@@ -327,9 +315,9 @@ public class Skin {
@Nullable
public TextureModel getModel() {
if (textures != null && textures.slim != null) {
return TextureModel.ALEX;
return TextureModel.SLIM;
} else if (textures != null && textures.defaultSkin != null) {
return TextureModel.STEVE;
return TextureModel.WIDE;
} else {
return null;
}
@@ -351,9 +339,9 @@ public class Skin {
public String getHash() {
TextureModel model = getModel();
if (model == TextureModel.ALEX)
if (model == TextureModel.SLIM)
return getAlexModelHash();
else if (model == TextureModel.STEVE)
else if (model == TextureModel.WIDE)
return getSteveModelHash();
else
return null;

View File

@@ -178,7 +178,7 @@ public class YggdrasilServer extends HttpServer {
public Object toCompleteResponse(String rootUrl) {
Map<String, Object> realTextures = new HashMap<>();
if (skin != null && skin.getSkin() != null) {
if (skin.getModel() == TextureModel.ALEX) {
if (skin.getModel() == TextureModel.SLIM) {
realTextures.put("SKIN", mapOf(
pair("url", rootUrl + "/textures/" + skin.getSkin().getHash()),
pair("metadata", mapOf(

View File

@@ -17,27 +17,12 @@
*/
package org.jackhuang.hmcl.auth.yggdrasil;
import java.util.Map;
import java.util.UUID;
public enum TextureModel {
STEVE("default"), ALEX("slim");
WIDE("default"), SLIM("slim");
public final String modelName;
TextureModel(String modelName) {
this.modelName = modelName;
}
public static TextureModel detectModelName(Map<String, String> metadata) {
if (metadata != null && "slim".equals(metadata.get("model"))) {
return ALEX;
} else {
return STEVE;
}
}
public static TextureModel detectUUID(UUID uuid) {
return (uuid.hashCode() & 1) == 1 ? ALEX : STEVE;
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@@ -9,22 +9,19 @@ import java.nio.file.Paths;
import static org.junit.jupiter.api.Assertions.*;
public class NormalizedSkinTest {
private static NormalizedSkin getSkin(String name) throws InvalidSkinException {
String path = Paths.get("../HMCL/src/main/resources/assets/img/skin/" + name + ".png").normalize().toAbsolutePath().toUri().toString();
private static NormalizedSkin getSkin(String name, boolean slim) throws InvalidSkinException {
String path = Paths.get(String.format("../HMCLCore/src/main/resources/assets/img/skin/%s/%s.png", slim ? "slim" : "wide", name)).normalize().toAbsolutePath().toUri().toString();
return new NormalizedSkin(new Image(path));
}
@Test
@EnabledIf("org.jackhuang.hmcl.JavaFXLauncher#isStarted")
public void testIsSlim() throws Exception {
assertFalse(getSkin("steve").isSlim());
assertTrue(getSkin("alex").isSlim());
assertTrue(getSkin("noor").isSlim());
assertFalse(getSkin("sunny").isSlim());
assertFalse(getSkin("ari").isSlim());
assertFalse(getSkin("zuri").isSlim());
assertTrue(getSkin("makena").isSlim());
assertFalse(getSkin("kai").isSlim());
assertTrue(getSkin("efe").isSlim());
String[] names = {"alex", "ari", "efe", "kai", "makena", "noor", "steve", "sunny", "zuri"};
for (String skin : names) {
assertTrue(getSkin(skin, true).isSlim());
assertFalse(getSkin(skin, false).isSlim());
}
}
}