更新默认皮肤 (#2943)
* 更新默认皮肤 * update * update * update * update * update * update
@@ -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;
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
BIN
HMCLCore/src/main/resources/assets/img/skin/slim/alex.png
Normal file
|
After Width: | Height: | Size: 1.2 KiB |
BIN
HMCLCore/src/main/resources/assets/img/skin/slim/ari.png
Normal file
|
After Width: | Height: | Size: 1.1 KiB |
BIN
HMCLCore/src/main/resources/assets/img/skin/slim/efe.png
Normal file
|
After Width: | Height: | Size: 1.3 KiB |
BIN
HMCLCore/src/main/resources/assets/img/skin/slim/kai.png
Normal file
|
After Width: | Height: | Size: 1.5 KiB |
BIN
HMCLCore/src/main/resources/assets/img/skin/slim/makena.png
Normal file
|
After Width: | Height: | Size: 1.4 KiB |
BIN
HMCLCore/src/main/resources/assets/img/skin/slim/noor.png
Normal file
|
After Width: | Height: | Size: 1.1 KiB |
BIN
HMCLCore/src/main/resources/assets/img/skin/slim/steve.png
Normal file
|
After Width: | Height: | Size: 1.1 KiB |
BIN
HMCLCore/src/main/resources/assets/img/skin/slim/sunny.png
Normal file
|
After Width: | Height: | Size: 1.2 KiB |
BIN
HMCLCore/src/main/resources/assets/img/skin/slim/zuri.png
Normal file
|
After Width: | Height: | Size: 1.1 KiB |
BIN
HMCLCore/src/main/resources/assets/img/skin/wide/alex.png
Normal file
|
After Width: | Height: | Size: 1.2 KiB |
BIN
HMCLCore/src/main/resources/assets/img/skin/wide/ari.png
Normal file
|
After Width: | Height: | Size: 1.1 KiB |
BIN
HMCLCore/src/main/resources/assets/img/skin/wide/efe.png
Normal file
|
After Width: | Height: | Size: 1.3 KiB |
BIN
HMCLCore/src/main/resources/assets/img/skin/wide/kai.png
Normal file
|
After Width: | Height: | Size: 1.5 KiB |
BIN
HMCLCore/src/main/resources/assets/img/skin/wide/makena.png
Normal file
|
After Width: | Height: | Size: 1.4 KiB |
BIN
HMCLCore/src/main/resources/assets/img/skin/wide/noor.png
Normal file
|
After Width: | Height: | Size: 1.1 KiB |
BIN
HMCLCore/src/main/resources/assets/img/skin/wide/steve.png
Normal file
|
After Width: | Height: | Size: 1.2 KiB |
BIN
HMCLCore/src/main/resources/assets/img/skin/wide/sunny.png
Normal file
|
After Width: | Height: | Size: 1.2 KiB |
BIN
HMCLCore/src/main/resources/assets/img/skin/wide/zuri.png
Normal file
|
After Width: | Height: | Size: 1.1 KiB |
@@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||