Skip to content

Commit

Permalink
Merge branch 'v3.x' into v4.x-cross
Browse files Browse the repository at this point in the history
  • Loading branch information
isHarryh committed Jan 20, 2025
2 parents 7538a93 + 9d945ca commit 1c80ac4
Show file tree
Hide file tree
Showing 8 changed files with 403 additions and 288 deletions.
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,9 @@ project(":core") {
api "com.alibaba:fastjson:2.0.39"
// Log4j
api "apache-log4j:log4j:1.2.15"
// TiniPinyin
api 'com.github.promeg:tinypinyin:2.0.3'
// OpenCC4j
api 'com.github.houbb:opencc4j:1.8.1'
}
}
8 changes: 4 additions & 4 deletions core/src/cn/harryh/arkpets/ArkChar.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import cn.harryh.arkpets.animations.AnimClipGroup;
import cn.harryh.arkpets.animations.AnimComposer;
import cn.harryh.arkpets.animations.AnimData;
import cn.harryh.arkpets.assets.AssetItem.AssetAccessor;
import cn.harryh.arkpets.assets.ModelItem.ModelAssetAccessor;
import cn.harryh.arkpets.transitions.EasingFunction;
import cn.harryh.arkpets.transitions.TransitionFloat;
import cn.harryh.arkpets.transitions.TransitionVector3;
Expand Down Expand Up @@ -87,9 +87,9 @@ public ArkChar(ArkConfig config, float scale) {
SkeletonData skeletonData;
try {
String assetLocation = config.character_asset;
AssetAccessor assetAccessor = new AssetAccessor(config.character_files);
String path2atlas = assetLocation + separator + assetAccessor.getFirstFileOf(".atlas");
String path2skel = assetLocation + separator + assetAccessor.getFirstFileOf(".skel");
ModelAssetAccessor modelAssetAccessor = new ModelAssetAccessor(config.character_files);
String path2atlas = assetLocation + separator + modelAssetAccessor.getFirstFileOf(".atlas");
String path2skel = assetLocation + separator + modelAssetAccessor.getFirstFileOf(".skel");
// Load atlas
TextureAtlas atlas = new TextureAtlas(Gdx.files.internal(path2atlas));
// Load skel (use SkeletonJson instead of SkeletonBinary if the file type is JSON)
Expand Down
212 changes: 0 additions & 212 deletions core/src/cn/harryh/arkpets/assets/AssetItemGroup.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.annotation.JSONField;
import com.github.promeg.pinyinhelper.Pinyin;

import java.io.File;
import java.io.Serializable;
import java.util.*;
import java.util.function.Function;


/** One Asset Item is corresponding to one certain local Spine asset.
/** One Model Item is corresponding to one certain local Spine model.
*/
public class AssetItem implements Serializable {
public class ModelItem implements Serializable {
@JSONField(serialize = false)
public String key;
@JSONField(serialize = false)
Expand All @@ -42,11 +43,14 @@ public class AssetItem implements Serializable {
/** @deprecated Legacy field in old version dataset */ @JSONField @Deprecated
public JSONObject checksum;

private AssetAccessor accessor;
// Lazy generated fields:
private ModelAssetAccessor accessor;
private String pinyinQuanpin;
private String pinyinSuoxie;

protected static final String[] extensions = {".atlas", ".png", ".skel"};

private AssetItem() {
private ModelItem() {
}

/** Gets the directory where the asset files located in.
Expand All @@ -57,20 +61,50 @@ public String getLocation() {
return assetDir.toString();
}

/** Gets the Asset Accessor of this asset.
* @return An Asset Accessor instance.
/** Gets the Model Asset Accessor of the model's asset files.
* @return A Model Asset Accessor instance.
*/
@JSONField(serialize = false)
public AssetAccessor getAccessor() {
public ModelAssetAccessor getAccessor() {
if (accessor == null)
accessor = new AssetAccessor(assetList);
accessor = new ModelAssetAccessor(assetList);
return accessor;
}

/** Verifies the integrity of the necessary fields of this {@code AssetItem}.
/** Gets the 拼音全拼 (Pinyin Quanpin, full Pinyin transcription) of the model's name.
* @return A String.
*/
@JSONField(serialize = false)
public String getPinyinQuanpin() {
if (pinyinQuanpin == null)
pinyinQuanpin = Pinyin.toPinyin(name, "");
return pinyinQuanpin;
}

/** Gets the 拼音缩写 (Pinyin Suoxie, abbreviate Pinyin transcription) of the model's name.
* @return A String.
*/
@JSONField(serialize = false)
public String getPinyinSuoxie() {
if (pinyinSuoxie == null) {
String quanpin = Pinyin.toPinyin(name, " ").trim();
if (!quanpin.isEmpty()) {
StringBuilder builder = new StringBuilder();
for (String word : quanpin.split("\\s+")) {
builder.append(word.charAt(0));
}
pinyinSuoxie = builder.toString();
} else {
pinyinSuoxie = "";
}
}
return pinyinSuoxie;
}

/** Verifies the integrity of the necessary fields of this {@code ModelItem}.
* @return {@code true} if all the following conditions are satisfied, otherwise {@code false}:
* 1. Both {@code assetDir} and {@code type} are not {@code null}.
* 2. The {@code AssetAccessor} is available.
* 2. The {@code ModelAssetAccessor} is available.
*/
@JSONField(serialize = false)
public boolean isValid() {
Expand Down Expand Up @@ -127,21 +161,21 @@ public int hashCode() {

@Override
public boolean equals(Object obj) {
if (obj instanceof AssetItem) {
return ((AssetItem)obj).assetDir.equals(assetDir);
if (obj instanceof ModelItem) {
return ((ModelItem)obj).assetDir.equals(assetDir);
}
return false;
}


/** The Asset Accessor providing methods to get the resource files of the asset.
/** The Model Asset Accessor providing methods to get the resource files of the model's asset files.
* @since ArkPets 2.2
*/
public static class AssetAccessor {
public static class ModelAssetAccessor {
private final ArrayList<String> list;
private final HashMap<String, ArrayList<String>> map;

public AssetAccessor(JSONObject fileMap) {
public ModelAssetAccessor(JSONObject fileMap) {
ArrayList<String> list = new ArrayList<>();
HashMap<String, ArrayList<String>> map = new HashMap<>();
try {
Expand Down Expand Up @@ -197,17 +231,17 @@ public boolean isAvailable() {
}


/** The Asset Property Extractor specializing in extracting a specified property.
/** The Model Property Extractor specializing in extracting a specified property.
* @param <T> The type of the specified property, typically {@code String}.
* @since ArkPets 2.2
*/
public interface PropertyExtractor<T> extends Function<AssetItem, Set<T>> {
/** Extracts the specified property of the given Asset Item.
* @param assetItem The given Asset Item.
public interface PropertyExtractor<T> extends Function<ModelItem, Set<T>> {
/** Extracts the specified property of the given Model Item.
* @param modelItem The given Model Item.
* @return A value {@link Set} of the extracted property.
*/
@Override
Set<T> apply(AssetItem assetItem);
Set<T> apply(ModelItem modelItem);

PropertyExtractor<String> ASSET_ITEM_KEY = item -> item.key == null ? Set.of() : Set.of(item.key);
PropertyExtractor<String> ASSET_ITEM_TYPE = item -> item.type == null ? Set.of() : Set.of(item.type);
Expand All @@ -216,7 +250,8 @@ public interface PropertyExtractor<T> extends Function<AssetItem, Set<T>> {
PropertyExtractor<String> ASSET_ITEM_SORT_TAGS = item -> new HashSet<>(item.sortTags.toJavaList(String.class));
}

/** The Asset Prefab storing the user prefab of the specific asset.

/** The Model Prefab storing the user prefab of the specific model.
* @since ArkPets 3.5
*/
public static class AssetPrefab {
Expand Down
Loading

0 comments on commit 1c80ac4

Please sign in to comment.