Skip to content

Commit

Permalink
🐺🚧🚀
Browse files Browse the repository at this point in the history
  • Loading branch information
AmarokIce committed Dec 25, 2024
1 parent 1cc3730 commit e487dd3
Show file tree
Hide file tree
Showing 28 changed files with 434 additions and 124 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,24 @@
package band.kessoku.lib.config;
/*
* Copyright (c) 2024 KessokuTeaTime
*
* Licensed under the GNU Lesser General Pubic License, Version 3 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/lgpl-3.0.html
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package band.kessoku.lib.api.config;

import band.kessoku.lib.api.KessokuLib;
import band.kessoku.lib.api.base.reflect.ModifiersUtil;
import band.kessoku.lib.api.base.reflect.ReflectUtil;
import band.kessoku.lib.config.api.*;
import band.kessoku.lib.api.config.api.*;
import club.someoneice.json.Pair;
import com.google.common.collect.*;
import com.google.common.io.Files;
Expand All @@ -15,12 +30,14 @@
import java.util.*;

/**
* The config handler, also see {@link band.kessoku.lib.config.api.Config Config}. <br>
* The config handler, also see {@link Config Config}. <br>
* The config format or file type determined by config codec.
*
* @see band.kessoku.lib.config.api.Config Config
* @see Config Config
* @see Codec Codec
* @see ConfigBasicCodec Basic Config Codec
*
* @author AmarokIce
*/
public final class ConfigHandler {
private static Path configDir;
Expand Down Expand Up @@ -120,7 +137,7 @@ public static void saveToClass(Class<?> clazz, ConfigHandler cfg, Map<String, Co
public static void scanFields(Class<?> clazz, ConfigHandler cfg) {
ImmutableList.Builder<Field> builder = ImmutableList.builder();
for (Field field : clazz.getDeclaredFields()) {
if (ModifiersUtil.isFinal(field) || !ModifiersUtil.isStatic(field)) {
if (!ModifiersUtil.isStatic(field)) {
continue;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright (c) 2024 KessokuTeaTime
*
* Licensed under the GNU Lesser General Pubic License, Version 3 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/lgpl-3.0.html
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package band.kessoku.lib.api.config;

import org.slf4j.Marker;
import org.slf4j.MarkerFactory;

public class KessokuConfig {
public static final String MOD_ID = "kessoku_config";
public static final String NAME = "Kessoku Config API";
public static final Marker MARKER = MarkerFactory.getMarker("[" + NAME + "]");
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright (c) 2024 KessokuTeaTime
*
* Licensed under the GNU Lesser General Pubic License, Version 3 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/lgpl-3.0.html
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package band.kessoku.lib.api.config.api;

/**
* Category is a sub config builder. Everything same as {@code Config} class. <br>
* Format by father config, allow another category in this category. <br>
* We're suggestion to be every field in category mark {@code static} like config.
*
* @author AmarokIce
*/
public class Category extends ConfigValue<Void> {
protected Category() {
super(null, null);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
package band.kessoku.lib.config.api;
/*
* Copyright (c) 2024 KessokuTeaTime
*
* Licensed under the GNU Lesser General Pubic License, Version 3 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/lgpl-3.0.html
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package band.kessoku.lib.api.config.api;

/**
* {@code Codec} is the key part of data encoding. <br>
Expand All @@ -9,6 +24,8 @@
*
* @see ConfigValue
* @param <T> The type we will encode and decode.
*
* @author AmarokIce
*/
public interface Codec<T> {
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
package band.kessoku.lib.config.api;
package band.kessoku.lib.api.config.api;

/*
* Copyright (c) 2024 KessokuTeaTime
*
* Licensed under the GNU Lesser General Pubic License, Version 3 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/lgpl-3.0.html
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
Expand Down Expand Up @@ -28,6 +43,8 @@
* {@code someoneField = test,}
*
* @see Config @Config
*
* @author AmarokIce
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
package band.kessoku.lib.config.api;
/*
* Copyright (c) 2024 KessokuTeaTime
*
* Licensed under the GNU Lesser General Pubic License, Version 3 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/lgpl-3.0.html
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package band.kessoku.lib.api.config.api;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
Expand All @@ -23,6 +38,8 @@
* @see Comment @Comment
* @see ConfigBasicCodec#register(String, Codec)
* @see ConfigValue
*
* @author AmarokIce
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
package band.kessoku.lib.config.api;
/*
* Copyright (c) 2024 KessokuTeaTime
*
* Licensed under the GNU Lesser General Pubic License, Version 3 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/lgpl-3.0.html
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package band.kessoku.lib.api.config.api;

import club.someoneice.json.JSON;
import club.someoneice.json.Pair;
Expand All @@ -15,6 +30,8 @@
/**
* @see Config @Config
* @see ConfigBasicCodec#register(String, Codec)
*
* @author AmarokIce
*/
public final class ConfigBasicCodec {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
package band.kessoku.lib.config.api;
/*
* Copyright (c) 2024 KessokuTeaTime
*
* Licensed under the GNU Lesser General Pubic License, Version 3 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/lgpl-3.0.html
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package band.kessoku.lib.api.config.api;

import java.util.List;

Expand All @@ -9,6 +24,8 @@
* @param key The key of config field.
* @param rawValue The raw data of config field's value.
* @param comments The comment for config field.
*
* @author AmarokIce
*/
public record ConfigData(String key, String rawValue, List<String> comments) {
@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
package band.kessoku.lib.config.api;
/*
* Copyright (c) 2024 KessokuTeaTime
*
* Licensed under the GNU Lesser General Pubic License, Version 3 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/lgpl-3.0.html
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package band.kessoku.lib.api.config.api;

import band.kessoku.lib.config.ConfigHandler;
import band.kessoku.lib.config.values.*;
import band.kessoku.lib.api.config.ConfigHandler;
import band.kessoku.lib.api.config.values.*;

import java.util.Objects;

Expand All @@ -11,7 +26,9 @@
*
* @see Codec
* @see ConfigValue#ConfigValue(Codec, Object)
* @param <T>
* @param <T> The value should record.
*
* @author AmarokIce
*/
public abstract class ConfigValue<T> {
public final Codec<T> codec;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
package band.kessoku.lib.config.api;
/*
* Copyright (c) 2024 KessokuTeaTime
*
* Licensed under the GNU Lesser General Pubic License, Version 3 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/lgpl-3.0.html
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package band.kessoku.lib.api.config.api;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
Expand Down Expand Up @@ -27,6 +42,8 @@
* {@code someoneField = test,}
*
* @see Config @Config
*
* @author AmarokIce
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* The API for config. It all started in {@link band.kessoku.lib.config.api.Config @Config}.<br>
* The API for config. It all started in {@link band.kessoku.lib.api.config.api.Config @Config}.<br>
* <br>
* {@snippet :
* import band.kessoku.lib.config.api.config.Name;
Expand All @@ -20,4 +20,4 @@
* {@code someoneField = test,}
*
*/
package band.kessoku.lib.config.api;
package band.kessoku.lib.api.config.api;
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright (c) 2024 KessokuTeaTime
*
* Licensed under the GNU Lesser General Pubic License, Version 3 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/lgpl-3.0.html
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* You can use annotations to create a config and save it to any file format you like. <br>
* @see band.kessoku.lib.api.config.api.Config Config
* @see band.kessoku.lib.api.config.api.ConfigValue ConfigValue
*/
package band.kessoku.lib.api.config;
Loading

0 comments on commit e487dd3

Please sign in to comment.