33import com .fasterxml .jackson .databind .JsonNode ;
44import com .fasterxml .jackson .databind .node .JsonNodeFactory ;
55import com .fasterxml .jackson .databind .node .ObjectNode ;
6+
67import java .util .Map ;
78import java .util .Optional ;
9+
810import lombok .extern .slf4j .Slf4j ;
911import org .springframework .stereotype .Component ;
1012import run .halo .app .plugin .SettingFetcher ;
13+
1114/**
1215 * Live2d 配置处理器
1316 *
@@ -25,36 +28,40 @@ public class Live2dSettingProcess extends JsonNodeFactory implements Live2dSetti
2528
2629 private final ThemeFetcher themeFetcher ;
2730
28- private final Map < String , JsonNode > settingMap ;
31+ private final SettingFetcher settingFetcher ;
2932
3033 private ObjectNode configNode ;
3134
35+ private Map <String , JsonNode > settingMap ;
36+
3237 public Live2dSettingProcess (SettingFetcher settingFetcher ,
3338 ThemeFetcher themeFetcher ) {
34- this .settingMap = settingFetcher . getValues () ;
39+ this .settingFetcher = settingFetcher ;
3540 this .themeFetcher = themeFetcher ;
3641 initConfigNode ();
3742 }
3843
39- public void initConfigNode () {
44+ public ObjectNode initConfigNode () {
45+ this .settingMap = settingFetcher .getValues ();
4046 this .configNode = new ObjectNode (this );
41- this . settingMap .forEach ((group , jsonNode ) -> {
42- JsonNode node = this . settingMap .get (group );
43- if (log .isDebugEnabled ()) {
47+ settingMap .forEach ((group , jsonNode ) -> {
48+ JsonNode node = settingMap .get (group );
49+ if (log .isDebugEnabled ()) {
4450 log .debug ("live2d config -> {} group save settingMap json {}" , group , node .toPrettyString ());
4551 }
4652 if (jsonNode instanceof ObjectNode ) {
47- this . configNode .setAll ((ObjectNode ) node );
53+ configNode .setAll ((ObjectNode ) node );
4854 }
4955 });
5056 // 移除不必要的参数
51- this .configNode .remove ("slots" );
52- setThemeLive2dTipsPath ();
57+ configNode .remove ("slots" );
58+ setThemeLive2dTipsPath (configNode );
59+ return configNode ;
5360 }
5461
55- private void setThemeLive2dTipsPath () {
62+ private void setThemeLive2dTipsPath (ObjectNode configNode ) {
5663 this .themeFetcher .getActiveThemeName ().ifPresent (activeThemeName -> {
57- this . configNode .put ("themeTipsPath" , THEME_TIPS_PATH_TEMPLATE .formatted (activeThemeName ));
64+ configNode .put ("themeTipsPath" , THEME_TIPS_PATH_TEMPLATE .formatted (activeThemeName ));
5865 });
5966 }
6067
@@ -65,9 +72,10 @@ public JsonNode getValue(String groupName, String key) {
6572
6673 @ Override
6774 public Optional <JsonNode > getConfig () {
68- if (log .isDebugEnabled ()) {
69- log .debug ("live2d config -> {}" , configNode .toPrettyString ());
75+ initConfigNode ();
76+ if (log .isDebugEnabled ()) {
77+ log .debug ("live2d config -> {}" , this .configNode .toPrettyString ());
7078 }
71- return Optional .of (configNode );
79+ return Optional .of (this . configNode );
7280 }
7381}
0 commit comments