diff --git a/api/src/main/java/ru/dragonestia/msb3/api/Bootstrap.java b/api/src/main/java/ru/dragonestia/msb3/api/Bootstrap.java deleted file mode 100644 index 480d536..0000000 --- a/api/src/main/java/ru/dragonestia/msb3/api/Bootstrap.java +++ /dev/null @@ -1,22 +0,0 @@ -package ru.dragonestia.msb3.api; - -import lombok.extern.log4j.Log4j2; -import net.minestom.server.entity.GameMode; -import ru.dragonestia.msb3.api.module.FlatWorldModule; -import ru.dragonestia.msb3.api.module.MotdModule; -import ru.dragonestia.msb3.api.module.ResourcePackRepositoryModule; - -@Log4j2 -public class Bootstrap { - - public static void main(String[] args) { - var boot = new ServerBootstrap(); - - MotdModule.init("logo.png", "msb3 server"); - FlatWorldModule.init(GameMode.ADVENTURE); - - ResourcePackRepositoryModule.init(boot, "0.0.0.0", 7270); - - boot.start("0.0.0.0", 25565); - } -} diff --git a/api/src/main/java/ru/dragonestia/msb3/api/ServerBootstrap.java b/api/src/main/java/ru/dragonestia/msb3/api/ServerBootstrap.java deleted file mode 100644 index b34d08d..0000000 --- a/api/src/main/java/ru/dragonestia/msb3/api/ServerBootstrap.java +++ /dev/null @@ -1,60 +0,0 @@ -package ru.dragonestia.msb3.api; - -import lombok.Getter; -import lombok.extern.log4j.Log4j2; -import net.minestom.server.MinecraftServer; -import ru.dragonestia.msb3.api.item.ItemPrefabManager; -import ru.dragonestia.msb3.api.item.ItemUtil; -import ru.dragonestia.msb3.api.resource.ResourcePackManager; - -import java.net.InetSocketAddress; - -@Log4j2 -public class ServerBootstrap { - - public static final ClassLoader CLASS_LOADER = ServerBootstrap.class.getClassLoader(); - - private static final String[] LOGO = { - "==============================================", - "Minestom Server Base v3 - by ScarletRedMan", - "", - " 8b d8 .dP\"Y8 88\"\"Yb 88888 ", - " 88b d88 `Ybo.\" 88__dP .dP ", - " 88YbdP88 o.`Y8b 88\"\"Yb o `Yb ", - " 88 YY 88 8bodP' 88oodP YbodP ", - "", - "Minecraft version: " + MinecraftServer.VERSION_NAME + " (protocol: " + MinecraftServer.PROTOCOL_VERSION + ")", - "==============================================", - }; - - @Getter private static ServerBootstrap instance; - @Getter private static boolean started = false; - - private final MinecraftServer server; - @Getter private final ResourcePackManager resourcePackManager; - @Getter private final ItemPrefabManager itemPrefabManager; - - public ServerBootstrap() { - instance = this; - - for (var line: LOGO) log.info(line); - - server = MinecraftServer.init(); - - MinecraftServer.setBrandName("Dragonestia"); - - resourcePackManager = new ResourcePackManager(); - itemPrefabManager = new ItemPrefabManager(); - - init(); - } - - public void start(String address, int port) { - started = true; - server.start(new InetSocketAddress(address, port)); - } - - private void init() { - ItemUtil.init(); - } -} diff --git a/api/src/main/java/ru/dragonestia/msb3/api/boot/DefaultBootstrap.java b/api/src/main/java/ru/dragonestia/msb3/api/boot/DefaultBootstrap.java new file mode 100644 index 0000000..654e421 --- /dev/null +++ b/api/src/main/java/ru/dragonestia/msb3/api/boot/DefaultBootstrap.java @@ -0,0 +1,82 @@ +package ru.dragonestia.msb3.api.boot; + +import lombok.extern.log4j.Log4j2; +import net.minestom.server.MinecraftServer; +import net.minestom.server.entity.GameMode; +import net.minestom.server.event.player.PlayerChatEvent; +import ru.dragonestia.msb3.api.module.FlatWorldModule; +import ru.dragonestia.msb3.api.module.MotdModule; +import ru.dragonestia.msb3.api.module.ResourcePackRepositoryModule; +import ru.dragonestia.msb3.api.resource.dialog.ButtonNumber; +import ru.dragonestia.msb3.api.talk.dialogue.DialogueRenderer; +import ru.dragonestia.msb3.api.talk.dialogue.DialogueTheme; +import team.unnamed.creative.ResourcePack; + +@Log4j2 +public class DefaultBootstrap extends ServerInitializer { + + public static void main(String[] args) { + ServerBootstrap.start("0.0.0.0", 25565, new DefaultBootstrap()); + } + + @Override + public void onDefaultModulesLoaded() { + MotdModule.init("logo.png", "msb3 server"); + FlatWorldModule.init(GameMode.ADVENTURE); + + MinecraftServer.getGlobalEventHandler().addListener(PlayerChatEvent.class, event -> { + var player = event.getPlayer(); + + var render = new DialogueRenderer(player, DialogueTheme.builder().build()); + render.setText(""" + Абсолютно точно. + Я знаю точнo - невозможное возможно + Сойти с ума, влюбиться так неосторoжно + Найти тебя, не отпускать ни днём, ни ночью + Всё невозможное - возможно, знаю точно! + А где тебя искать, прошу ты мне ответь + В какие города мне за тобой лететь + Я готов на край Земли, я всё должен объяснить + Пойми, что без тебя я не умею жить + Я знаю точно - невозможное возможно + Сойти с ума, влюбиться так неосторожно + Найти тебя, не отпускать ни днём, ни ночью + Всё невозможное - возможно, знаю точно! + На-на-на-на (на-на-на-на), а-а, а-а + На-на-на-на (на-на-на-на), а-а, а-а + Всё готов делить, с тобой я пополам + Ты только мне поверь, я сделал выбор сам + Дай же мне последний шанс, я всё должен объяснить + Пойми, что без тебя я не умею жить + Я знаю точно - невозможное возможно + Сойти с ума, влюбиться так неосторожно + Найти тебя, не отпускать ни днём, ни ночью + Всё невозможное - возможно, знаю точно! + На-на-на-на (на-на-на-на), а-а, а-а + На-на-на-на (на-на-на-на), а-а, а-а + Я знаю точно - невозможное возможно + Сойти с ума, влюбиться так неосторожно + Найти тебя, не отпускать ни днём, ни ночью + Всё невозможное - возможно, знаю точно! + На-на-на-на (на-на-на-на), а-а, а-а + На-на-на-на (на-на-на-на), а-а, а-а"""); + + render.setButton(ButtonNumber.BUTTON_1, "Hello world!\nHello world!\nHello world!\nHello world!\nHello world!", ctx -> {}); + render.setButton(ButtonNumber.BUTTON_2, "I am a teapot", ctx -> {}); + render.setButton(ButtonNumber.BUTTON_3, "I love pizza\nMamma mia\nPeperoni\nPapa carlo\nZaebumba\nZaebumba", ctx -> {}); + render.setButton(ButtonNumber.BUTTON_4, "msb3 is top!", ctx -> {}); + + render.show(); + }); + } + + @Override + public void onInitializeResources(ResourcePack resourcePack) { + + } + + @Override + public void onResourcePackCompiled(ResourcePack resourcePack) { + ResourcePackRepositoryModule.init("0.0.0.0", 7270); + } +} diff --git a/api/src/main/java/ru/dragonestia/msb3/api/boot/ServerBootstrap.java b/api/src/main/java/ru/dragonestia/msb3/api/boot/ServerBootstrap.java new file mode 100644 index 0000000..49122cc --- /dev/null +++ b/api/src/main/java/ru/dragonestia/msb3/api/boot/ServerBootstrap.java @@ -0,0 +1,143 @@ +package ru.dragonestia.msb3.api.boot; + +import lombok.Getter; +import lombok.experimental.UtilityClass; +import lombok.extern.log4j.Log4j2; +import net.kyori.adventure.key.Key; +import net.minestom.server.MinecraftServer; +import ru.dragonestia.msb3.api.item.ItemUtil; +import ru.dragonestia.msb3.api.resource.DialogueResources; +import ru.dragonestia.msb3.api.resource.MonologueResources; +import ru.dragonestia.msb3.api.title.BlackScreen; +import ru.dragonestia.msb3.api.util.ResourceFromJar; +import ru.dragonestia.msb3.resource.Resources; +import ru.dragonestia.msb3.resource.glyph.GlyphCharacterFactory; +import ru.dragonestia.msb3.resource.glyph.MinecraftFont; +import ru.dragonestia.msb3.resource.utils.ClassPreLoader; +import team.unnamed.creative.lang.Language; +import team.unnamed.creative.serialize.minecraft.MinecraftResourcePackWriter; + +import java.io.File; +import java.net.InetSocketAddress; +import java.util.HashMap; +import java.util.List; + +@Log4j2 +@UtilityClass +public final class ServerBootstrap { + + public static final ClassLoader CLASS_LOADER = ServerBootstrap.class.getClassLoader(); + + private static final String[] LOGO = { + "==============================================", + "Minestom Server Base v3 - by ScarletRedMan", + "", + " 8b d8 .dP\"Y8 88\"\"Yb 88888 ", + " 88b d88 `Ybo.\" 88__dP .dP ", + " 88YbdP88 o.`Y8b 88\"\"Yb o `Yb ", + " 88 YY 88 8bodP' 88oodP YbodP ", + "", + "Minecraft version: " + MinecraftServer.VERSION_NAME + " (protocol: " + MinecraftServer.PROTOCOL_VERSION + ")", + "==============================================", + }; + + @Getter private boolean started = false; + + private final MinecraftServer server = preInitialize(); + + private MinecraftServer preInitialize() { + for (var line: LOGO) log.info(line); + + var server = MinecraftServer.init(); + MinecraftServer.setBrandName("Dragonestia"); + return server; + } + + public synchronized void start(String address, int port, ServerInitializer initializer) { + if (started) return; + + started = true; + init(initializer); + server.start(new InetSocketAddress(address, port)); + initializer.onServerStarted(); + } + + private void init(ServerInitializer initializer) { + initializer.onLoad(); + + initDefaultModules(); + initializer.onDefaultModulesLoaded(); + + initDefaultGlyphs(); + initializer.onInitializeResources(Resources.getResourcePack()); + + compileResourcePack(); + initializer.onResourcePackCompiled(Resources.getResourcePack()); + } + + private void initDefaultModules() { + ItemUtil.init(); + } + + private void compileResourcePack() { + var resourcePack = Resources.compile(); + + log.info("Used {}/{} glyphs", GlyphCharacterFactory.countUsedChars(), GlyphCharacterFactory.countCharRange()); + + var file = new File("./resource-pack.zip"); + MinecraftResourcePackWriter.minecraft().writeToZipFile(file, resourcePack); + + log.info("Compiled resource pack. File: ./resource-pack.zip"); + } + + private void initDefaultGlyphs() { + ClassPreLoader.preload(BlackScreen.class); + + MonologueResources.registerAvatar(MonologueResources.DEFAULT, ResourceFromJar.of(ServerBootstrap.CLASS_LOADER, "glyphs/monologue/default_avatar.png")); + MonologueResources.registerFrame(MonologueResources.DEFAULT, ResourceFromJar.of(ServerBootstrap.CLASS_LOADER, "glyphs/monologue/avatar_frame.png")); + + DialogueResources.registerAvatar(DialogueResources.DEFAULT, ResourceFromJar.of("glyphs/dialogue/default_avatar.png")); + DialogueResources.registerAvatarFrame(DialogueResources.DEFAULT, ResourceFromJar.of("glyphs/dialogue/avatar_frame.png")); + DialogueResources.registerScrollUp(DialogueResources.DEFAULT, ResourceFromJar.of("glyphs/dialogue/scroll_phrase_up_button.png")); + DialogueResources.registerScrollDown(DialogueResources.DEFAULT, ResourceFromJar.of("glyphs/dialogue/scroll_phrase_down_button.png")); + DialogueResources.registerBackground(DialogueResources.DEFAULT, ResourceFromJar.of("glyphs/dialogue/background.png")); + DialogueResources.registerSubstrate(DialogueResources.DEFAULT, ResourceFromJar.of("glyphs/dialogue/phrase_substrate.png")); + DialogueResources.registerActiveTextField(DialogueResources.DEFAULT, ResourceFromJar.of("glyphs/dialogue/answer_active_text_field.png")); + DialogueResources.registerNotActiveTextField(DialogueResources.DEFAULT, ResourceFromJar.of("glyphs/dialogue/answer_not_active_text_field.png")); + DialogueResources.registerButton(DialogueResources.DEFAULT + 1, ResourceFromJar.of("glyphs/dialogue/answer_button_active_1.png")); + DialogueResources.registerButton(DialogueResources.DEFAULT + 2, ResourceFromJar.of("glyphs/dialogue/answer_button_active_2.png")); + DialogueResources.registerButton(DialogueResources.DEFAULT + 3, ResourceFromJar.of("glyphs/dialogue/answer_button_active_3.png")); + DialogueResources.registerButton(DialogueResources.DEFAULT + 4, ResourceFromJar.of("glyphs/dialogue/answer_button_active_4.png")); + initDialogueFont(); + initLocales(); + } + + private void initDialogueFont() { + MinecraftFont.compileFontProvider(8, -28); + MinecraftFont.compileFontProvider(8, -37); + MinecraftFont.compileFontProvider(8, -46); + MinecraftFont.compileFontProvider(8, -55); + MinecraftFont.compileFontProvider(8, -64); + MinecraftFont.compileFontProvider(8, -73); + MinecraftFont.compileFontProvider(8, -82); + + MinecraftFont.compileFontProvider(8, -122); + MinecraftFont.compileFontProvider(8, -131); + MinecraftFont.compileFontProvider(8, -140); + MinecraftFont.compileFontProvider(8, -149); + + MinecraftFont.compileFontProvider(8, -170); + MinecraftFont.compileFontProvider(8, -179); + MinecraftFont.compileFontProvider(8, -188); + MinecraftFont.compileFontProvider(8, -197); + } + + private void initLocales() { + var locales = new HashMap(); + locales.put("container.inventory", " "); + + for (var lang: List.of("en_us", "ru_ru")) { + Resources.getResourcePack().language(Language.language(Key.key("minecraft", lang), locales)); + } + } +} diff --git a/api/src/main/java/ru/dragonestia/msb3/api/boot/ServerInitializer.java b/api/src/main/java/ru/dragonestia/msb3/api/boot/ServerInitializer.java new file mode 100644 index 0000000..1aaaf5a --- /dev/null +++ b/api/src/main/java/ru/dragonestia/msb3/api/boot/ServerInitializer.java @@ -0,0 +1,42 @@ +package ru.dragonestia.msb3.api.boot; + +import team.unnamed.creative.ResourcePack; + +/** + * Класс инициализатора сервера. Здесь имеются все точки состояний сервера. + * Создан для того чтобы было проще прописывать логику инициализации сервера + */ +public abstract class ServerInitializer { + + /** + * Запускается при самом старте приложения, когда никакая конфигурация сервера еще не подгружена + */ + public void onLoad() {} + + /** + * Запускается после инициализации всех стандартных модулей сервера + */ + public abstract void onDefaultModulesLoaded(); + + /** + * Запускается на стадии подготовки всех ресурсов, которые необходимо скомпилировать и добавить в ресурс-пак. + * + *

Именно на данном этапе необходимо регистрировать глифы. + * @param resourcePack Ресурс-пак + */ + public void onInitializeResources(ResourcePack resourcePack) {} + + /** + * Запускается после того как все пакеты ресурсов были успешно скомпилированы и готовы к последующей упаковке + * и отправке клиенту игрока. + * + *

Сервер в данном состоянии еще не полностью загружен + * @param resourcePack Скомпилированный ресурс-пак + */ + public void onResourcePackCompiled(ResourcePack resourcePack) {} + + /** + * Сервер полностью запущен и доступен для игры + */ + public void onServerStarted() {} +} diff --git a/api/src/main/java/ru/dragonestia/msb3/api/glyph/GlyphConstants.java b/api/src/main/java/ru/dragonestia/msb3/api/glyph/GlyphConstants.java deleted file mode 100644 index 2cfc056..0000000 --- a/api/src/main/java/ru/dragonestia/msb3/api/glyph/GlyphConstants.java +++ /dev/null @@ -1,7 +0,0 @@ -package ru.dragonestia.msb3.api.glyph; - -public final class GlyphConstants { - - public static final int CHEST_GUI_WIDTH = 176; - public static final int DEFAULT_CHAT_WIDTH = 320; -} diff --git a/api/src/main/java/ru/dragonestia/msb3/api/glyph/compile/ArbitraryCharacterFactory.java b/api/src/main/java/ru/dragonestia/msb3/api/glyph/compile/ArbitraryCharacterFactory.java deleted file mode 100644 index d380843..0000000 --- a/api/src/main/java/ru/dragonestia/msb3/api/glyph/compile/ArbitraryCharacterFactory.java +++ /dev/null @@ -1,8 +0,0 @@ -package ru.dragonestia.msb3.api.glyph.compile; - -import org.jetbrains.annotations.NotNull; - -public interface ArbitraryCharacterFactory { - - @NotNull Character nextCharacter() throws IllegalStateException; -} diff --git a/api/src/main/java/ru/dragonestia/msb3/api/glyph/compile/DefaultArbitraryCharacterFactory.java b/api/src/main/java/ru/dragonestia/msb3/api/glyph/compile/DefaultArbitraryCharacterFactory.java deleted file mode 100644 index 8462007..0000000 --- a/api/src/main/java/ru/dragonestia/msb3/api/glyph/compile/DefaultArbitraryCharacterFactory.java +++ /dev/null @@ -1,51 +0,0 @@ -package ru.dragonestia.msb3.api.glyph.compile; - -import org.jetbrains.annotations.NotNull; - -import java.util.Arrays; -import java.util.HashSet; -import java.util.Set; - -public class DefaultArbitraryCharacterFactory implements ArbitraryCharacterFactory { - - private final static Set reservedCharacters = new HashSet<>(); - - static { - for (char c = 'a'; c <= 'z'; c++) reservedCharacters.add(c); - for (char c = 'A'; c <= 'Z'; c++) reservedCharacters.add(c); - for (char c = 'а'; c <= 'я'; c++) reservedCharacters.add(c); - for (char c = 'А'; c <= 'Я'; c++) reservedCharacters.add(c); - for (char c = '0'; c <= '9'; c++) reservedCharacters.add(c); - - reservedCharacters.addAll(Arrays.asList( - '!', '?', ':', '$', - ';', '#', '@', '%', - '^', '&', '*', '(', - ')', '_', '-', '+', - '/', '\\', '№', '"', - '\'', '{', '}', '[', - ']', '~', '`', '<', '>', - ',', '.', '|', '\n', '\r', - '\b', '\f', '\t', ' ', - 'ё', 'Ё', '=') - ); - } - - private char currentChar = '\uA201'; - - @Override - public @NotNull Character nextCharacter() throws IllegalStateException { - if (currentChar == Character.MAX_VALUE) { - throw new IllegalStateException("Characters range exceeded"); - } - - do { - currentChar++; - } while (!isCharacterAllowed(currentChar)); - return currentChar; - } - - private boolean isCharacterAllowed(char c) { - return !reservedCharacters.contains(c); - } -} diff --git a/api/src/main/java/ru/dragonestia/msb3/api/glyph/compile/DefaultGlyphCompiler.java b/api/src/main/java/ru/dragonestia/msb3/api/glyph/compile/DefaultGlyphCompiler.java deleted file mode 100644 index 3bdfe65..0000000 --- a/api/src/main/java/ru/dragonestia/msb3/api/glyph/compile/DefaultGlyphCompiler.java +++ /dev/null @@ -1,45 +0,0 @@ -package ru.dragonestia.msb3.api.glyph.compile; - -import net.kyori.adventure.key.Key; -import org.jetbrains.annotations.NotNull; -import team.unnamed.creative.font.Font; -import team.unnamed.creative.font.FontProvider; -import team.unnamed.creative.part.ResourcePackPart; - -import java.util.*; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -public class DefaultGlyphCompiler implements GlyphCompiler { - - @Override - public @NotNull Collection<@NotNull ResourcePackPart> compile(@NotNull Collection<@NotNull ResourceProducer> producers) { - Set fileResources = new HashSet<>(); - - Set fontKeys = producers - .stream() - .map(ResourceProducer::fontKey) - .collect(Collectors.toUnmodifiableSet()); - - for (Key key : fontKeys) { - List fontProviders = new ArrayList<>(); - ArbitraryCharacterFactory characterFactory = new DefaultArbitraryCharacterFactory(); - for (ResourceProducer producer : producers) { - if (producer.fontKey().equals(key)) { - producer.produceResources(characterFactory); - // Add font providers for current font key - fontProviders.addAll(producer.fontProviders()); - // Add textures to common set with resources - fileResources.addAll(producer.textures()); - } - } - fileResources.add(Font.font(key, fontProviders)); - } - - return fileResources; - } - - Iterable toIterable(final Stream stream) { - return stream::iterator; - } -} diff --git a/api/src/main/java/ru/dragonestia/msb3/api/glyph/compile/GlyphCompiler.java b/api/src/main/java/ru/dragonestia/msb3/api/glyph/compile/GlyphCompiler.java deleted file mode 100644 index 2e95249..0000000 --- a/api/src/main/java/ru/dragonestia/msb3/api/glyph/compile/GlyphCompiler.java +++ /dev/null @@ -1,20 +0,0 @@ -package ru.dragonestia.msb3.api.glyph.compile; - -import org.jetbrains.annotations.NotNull; -import team.unnamed.creative.part.ResourcePackPart; - -import java.util.Arrays; -import java.util.Collection; - -public interface GlyphCompiler { - - static GlyphCompiler instance() { - return new DefaultGlyphCompiler(); - } - - @NotNull Collection<@NotNull ResourcePackPart> compile(@NotNull Collection<@NotNull ResourceProducer> resourceProducerCollection); - - default @NotNull Collection<@NotNull ResourcePackPart> compile(@NotNull ResourceProducer... resourceProducer) { - return compile(Arrays.asList(resourceProducer)); - } -} diff --git a/api/src/main/java/ru/dragonestia/msb3/api/glyph/compile/ResourceProducer.java b/api/src/main/java/ru/dragonestia/msb3/api/glyph/compile/ResourceProducer.java deleted file mode 100644 index ad6d90b..0000000 --- a/api/src/main/java/ru/dragonestia/msb3/api/glyph/compile/ResourceProducer.java +++ /dev/null @@ -1,26 +0,0 @@ -package ru.dragonestia.msb3.api.glyph.compile; - -import net.kyori.adventure.key.Key; -import org.jetbrains.annotations.NotNull; -import ru.dragonestia.msb3.api.glyph.glyph.exception.ResourceAlreadyProducedException; -import ru.dragonestia.msb3.api.glyph.glyph.exception.ResourceNotProducedException; -import team.unnamed.creative.font.FontProvider; -import team.unnamed.creative.texture.Texture; - -import java.util.Collection; -import java.util.Collections; - -public interface ResourceProducer { - - @NotNull Key fontKey(); - - boolean produced(); - - void produceResources(ArbitraryCharacterFactory characterFactory) throws ResourceAlreadyProducedException; - - @NotNull Collection<@NotNull FontProvider> fontProviders() throws ResourceNotProducedException; - - default @NotNull Collection<@NotNull Texture> textures() throws ResourceNotProducedException { - return Collections.emptyList(); - } -} diff --git a/api/src/main/java/ru/dragonestia/msb3/api/glyph/font/GlyphFont.java b/api/src/main/java/ru/dragonestia/msb3/api/glyph/font/GlyphFont.java deleted file mode 100644 index 6657ebd..0000000 --- a/api/src/main/java/ru/dragonestia/msb3/api/glyph/font/GlyphFont.java +++ /dev/null @@ -1,66 +0,0 @@ -package ru.dragonestia.msb3.api.glyph.font; - -import net.kyori.adventure.key.Key; -import org.jetbrains.annotations.NotNull; -import ru.dragonestia.msb3.api.ServerBootstrap; -import ru.dragonestia.msb3.api.glyph.compile.GlyphCompiler; -import ru.dragonestia.msb3.api.glyph.glyph.Glyph; -import ru.dragonestia.msb3.api.glyph.glyph.image.TextureProperties; -import ru.dragonestia.msb3.api.glyph.glyph.image.multicharacter.LanguageGlyphCollection; -import ru.dragonestia.msb3.api.glyph.glyph.space.SpacesGlyphResourceProducer; -import ru.dragonestia.msb3.api.glyph.glyph.space.mojang.MojangSpacesGlyph; -import ru.dragonestia.msb3.api.util.ResourceFromJar; -import team.unnamed.creative.base.Writable; -import team.unnamed.creative.part.ResourcePackPart; -import team.unnamed.creative.texture.Texture; - -import java.util.Collection; -import java.util.List; - -public class GlyphFont { - - public static final SpacesGlyphResourceProducer SPACES = MojangSpacesGlyph.create(); - private static final Key MINECRAFT_FONT_KEY = Key.key(Glyph.DEFAULT_NAMESPACE, "minecraft_font"); - private static final Writable MINECRAFT_FONT_IMAGE_WRITABLE = ResourceFromJar.of(ServerBootstrap.CLASS_LOADER, "glyphs/defaults/minecraft_font.png"); - public static final LanguageGlyphCollection LANGUAGE_GLYPH = minecraftFontGlyphCollection( - MINECRAFT_FONT_KEY, - Key.key(MINECRAFT_FONT_KEY.asString().concat(".png")), - MINECRAFT_FONT_IMAGE_WRITABLE, - List.of(new TextureProperties(12,-6), - new TextureProperties(8,-24), - new TextureProperties(8,8), - new TextureProperties(8,-36))); - - private GlyphFont() {} - - public static Collection compile() { - return GlyphCompiler.instance().compile(SPACES, LANGUAGE_GLYPH); - } - - public static @NotNull LanguageGlyphCollection minecraftFontGlyphCollection(@NotNull Key fontKey, @NotNull Key textureKey, @NotNull List<@NotNull TextureProperties> propertiesList) { - return minecraftFontGlyphCollection(fontKey, textureKey, MINECRAFT_FONT_IMAGE_WRITABLE, propertiesList); - } - - public static @NotNull LanguageGlyphCollection minecraftFontGlyphCollection( - @NotNull Key fontKey, - @NotNull Key textureKey, - @NotNull Writable writable, - @NotNull List<@NotNull TextureProperties> propertiesList - ) { - return LanguageGlyphCollection.of(fontKey, - Texture.texture(textureKey, writable), - propertiesList, - List.of(" АБВГДЕЖЗИК", - "ЛМНОПРСТУФХЦЧШЩЪ", - "ЫЬЭЮЯабвгдежзикл", - "мнопрстуфхцчшщъы", - "ьэюяйЙёЁ ", - "₽!\"#$%&'()*+,-./", - "0123456789: <=>?", - "@ABCDEFGHIJKLMNO", - "PQRSTUVWXYZ[\\]^_", - "`abcdefghijklmno", - "pqrstuvwxyz{|} ") - ); - } -} diff --git a/api/src/main/java/ru/dragonestia/msb3/api/glyph/glyph/AppendableGlyph.java b/api/src/main/java/ru/dragonestia/msb3/api/glyph/glyph/AppendableGlyph.java deleted file mode 100644 index 575546b..0000000 --- a/api/src/main/java/ru/dragonestia/msb3/api/glyph/glyph/AppendableGlyph.java +++ /dev/null @@ -1,3 +0,0 @@ -package ru.dragonestia.msb3.api.glyph.glyph; - -public interface AppendableGlyph extends Glyph {} diff --git a/api/src/main/java/ru/dragonestia/msb3/api/glyph/glyph/EmptyGlyph.java b/api/src/main/java/ru/dragonestia/msb3/api/glyph/glyph/EmptyGlyph.java deleted file mode 100644 index 55b7f45..0000000 --- a/api/src/main/java/ru/dragonestia/msb3/api/glyph/glyph/EmptyGlyph.java +++ /dev/null @@ -1,24 +0,0 @@ -package ru.dragonestia.msb3.api.glyph.glyph; - -import net.kyori.adventure.text.Component; -import org.jetbrains.annotations.NotNull; - -import lombok.AccessLevel; -import lombok.NoArgsConstructor; -import ru.dragonestia.msb3.api.glyph.glyph.exception.ResourceNotProducedException; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class EmptyGlyph implements AppendableGlyph { - - public static final EmptyGlyph INSTANCE = new EmptyGlyph(); - - @Override - public @NotNull Component toAdventure() throws ResourceNotProducedException { - return Component.text(""); - } - - @Override - public int width() { - return 0; - } -} diff --git a/api/src/main/java/ru/dragonestia/msb3/api/glyph/glyph/Glyph.java b/api/src/main/java/ru/dragonestia/msb3/api/glyph/glyph/Glyph.java deleted file mode 100644 index ea4d045..0000000 --- a/api/src/main/java/ru/dragonestia/msb3/api/glyph/glyph/Glyph.java +++ /dev/null @@ -1,21 +0,0 @@ -package ru.dragonestia.msb3.api.glyph.glyph; - -import net.kyori.adventure.key.Key; -import net.kyori.adventure.text.Component; -import org.jetbrains.annotations.NotNull; -import ru.dragonestia.msb3.api.glyph.glyph.exception.ResourceNotProducedException; - -public interface Glyph { - - String DEFAULT_NAMESPACE = "msb3"; - - Key DEFAULT_FONT_KEY = Key.key(DEFAULT_NAMESPACE, "default"); - - Key DEFAULT_SPACES_FONT_KEY = Key.key(DEFAULT_NAMESPACE, "spaces"); - - int SEPARATOR_WIDTH = 1; - - @NotNull Component toAdventure() throws ResourceNotProducedException; - - int width(); -} diff --git a/api/src/main/java/ru/dragonestia/msb3/api/glyph/glyph/GlyphComponentBuilder.java b/api/src/main/java/ru/dragonestia/msb3/api/glyph/glyph/GlyphComponentBuilder.java deleted file mode 100644 index 16d9e96..0000000 --- a/api/src/main/java/ru/dragonestia/msb3/api/glyph/glyph/GlyphComponentBuilder.java +++ /dev/null @@ -1,60 +0,0 @@ -package ru.dragonestia.msb3.api.glyph.glyph; - -import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.format.NamedTextColor; -import org.jetbrains.annotations.NotNull; -import ru.dragonestia.msb3.api.glyph.glyph.space.SpacesGlyphResourceProducer; - -import java.util.List; - -public interface GlyphComponentBuilder { - - static @NotNull GlyphComponentBuilder universal(SpacesGlyphResourceProducer spacesProducer) { - return new GlyphComponentBuilderImpl(spacesProducer, 0, Component.text("")); - } - - static @NotNull GlyphComponentBuilder gui(SpacesGlyphResourceProducer spacesProducer) { - return new GlyphComponentBuilderImpl(spacesProducer, -8, Component.text("", NamedTextColor.WHITE)); - } - - @NotNull GlyphComponentBuilder append(PositionType positionType, int position, @NotNull AppendableGlyph glyph); - - default @NotNull GlyphComponentBuilder append(PositionType positionType, @NotNull AppendableGlyph glyph) { - return append(positionType, 0, glyph); - } - - @NotNull GlyphComponentBuilder append(PositionType positionType, int position, @NotNull List glyphList); - - default @NotNull GlyphComponentBuilder append(PositionType positionType, @NotNull List glyphList) { - return append(positionType, 0, glyphList); - } - - // Append with default position type - - default @NotNull GlyphComponentBuilder append(int position, @NotNull AppendableGlyph glyph) { - return append(PositionType.ABSOLUTE, position, glyph); - } - - default @NotNull GlyphComponentBuilder append(@NotNull AppendableGlyph glyph) { - return append(PositionType.ABSOLUTE, glyph); - } - - default @NotNull GlyphComponentBuilder append(int position, @NotNull List glyphList) { - return append(PositionType.ABSOLUTE, position, glyphList); - } - - default @NotNull GlyphComponentBuilder append(@NotNull List glyphList) { - return append(PositionType.ABSOLUTE, glyphList); - } - - @NotNull Component build(boolean keepInitialPosition); - - default @NotNull Component build() { - return build(true); - } - - enum PositionType { - ABSOLUTE, - RELATIVE - } -} diff --git a/api/src/main/java/ru/dragonestia/msb3/api/glyph/glyph/GlyphComponentBuilderImpl.java b/api/src/main/java/ru/dragonestia/msb3/api/glyph/glyph/GlyphComponentBuilderImpl.java deleted file mode 100644 index ffc0815..0000000 --- a/api/src/main/java/ru/dragonestia/msb3/api/glyph/glyph/GlyphComponentBuilderImpl.java +++ /dev/null @@ -1,86 +0,0 @@ -package ru.dragonestia.msb3.api.glyph.glyph; - -import net.kyori.adventure.text.Component; -import org.jetbrains.annotations.NotNull; - -import lombok.AccessLevel; -import lombok.RequiredArgsConstructor; -import ru.dragonestia.msb3.api.glyph.glyph.space.SpacesGlyphResourceProducer; - -import java.util.ArrayList; -import java.util.List; - -@RequiredArgsConstructor(access = AccessLevel.PACKAGE) -public class GlyphComponentBuilderImpl implements GlyphComponentBuilder { - - private final SpacesGlyphResourceProducer spacesProducer; - private final int initialPosition; - private final Component baseComponent; - - private final List glyphs = new ArrayList<>(); - - private int previousElementsWidth; - - @Override - public @NotNull GlyphComponentBuilder append(PositionType positionType, int position, @NotNull AppendableGlyph glyph) { - if (positionType == PositionType.ABSOLUTE && previousElementsWidth != 0) { - glyphs.add(spacesProducer.translate((-1) * previousElementsWidth)); - previousElementsWidth = 0; - } - - if (position != 0) { - glyphs.add(spacesProducer.translate(position)); - } - - glyphs.add(glyph); - this.previousElementsWidth += position + glyph.width(); - - return this; - } - - @Override - public @NotNull GlyphComponentBuilder append(PositionType positionType, int position, @NotNull List glyphList) { - if (positionType == PositionType.ABSOLUTE && previousElementsWidth != 0) { - glyphs.add(spacesProducer.translate((-1) * previousElementsWidth)); - previousElementsWidth = 0; - } - - if (position != 0) { - glyphs.add(spacesProducer.translate(position)); - } - - int width = 0; - for (AppendableGlyph glyph : glyphList) { - glyphs.add(glyph); - width += glyph.width(); - } - - this.previousElementsWidth += position + width; - - return this; - } - - @Override - public @NotNull Component build(boolean keepInitialPosition) { - if (keepInitialPosition) { - previousElementsWidth += initialPosition; - - // Component should have zero width finally - if (previousElementsWidth != 0) { - glyphs.add(spacesProducer.translate((-1) * previousElementsWidth)); - } - } - - var component = baseComponent; - - if (initialPosition != 0) { - component = component.append(spacesProducer.translate(initialPosition).toAdventure()); - } - - for (Glyph glyph : glyphs) { - component = component.append(glyph.toAdventure()); - } - - return component; - } -} diff --git a/api/src/main/java/ru/dragonestia/msb3/api/glyph/glyph/exception/ResourceAlreadyProducedException.java b/api/src/main/java/ru/dragonestia/msb3/api/glyph/glyph/exception/ResourceAlreadyProducedException.java deleted file mode 100644 index 3fd0416..0000000 --- a/api/src/main/java/ru/dragonestia/msb3/api/glyph/glyph/exception/ResourceAlreadyProducedException.java +++ /dev/null @@ -1,3 +0,0 @@ -package ru.dragonestia.msb3.api.glyph.glyph.exception; - -public class ResourceAlreadyProducedException extends RuntimeException {} diff --git a/api/src/main/java/ru/dragonestia/msb3/api/glyph/glyph/exception/ResourceNotProducedException.java b/api/src/main/java/ru/dragonestia/msb3/api/glyph/glyph/exception/ResourceNotProducedException.java deleted file mode 100644 index 8a66085..0000000 --- a/api/src/main/java/ru/dragonestia/msb3/api/glyph/glyph/exception/ResourceNotProducedException.java +++ /dev/null @@ -1,3 +0,0 @@ -package ru.dragonestia.msb3.api.glyph.glyph.exception; - -public class ResourceNotProducedException extends RuntimeException {} diff --git a/api/src/main/java/ru/dragonestia/msb3/api/glyph/glyph/image/ImageGlyph.java b/api/src/main/java/ru/dragonestia/msb3/api/glyph/glyph/image/ImageGlyph.java deleted file mode 100644 index d224887..0000000 --- a/api/src/main/java/ru/dragonestia/msb3/api/glyph/glyph/image/ImageGlyph.java +++ /dev/null @@ -1,32 +0,0 @@ -package ru.dragonestia.msb3.api.glyph.glyph.image; - -import net.kyori.adventure.key.Key; -import net.kyori.adventure.text.Component; -import org.jetbrains.annotations.NotNull; -import ru.dragonestia.msb3.api.glyph.compile.ResourceProducer; -import ru.dragonestia.msb3.api.glyph.glyph.AppendableGlyph; -import ru.dragonestia.msb3.api.glyph.glyph.Glyph; -import ru.dragonestia.msb3.api.glyph.glyph.exception.ResourceNotProducedException; -import team.unnamed.creative.texture.Texture; - -public interface ImageGlyph extends AppendableGlyph, ResourceProducer { - - static @NotNull ImageGlyph of(@NotNull Key key, - @NotNull Texture texture, - @NotNull TextureProperties properties) { - return new ImageGlyphImpl(key, texture, properties); - } - - static @NotNull ImageGlyph of(@NotNull Texture texture, - @NotNull TextureProperties properties) { - return of(Glyph.DEFAULT_FONT_KEY, texture, properties); - } - - @NotNull Character character() throws ResourceNotProducedException; - - @NotNull Texture texture(); - - default @NotNull Component toAdventure() throws ResourceNotProducedException { - return Component.text(character()).font(fontKey()); - } -} diff --git a/api/src/main/java/ru/dragonestia/msb3/api/glyph/glyph/image/ImageGlyphImpl.java b/api/src/main/java/ru/dragonestia/msb3/api/glyph/glyph/image/ImageGlyphImpl.java deleted file mode 100644 index fd2bdcc..0000000 --- a/api/src/main/java/ru/dragonestia/msb3/api/glyph/glyph/image/ImageGlyphImpl.java +++ /dev/null @@ -1,105 +0,0 @@ -package ru.dragonestia.msb3.api.glyph.glyph.image; - -import net.kyori.adventure.key.Key; -import org.jetbrains.annotations.NotNull; -import ru.dragonestia.msb3.api.glyph.compile.ArbitraryCharacterFactory; -import ru.dragonestia.msb3.api.glyph.glyph.Glyph; -import ru.dragonestia.msb3.api.glyph.glyph.exception.ResourceAlreadyProducedException; -import ru.dragonestia.msb3.api.glyph.glyph.exception.ResourceNotProducedException; -import ru.dragonestia.msb3.api.glyph.util.ImageUtil; -import team.unnamed.creative.font.FontProvider; -import team.unnamed.creative.texture.Texture; - -import lombok.AccessLevel; -import lombok.RequiredArgsConstructor; - -import javax.imageio.ImageIO; -import java.awt.image.BufferedImage; -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.util.Collection; -import java.util.Collections; -import java.util.Set; - -@RequiredArgsConstructor(access = AccessLevel.PACKAGE) -public class ImageGlyphImpl implements ImageGlyph { - - private final Key fontKey; - private final Texture texture; - private final TextureProperties properties; - - private Character character; - private Set fontProviders; - - private int width = -1; - - @Override - public @NotNull Key fontKey() { - return fontKey; - } - - @Override - public boolean produced() { - return fontProviders != null; - } - - @Override - public void produceResources(ArbitraryCharacterFactory characterFactory) throws ResourceAlreadyProducedException { - if (fontProviders != null) { - throw new ResourceAlreadyProducedException(); - } - - var fontProviderBuilder = FontProvider.bitMap(); - - this.character = characterFactory.nextCharacter(); - - fontProviderBuilder.characters(String.valueOf(character)); - fontProviderBuilder.file(texture.key()); - fontProviderBuilder.ascent(properties.ascent()); - fontProviderBuilder.height(properties.height()); - - this.fontProviders = Collections.singleton(fontProviderBuilder.build()); - } - - @Override - public @NotNull Collection<@NotNull FontProvider> fontProviders() throws ResourceNotProducedException { - if (fontProviders == null) { - throw new ResourceNotProducedException(); - } - return fontProviders; - } - - @Override - public @NotNull Collection<@NotNull Texture> textures() throws ResourceNotProducedException { - return Collections.singleton(texture); - } - - @Override - public int width() { - if (width == -1) { - try { - BufferedImage image = ImageIO.read(new ByteArrayInputStream(texture.data().toByteArray())); - int fileHeight = image.getHeight(); - width = (int) Math.ceil( - ((double) properties.height() / (double) fileHeight) - * ImageUtil.calculateWidth(image)) + Glyph.SEPARATOR_WIDTH; - } catch (IOException e) { - e.printStackTrace(); - } - } - return width; - } - - @Override - public @NotNull Character character() throws ResourceNotProducedException { - if (fontProviders == null) { - throw new ResourceNotProducedException(); - } - return character; - } - - @Override - public @NotNull Texture texture() { - return texture; - } -} diff --git a/api/src/main/java/ru/dragonestia/msb3/api/glyph/glyph/image/multicharacter/ColorableGlyph.java b/api/src/main/java/ru/dragonestia/msb3/api/glyph/glyph/image/multicharacter/ColorableGlyph.java deleted file mode 100644 index 55b3ddf..0000000 --- a/api/src/main/java/ru/dragonestia/msb3/api/glyph/glyph/image/multicharacter/ColorableGlyph.java +++ /dev/null @@ -1,11 +0,0 @@ -package ru.dragonestia.msb3.api.glyph.glyph.image.multicharacter; - -import net.kyori.adventure.text.format.TextColor; -import org.jetbrains.annotations.Nullable; - -public interface ColorableGlyph { - - @Nullable TextColor color(); - - void updateColor(@Nullable TextColor color); -} diff --git a/api/src/main/java/ru/dragonestia/msb3/api/glyph/glyph/image/multicharacter/LanguageGlyphCollection.java b/api/src/main/java/ru/dragonestia/msb3/api/glyph/glyph/image/multicharacter/LanguageGlyphCollection.java deleted file mode 100644 index 02ece03..0000000 --- a/api/src/main/java/ru/dragonestia/msb3/api/glyph/glyph/image/multicharacter/LanguageGlyphCollection.java +++ /dev/null @@ -1,45 +0,0 @@ -package ru.dragonestia.msb3.api.glyph.glyph.image.multicharacter; - -import net.kyori.adventure.key.Key; -import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.format.TextColor; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import ru.dragonestia.msb3.api.glyph.compile.ResourceProducer; -import ru.dragonestia.msb3.api.glyph.glyph.AppendableGlyph; -import ru.dragonestia.msb3.api.glyph.glyph.Glyph; -import ru.dragonestia.msb3.api.glyph.glyph.image.TextureProperties; -import team.unnamed.creative.texture.Texture; - -import java.util.List; - -public interface LanguageGlyphCollection extends ResourceProducer { - - static @NotNull LanguageGlyphCollection of(@NotNull Key fontKey, - @NotNull Texture texture, - @NotNull List<@NotNull TextureProperties> propertiesList, - @NotNull List<@NotNull String> charactersMapping) { - return new LanguageGlyphCollectionImpl(fontKey, texture, propertiesList, charactersMapping); - } - - @Deprecated(forRemoval = true) - static @NotNull LanguageGlyphCollection of(@NotNull Texture texture, - @NotNull List<@NotNull TextureProperties> propertiesList, - @NotNull List<@NotNull String> charactersMapping) { - return of(Glyph.DEFAULT_FONT_KEY, texture, propertiesList, charactersMapping); - } - - @NotNull AppendableGlyph translate(int height, int ascent, @NotNull Character character, @Nullable TextColor color) throws IllegalArgumentException; - - @NotNull List<@NotNull AppendableGlyph> translate(int height, int ascent, @NotNull String text, @Nullable TextColor color) throws IllegalArgumentException; - - @NotNull List<@NotNull AppendableGlyph> translate(int height, int ascent, @NotNull Component text) throws IllegalArgumentException; - - default @NotNull AppendableGlyph translate(int height, int ascent, @NotNull Character character) throws IllegalArgumentException { - return translate(height, ascent, character, null); - } - - default @NotNull List<@NotNull AppendableGlyph> translate(int height, int ascent, @NotNull String text) throws IllegalArgumentException { - return translate(height, ascent, text, null); - } -} diff --git a/api/src/main/java/ru/dragonestia/msb3/api/glyph/glyph/image/multicharacter/LanguageGlyphCollectionImpl.java b/api/src/main/java/ru/dragonestia/msb3/api/glyph/glyph/image/multicharacter/LanguageGlyphCollectionImpl.java deleted file mode 100644 index 4cf78ef..0000000 --- a/api/src/main/java/ru/dragonestia/msb3/api/glyph/glyph/image/multicharacter/LanguageGlyphCollectionImpl.java +++ /dev/null @@ -1,108 +0,0 @@ -package ru.dragonestia.msb3.api.glyph.glyph.image.multicharacter; - -import net.kyori.adventure.key.Key; -import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.format.TextColor; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import ru.dragonestia.msb3.api.glyph.compile.ArbitraryCharacterFactory; -import ru.dragonestia.msb3.api.glyph.glyph.AppendableGlyph; -import ru.dragonestia.msb3.api.glyph.glyph.exception.ResourceAlreadyProducedException; -import ru.dragonestia.msb3.api.glyph.glyph.exception.ResourceNotProducedException; -import ru.dragonestia.msb3.api.glyph.glyph.image.TextureProperties; -import ru.dragonestia.msb3.api.glyph.util.KyoriUtil; -import team.unnamed.creative.font.FontProvider; -import team.unnamed.creative.texture.Texture; - -import java.util.*; - -public class LanguageGlyphCollectionImpl implements LanguageGlyphCollection { - - private final Key fontKey; - private final Texture texture; - - private final Map propertiesToMulticharacterMap = new HashMap<>(); - - private Set fontProviders; - - LanguageGlyphCollectionImpl( - Key fontKey, - Texture texture, - List propertiesList, - List charactersMapping - ) { - this.fontKey = fontKey; - this.texture = texture; - - for (TextureProperties properties : propertiesList) { - propertiesToMulticharacterMap.put(properties, MulticharacterImageGlyphCollection.of(fontKey, texture, properties, charactersMapping)); - } - } - - - @Override - public @NotNull Key fontKey() { - return fontKey; - } - - @Override - public boolean produced() { - return fontProviders != null; - } - - @Override - public void produceResources(ArbitraryCharacterFactory characterFactory) throws ResourceAlreadyProducedException { - if (fontProviders != null) { - throw new ResourceAlreadyProducedException(); - } - - fontProviders = new HashSet<>(); - - for (var entry : propertiesToMulticharacterMap.entrySet()) { - entry.getValue().produceResources(characterFactory); - fontProviders.addAll(entry.getValue().fontProviders()); - } - } - - @Override - public @NotNull Collection<@NotNull FontProvider> fontProviders() throws ResourceNotProducedException { - return fontProviders; - } - - @Override - public @NotNull Collection<@NotNull Texture> textures() throws ResourceNotProducedException { - return Collections.singleton(texture); - } - - @Override - public @NotNull AppendableGlyph translate(int height, int ascent, @NotNull Character character, @Nullable TextColor color) throws IllegalArgumentException { - TextureProperties properties = new TextureProperties(height, ascent); - if (!propertiesToMulticharacterMap.containsKey(properties)) { - throw new IllegalArgumentException(); - } - return propertiesToMulticharacterMap.get(properties).translate(character, color); - } - - @Override - public @NotNull List<@NotNull AppendableGlyph> translate(int height, int ascent, @NotNull String text, @Nullable TextColor color) throws IllegalArgumentException { - TextureProperties properties = new TextureProperties(height, ascent); - if (!propertiesToMulticharacterMap.containsKey(properties)) { - throw new IllegalArgumentException(properties.toString()); - } - return propertiesToMulticharacterMap.get(properties).translate(text, color); - } - - public @NotNull List<@NotNull AppendableGlyph> translate(int height, int ascent, @NotNull Component component) throws IllegalArgumentException { - var property = new TextureProperties(height, ascent); - var glyphCollection = Objects.requireNonNull(propertiesToMulticharacterMap.get(property), property.toString()); - - var result = new ArrayList(); - List textAndColors = KyoriUtil.toColoredParts(component); - - for (var parts: textAndColors) { - result.addAll(glyphCollection.translate(parts.text(), parts.color())); - } - - return Collections.unmodifiableList(result); - } -} diff --git a/api/src/main/java/ru/dragonestia/msb3/api/glyph/glyph/image/multicharacter/MulticharacterImageGlyphCollection.java b/api/src/main/java/ru/dragonestia/msb3/api/glyph/glyph/image/multicharacter/MulticharacterImageGlyphCollection.java deleted file mode 100644 index 8e2f8e2..0000000 --- a/api/src/main/java/ru/dragonestia/msb3/api/glyph/glyph/image/multicharacter/MulticharacterImageGlyphCollection.java +++ /dev/null @@ -1,54 +0,0 @@ -package ru.dragonestia.msb3.api.glyph.glyph.image.multicharacter; - -import net.kyori.adventure.key.Key; -import net.kyori.adventure.text.format.TextColor; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import ru.dragonestia.msb3.api.glyph.compile.ResourceProducer; -import ru.dragonestia.msb3.api.glyph.glyph.AppendableGlyph; -import ru.dragonestia.msb3.api.glyph.glyph.Glyph; -import ru.dragonestia.msb3.api.glyph.glyph.image.TextureProperties; -import ru.dragonestia.msb3.api.glyph.glyph.space.SpacesGlyph; -import team.unnamed.creative.texture.Texture; - -import java.util.ArrayList; -import java.util.List; - -public interface MulticharacterImageGlyphCollection extends ResourceProducer { - - static @NotNull MulticharacterImageGlyphCollection of(@NotNull Key fontKey, - @NotNull Texture texture, - @NotNull TextureProperties properties, - @NotNull List<@NotNull String> charactersMapping) { - return new MulticharacterImageGlyphCollectionImpl(fontKey, texture, properties, charactersMapping); - } - - @Deprecated(forRemoval = true) - static @NotNull MulticharacterImageGlyphCollection of(@NotNull Texture texture, - @NotNull TextureProperties properties, - @NotNull List<@NotNull String> charactersMapping) { - return of(Glyph.DEFAULT_FONT_KEY, texture, properties, charactersMapping); - } - - @NotNull AppendableGlyph translate(@NotNull Character character, @Nullable TextColor color) throws IllegalArgumentException; - - default @NotNull List<@NotNull AppendableGlyph> translate(@NotNull String text, @Nullable TextColor color) throws IllegalArgumentException { - List glyphs = new ArrayList<>(); - for (char character : text.toCharArray()) { - if (character == ' ') { - glyphs.add(SpacesGlyph.DEFAULT_SPACE_GLYPH); - } else { - glyphs.add(translate(character, color)); - } - } - return glyphs; - } - - default @NotNull AppendableGlyph translate(@NotNull Character character) throws IllegalArgumentException { - return translate(character, null); - } - - default @NotNull List<@NotNull AppendableGlyph> translate(@NotNull String text) throws IllegalArgumentException { - return translate(text, null); - } -} diff --git a/api/src/main/java/ru/dragonestia/msb3/api/glyph/glyph/image/multicharacter/MulticharacterImageGlyphCollectionImpl.java b/api/src/main/java/ru/dragonestia/msb3/api/glyph/glyph/image/multicharacter/MulticharacterImageGlyphCollectionImpl.java deleted file mode 100644 index b7879b4..0000000 --- a/api/src/main/java/ru/dragonestia/msb3/api/glyph/glyph/image/multicharacter/MulticharacterImageGlyphCollectionImpl.java +++ /dev/null @@ -1,131 +0,0 @@ -package ru.dragonestia.msb3.api.glyph.glyph.image.multicharacter; - -import net.kyori.adventure.key.Key; -import net.kyori.adventure.text.format.TextColor; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import ru.dragonestia.msb3.api.glyph.compile.ArbitraryCharacterFactory; -import ru.dragonestia.msb3.api.glyph.glyph.Glyph; -import ru.dragonestia.msb3.api.glyph.glyph.exception.ResourceAlreadyProducedException; -import ru.dragonestia.msb3.api.glyph.glyph.exception.ResourceNotProducedException; -import ru.dragonestia.msb3.api.glyph.glyph.image.TextureProperties; -import ru.dragonestia.msb3.api.glyph.util.ImageUtil; -import team.unnamed.creative.font.FontProvider; -import team.unnamed.creative.texture.Texture; - -import lombok.AccessLevel; -import lombok.RequiredArgsConstructor; - -import javax.imageio.ImageIO; -import java.awt.image.BufferedImage; -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.util.*; - -@RequiredArgsConstructor(access = AccessLevel.PACKAGE) -public class MulticharacterImageGlyphCollectionImpl implements MulticharacterImageGlyphCollection { - - private final Key fontKey; - private final Texture texture; - private final TextureProperties properties; - private final List charactersMapping; - - private final Map originToArbitraryCharacterMap = new HashMap<>(); - - private Set fontProviders; - - private BufferedImage image; - - @Override - public @NotNull Key fontKey() { - return fontKey; - } - - @Override - public boolean produced() { - return fontProviders != null; - } - - @Override - public void produceResources(ArbitraryCharacterFactory characterFactory) throws ResourceAlreadyProducedException { - if (fontProviders != null) { - throw new ResourceAlreadyProducedException(); - } - - var fontProviderBuilder = FontProvider.bitMap(); - fontProviderBuilder.file(texture.key()); - fontProviderBuilder.ascent(properties.ascent()); - fontProviderBuilder.height(properties.height()); - - List mappingLines = new ArrayList<>(); - - for (String mappingLine : charactersMapping) { - StringBuilder builder = new StringBuilder(); - for (char character : mappingLine.toCharArray()) { - char arbitraryCharacter = characterFactory.nextCharacter(); - originToArbitraryCharacterMap.put(character, arbitraryCharacter); - builder.append(arbitraryCharacter); - } - mappingLines.add(builder.toString()); - } - - fontProviderBuilder.characters(mappingLines); - - this.fontProviders = Collections.singleton(fontProviderBuilder.build()); - } - - @Override - public @NotNull Collection<@NotNull FontProvider> fontProviders() throws ResourceNotProducedException { - return fontProviders; - } - - @Override - public @NotNull Collection<@NotNull Texture> textures() throws ResourceNotProducedException { - return Collections.singleton(texture); - } - - @Override - public @NotNull PreparedImageGlyph translate(@NotNull Character character, @Nullable TextColor color) throws IllegalArgumentException { - if (!originToArbitraryCharacterMap.containsKey(character)) { - throw new IllegalArgumentException(); - } - - int width = 0; - for (int lineIndex = 0; lineIndex < charactersMapping.size(); lineIndex++) { - String line = charactersMapping.get(lineIndex); - for (int characterIndex = 0; characterIndex < line.toCharArray().length; characterIndex++) { - if (line.charAt(characterIndex) == character) { - if (image == null) { - cacheImage(); - } - - if (image == null) { - throw new IllegalArgumentException(); - } - - int filePartWidth = image.getWidth() / charactersMapping.get(0).length(); - int filePartHeight = image.getHeight() / charactersMapping.size(); - - width = (int) Math.ceil( - ((double) properties.height() / (double) filePartHeight) - * ImageUtil.calculateWidth( - image, filePartWidth * characterIndex, filePartHeight * lineIndex, - filePartWidth * (characterIndex + 1), filePartHeight * (lineIndex + 1) - )) + Glyph.SEPARATOR_WIDTH; - break; - } - } - } - - return new PreparedImageGlyph(fontKey, originToArbitraryCharacterMap.get(character), width, color); - } - - private void cacheImage() { - try { - image = ImageIO.read(new ByteArrayInputStream(texture.data().toByteArray())); - } catch (IOException e) { - e.printStackTrace(); - } - } - -} diff --git a/api/src/main/java/ru/dragonestia/msb3/api/glyph/glyph/image/multicharacter/PreparedImageGlyph.java b/api/src/main/java/ru/dragonestia/msb3/api/glyph/glyph/image/multicharacter/PreparedImageGlyph.java deleted file mode 100644 index c8d2d89..0000000 --- a/api/src/main/java/ru/dragonestia/msb3/api/glyph/glyph/image/multicharacter/PreparedImageGlyph.java +++ /dev/null @@ -1,43 +0,0 @@ -package ru.dragonestia.msb3.api.glyph.glyph.image.multicharacter; - -import net.kyori.adventure.key.Key; -import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.format.NamedTextColor; -import net.kyori.adventure.text.format.TextColor; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import lombok.AccessLevel; -import lombok.AllArgsConstructor; -import ru.dragonestia.msb3.api.glyph.glyph.AppendableGlyph; - -@AllArgsConstructor(access = AccessLevel.PACKAGE) -public class PreparedImageGlyph implements AppendableGlyph, ColorableGlyph { - - private final Key key; - private final Character character; - private final int width; - private @Nullable TextColor color; - - @Override - public @NotNull Component toAdventure() { - return Component.text(character) - .font(key) - .color(color == null ? NamedTextColor.BLACK : color); - } - - @Override - public int width() { - return width; - } - - @Override - public @Nullable TextColor color() { - return color; - } - - @Override - public void updateColor(@Nullable TextColor color) { - this.color = color; - } -} diff --git a/api/src/main/java/ru/dragonestia/msb3/api/glyph/glyph/space/AbstractSpacesGlyphResourceProducer.java b/api/src/main/java/ru/dragonestia/msb3/api/glyph/glyph/space/AbstractSpacesGlyphResourceProducer.java deleted file mode 100644 index 1c42e8e..0000000 --- a/api/src/main/java/ru/dragonestia/msb3/api/glyph/glyph/space/AbstractSpacesGlyphResourceProducer.java +++ /dev/null @@ -1,64 +0,0 @@ -package ru.dragonestia.msb3.api.glyph.glyph.space; - -import net.kyori.adventure.key.Key; -import org.jetbrains.annotations.NotNull; - -import lombok.RequiredArgsConstructor; -import ru.dragonestia.msb3.api.glyph.glyph.EmptyGlyph; -import ru.dragonestia.msb3.api.glyph.glyph.Glyph; -import ru.dragonestia.msb3.api.glyph.glyph.exception.ResourceNotProducedException; -import ru.dragonestia.msb3.api.glyph.util.ArrayUtil; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -@RequiredArgsConstructor -public abstract class AbstractSpacesGlyphResourceProducer implements SpacesGlyphResourceProducer { - - private final Key fontKey; - - protected Map mapping; - - @Override - public @NotNull Key fontKey() { - return fontKey; - } - - @Override - public boolean produced() { - return mapping != null; - } - - @Override - public Glyph translate(int length) throws ResourceNotProducedException { - if (mapping == null) { - throw new ResourceNotProducedException(); - } - - if (length == 0) { - return EmptyGlyph.INSTANCE; - } - - int sign = length > 0 ? 1 : -1; - String binaryString = Integer.toBinaryString(Math.abs(length)); - - List characters = new ArrayList<>(); - - int currentRankLength = 1; - for (int index = 0; index < binaryString.length(); index++) { - char digit = binaryString.charAt(binaryString.length() - index - 1); - if (digit == '1') { - int partLength = currentRankLength * sign; - if (!mapping.containsKey(partLength)) { - throw new IllegalArgumentException("Too much length"); - } - characters.add(mapping.get(partLength)); - } - currentRankLength *= 2; - } - - return new SpacesGlyph(fontKey(), ArrayUtil.toCharArray(characters), length); - } - -} diff --git a/api/src/main/java/ru/dragonestia/msb3/api/glyph/glyph/space/DefaultSpaceGlyph.java b/api/src/main/java/ru/dragonestia/msb3/api/glyph/glyph/space/DefaultSpaceGlyph.java deleted file mode 100644 index 4d38585..0000000 --- a/api/src/main/java/ru/dragonestia/msb3/api/glyph/glyph/space/DefaultSpaceGlyph.java +++ /dev/null @@ -1,24 +0,0 @@ -package ru.dragonestia.msb3.api.glyph.glyph.space; - -import net.kyori.adventure.text.Component; -import org.jetbrains.annotations.NotNull; -import ru.dragonestia.msb3.api.glyph.glyph.AppendableGlyph; -import ru.dragonestia.msb3.api.glyph.glyph.exception.ResourceNotProducedException; -import team.unnamed.creative.font.Font; - -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PACKAGE) -public class DefaultSpaceGlyph implements AppendableGlyph { - - @Override - public @NotNull Component toAdventure() throws ResourceNotProducedException { - return Component.text(" ").font(Font.MINECRAFT_DEFAULT); - } - - @Override - public int width() { - return 4; - } -} diff --git a/api/src/main/java/ru/dragonestia/msb3/api/glyph/glyph/space/DefaultSpacesGlyphResourceProducer.java b/api/src/main/java/ru/dragonestia/msb3/api/glyph/glyph/space/DefaultSpacesGlyphResourceProducer.java deleted file mode 100644 index 27fb036..0000000 --- a/api/src/main/java/ru/dragonestia/msb3/api/glyph/glyph/space/DefaultSpacesGlyphResourceProducer.java +++ /dev/null @@ -1,91 +0,0 @@ -package ru.dragonestia.msb3.api.glyph.glyph.space; - -import net.kyori.adventure.key.Key; -import org.jetbrains.annotations.NotNull; -import ru.dragonestia.msb3.api.glyph.compile.ArbitraryCharacterFactory; -import ru.dragonestia.msb3.api.glyph.glyph.exception.ResourceAlreadyProducedException; -import ru.dragonestia.msb3.api.glyph.glyph.exception.ResourceNotProducedException; -import team.unnamed.creative.base.Writable; -import team.unnamed.creative.font.BitMapFontProvider; -import team.unnamed.creative.font.FontProvider; -import team.unnamed.creative.texture.Texture; - -import java.util.*; - -public class DefaultSpacesGlyphResourceProducer extends AbstractSpacesGlyphResourceProducer { - - private final Key textureKey; - private final Writable writable; - - private Set textures; - private Set fontProviders; - - public DefaultSpacesGlyphResourceProducer(Key fontKey, Key textureKey, Writable writable) { - super(fontKey); - this.textureKey = textureKey; - this.writable = writable; - } - - @Override - public boolean produced() { - return textures != null; - } - - @Override - public void produceResources(ArbitraryCharacterFactory characterFactory) { - if (textures != null) { - throw new ResourceAlreadyProducedException(); - } - - this.mapping = new HashMap<>(); - - Set fontProviders = new HashSet<>(); - - for (int length = 1; length <= 2048; length *= 2) { - fontProviders.add(prepareBuilder(characterFactory, length).build()); - fontProviders.add(prepareBuilder(characterFactory, length * (-1)).build()); - } - - this.textures = Collections.singleton(Texture.texture(textureKey, writable)); - this.fontProviders = fontProviders; - } - - @Override - public @NotNull Collection<@NotNull FontProvider> fontProviders() throws ResourceNotProducedException { - if (fontProviders == null) { - throw new ResourceNotProducedException(); - } - return fontProviders; - } - - @Override - public @NotNull Collection<@NotNull Texture> textures() throws ResourceNotProducedException { - if (textures == null) { - throw new ResourceNotProducedException(); - } - return textures; - } - - @NotNull - private BitMapFontProvider.Builder prepareBuilder(ArbitraryCharacterFactory characterFactory, int length) { - var fontProviderBuilder = FontProvider.bitMap(); - - char character = characterFactory.nextCharacter(); - - fontProviderBuilder.characters(String.valueOf(character)); - fontProviderBuilder.file(textureKey); - - if (length > 0) { - fontProviderBuilder.height(length - 1); - fontProviderBuilder.ascent(0); - } else { - fontProviderBuilder.height(length - 2); - fontProviderBuilder.ascent(-32768); - } - - mapping.put(length, character); - - return fontProviderBuilder; - } - -} diff --git a/api/src/main/java/ru/dragonestia/msb3/api/glyph/glyph/space/SpacesGlyph.java b/api/src/main/java/ru/dragonestia/msb3/api/glyph/glyph/space/SpacesGlyph.java deleted file mode 100644 index 5c9fa41..0000000 --- a/api/src/main/java/ru/dragonestia/msb3/api/glyph/glyph/space/SpacesGlyph.java +++ /dev/null @@ -1,40 +0,0 @@ -package ru.dragonestia.msb3.api.glyph.glyph.space; - -import net.kyori.adventure.key.Key; -import net.kyori.adventure.text.Component; -import org.jetbrains.annotations.NotNull; -import ru.dragonestia.msb3.api.glyph.glyph.Glyph; -import team.unnamed.creative.base.Writable; - -import lombok.AccessLevel; -import lombok.RequiredArgsConstructor; - -@RequiredArgsConstructor(access = AccessLevel.PACKAGE) -public class SpacesGlyph implements Glyph { - - private static final Key DEFAULT_SPACE_TEXTURE_KEY = Key.key(Glyph.DEFAULT_NAMESPACE, "space"); - public static final @NotNull DefaultSpaceGlyph DEFAULT_SPACE_GLYPH = new DefaultSpaceGlyph(); - private final Key key; - private final char[] characters; - private final int length; - - public static @NotNull SpacesGlyphResourceProducer create(@NotNull Key fontKey, - @NotNull Key textureKey, - @NotNull Writable spacesWritable) { - return new DefaultSpacesGlyphResourceProducer(fontKey, textureKey, spacesWritable); - } - - public static SpacesGlyphResourceProducer create(@NotNull Writable spacesWritable) { - return create(Glyph.DEFAULT_SPACES_FONT_KEY, DEFAULT_SPACE_TEXTURE_KEY, spacesWritable); - } - - @Override - public @NotNull Component toAdventure() { - return Component.text(new String(characters)).font(key); - } - - @Override - public int width() { - return length; - } -} diff --git a/api/src/main/java/ru/dragonestia/msb3/api/glyph/glyph/space/SpacesGlyphResourceProducer.java b/api/src/main/java/ru/dragonestia/msb3/api/glyph/glyph/space/SpacesGlyphResourceProducer.java deleted file mode 100644 index 9b8ca87..0000000 --- a/api/src/main/java/ru/dragonestia/msb3/api/glyph/glyph/space/SpacesGlyphResourceProducer.java +++ /dev/null @@ -1,10 +0,0 @@ -package ru.dragonestia.msb3.api.glyph.glyph.space; - -import ru.dragonestia.msb3.api.glyph.compile.ResourceProducer; -import ru.dragonestia.msb3.api.glyph.glyph.Glyph; -import ru.dragonestia.msb3.api.glyph.glyph.exception.ResourceNotProducedException; - -public interface SpacesGlyphResourceProducer extends ResourceProducer { - - Glyph translate(int length) throws ResourceNotProducedException; -} diff --git a/api/src/main/java/ru/dragonestia/msb3/api/glyph/glyph/space/mojang/MojangSpacesGlyph.java b/api/src/main/java/ru/dragonestia/msb3/api/glyph/glyph/space/mojang/MojangSpacesGlyph.java deleted file mode 100644 index 1901886..0000000 --- a/api/src/main/java/ru/dragonestia/msb3/api/glyph/glyph/space/mojang/MojangSpacesGlyph.java +++ /dev/null @@ -1,18 +0,0 @@ -package ru.dragonestia.msb3.api.glyph.glyph.space.mojang; - -import net.kyori.adventure.key.Key; -import org.jetbrains.annotations.NotNull; -import ru.dragonestia.msb3.api.glyph.compile.ResourceProducer; -import ru.dragonestia.msb3.api.glyph.glyph.Glyph; -import ru.dragonestia.msb3.api.glyph.glyph.space.SpacesGlyphResourceProducer; - -public interface MojangSpacesGlyph extends Glyph, ResourceProducer { - - static @NotNull SpacesGlyphResourceProducer create(@NotNull Key key) { - return new MojangSpacesGlyphResourceProducer(key); - } - - static SpacesGlyphResourceProducer create() { - return create(Glyph.DEFAULT_SPACES_FONT_KEY); - } -} diff --git a/api/src/main/java/ru/dragonestia/msb3/api/glyph/glyph/space/mojang/MojangSpacesGlyphResourceProducer.java b/api/src/main/java/ru/dragonestia/msb3/api/glyph/glyph/space/mojang/MojangSpacesGlyphResourceProducer.java deleted file mode 100644 index eccef64..0000000 --- a/api/src/main/java/ru/dragonestia/msb3/api/glyph/glyph/space/mojang/MojangSpacesGlyphResourceProducer.java +++ /dev/null @@ -1,60 +0,0 @@ -package ru.dragonestia.msb3.api.glyph.glyph.space.mojang; - -import net.kyori.adventure.key.Key; -import org.jetbrains.annotations.NotNull; -import ru.dragonestia.msb3.api.glyph.compile.ArbitraryCharacterFactory; -import ru.dragonestia.msb3.api.glyph.glyph.exception.ResourceAlreadyProducedException; -import ru.dragonestia.msb3.api.glyph.glyph.exception.ResourceNotProducedException; -import ru.dragonestia.msb3.api.glyph.glyph.space.AbstractSpacesGlyphResourceProducer; -import team.unnamed.creative.font.FontProvider; - -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.Set; - -public class MojangSpacesGlyphResourceProducer extends AbstractSpacesGlyphResourceProducer { - - private Set fontProviders; - - public MojangSpacesGlyphResourceProducer(Key key) { - super(key); - } - - @Override - public boolean produced() { - return fontProviders != null; - } - - @Override - public void produceResources(ArbitraryCharacterFactory characterFactory) { - if (fontProviders != null) { - throw new ResourceAlreadyProducedException(); - } - - mapping = new HashMap<>(); - - var fontProviderBuilder = FontProvider.space(); - - for (int length = 1; length <= 2048; length *= 2) { - fontProviderBuilder.advance(retrieveCharacter(characterFactory, length), length); - fontProviderBuilder.advance(retrieveCharacter(characterFactory, length * (-1)), length * (-1)); - } - - this.fontProviders = Collections.singleton(fontProviderBuilder.build()); - } - - @Override - public @NotNull Collection<@NotNull FontProvider> fontProviders() throws ResourceNotProducedException { - if (fontProviders == null) { - throw new ResourceNotProducedException(); - } - return fontProviders; - } - - private Character retrieveCharacter(ArbitraryCharacterFactory characterFactory, int length) { - char character = characterFactory.nextCharacter(); - mapping.put(length, character); - return character; - } -} diff --git a/api/src/main/java/ru/dragonestia/msb3/api/glyph/pack/DefaultGlyphResourcePack.java b/api/src/main/java/ru/dragonestia/msb3/api/glyph/pack/DefaultGlyphResourcePack.java deleted file mode 100644 index 4cac26b..0000000 --- a/api/src/main/java/ru/dragonestia/msb3/api/glyph/pack/DefaultGlyphResourcePack.java +++ /dev/null @@ -1,63 +0,0 @@ -package ru.dragonestia.msb3.api.glyph.pack; - -import org.jetbrains.annotations.NotNull; - -import lombok.AccessLevel; -import lombok.NoArgsConstructor; -import ru.dragonestia.msb3.api.glyph.compile.GlyphCompiler; -import ru.dragonestia.msb3.api.glyph.compile.ResourceProducer; -import team.unnamed.creative.part.ResourcePackPart; - -import java.util.*; - -@NoArgsConstructor(access = AccessLevel.PROTECTED) -public class DefaultGlyphResourcePack implements GlyphResourcePack { - - private final Map raw = new HashMap<>(); - private final Map compiled = new HashMap<>(); - - private final Set resources = new HashSet<>(); - - @Override - public @NotNull Collection<@NotNull ResourcePackPart> all() { - if (!raw.isEmpty()) { - compileAll(); - } - return resources; - } - - @Override - public void compileAll() { - var resources = GlyphCompiler.instance().compile(raw.values()); - this.resources.addAll(resources); - compiled.putAll(raw); - raw.clear(); - } - - @Override - public @NotNull GlyphResourcePack with(@NotNull ResourceIdentifier<@NotNull T> id, @NotNull T producer) { - if (raw.containsKey(id.key()) || compiled.containsKey(id.key())) { - throw new IllegalArgumentException("Producer with this identifier already registered"); - } - raw.put(id.key(), producer); - return this; - } - - @Override - public @NotNull GlyphResourcePack with(@NotNull ResourcePackPart resource) { - resources.add(resource); - return this; - } - - @Override - public @NotNull T get(@NotNull ResourceIdentifier<@NotNull T> id) throws IllegalArgumentException { - if (!compiled.containsKey(id.key())) { - throw new IllegalArgumentException("Producer with that identifier is not compiled. Provided key: " + id.key()); - } - ResourceProducer producer = compiled.get(id.key()); - if (!id.getType().isAssignableFrom(producer.getClass())) { - throw new IllegalArgumentException("Wrong producer type"); - } - return (T) producer; - } -} diff --git a/api/src/main/java/ru/dragonestia/msb3/api/glyph/pack/GlyphResourcePack.java b/api/src/main/java/ru/dragonestia/msb3/api/glyph/pack/GlyphResourcePack.java deleted file mode 100644 index fd1877f..0000000 --- a/api/src/main/java/ru/dragonestia/msb3/api/glyph/pack/GlyphResourcePack.java +++ /dev/null @@ -1,58 +0,0 @@ -package ru.dragonestia.msb3.api.glyph.pack; - -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; -import ru.dragonestia.msb3.api.glyph.compile.ResourceProducer; -import ru.dragonestia.msb3.api.glyph.glyph.space.SpacesGlyphResourceProducer; -import ru.dragonestia.msb3.api.glyph.glyph.space.mojang.MojangSpacesGlyph; -import team.unnamed.creative.ResourcePack; -import team.unnamed.creative.part.ResourcePackPart; - -import java.util.Collection; - -public interface GlyphResourcePack { - - @NotNull Collection<@NotNull ResourcePackPart> all(); - - void compileAll(); - - @Contract("_, _ -> this") - @NotNull GlyphResourcePack with(@NotNull ResourceIdentifier<@NotNull T> id, @NotNull T producer); - - @Contract("_ -> this") - @NotNull GlyphResourcePack with(@NotNull ResourcePackPart resource); - - @Contract("_ -> this") - default @NotNull GlyphResourcePack with(@NotNull ResourcePackPart... resources) { - for (ResourcePackPart resource : resources) { - with(resource); - } - return this; - } - - @Contract("_ -> this") - default @NotNull GlyphResourcePack with(@NotNull Collection<@NotNull ResourcePackPart> resources) { - resources.forEach(this::with); - return this; - } - - @Contract("-> this") - default @NotNull GlyphResourcePack withMojangSpaces() { - with(ResourceIdentifier.SPACES, MojangSpacesGlyph.create()); - return this; - } - - @NotNull T get(@NotNull ResourceIdentifier<@NotNull T> id) throws IllegalArgumentException; - - default @NotNull SpacesGlyphResourceProducer spaces() { - return get(ResourceIdentifier.SPACES); - } - - default void writeAll(@NotNull ResourcePack resourcePack) { - all().forEach(resourcePack::part); - } - - static @NotNull GlyphResourcePack create() { - return new DefaultGlyphResourcePack(); - } -} diff --git a/api/src/main/java/ru/dragonestia/msb3/api/glyph/pack/ImageResourceIdentifier.java b/api/src/main/java/ru/dragonestia/msb3/api/glyph/pack/ImageResourceIdentifier.java deleted file mode 100644 index bf6a472..0000000 --- a/api/src/main/java/ru/dragonestia/msb3/api/glyph/pack/ImageResourceIdentifier.java +++ /dev/null @@ -1,12 +0,0 @@ -package ru.dragonestia.msb3.api.glyph.pack; - -import org.jetbrains.annotations.NotNull; -import ru.dragonestia.msb3.api.glyph.glyph.image.ImageGlyph; - -public interface ImageResourceIdentifier extends ResourceIdentifier<@NotNull ImageGlyph> { - - @Override - default @NotNull Class<@NotNull ImageGlyph> getType() { - return ImageGlyph.class; - } -} diff --git a/api/src/main/java/ru/dragonestia/msb3/api/glyph/pack/ResourceIdentifier.java b/api/src/main/java/ru/dragonestia/msb3/api/glyph/pack/ResourceIdentifier.java deleted file mode 100644 index 0d8885b..0000000 --- a/api/src/main/java/ru/dragonestia/msb3/api/glyph/pack/ResourceIdentifier.java +++ /dev/null @@ -1,19 +0,0 @@ -package ru.dragonestia.msb3.api.glyph.pack; - -import org.jetbrains.annotations.NotNull; -import ru.dragonestia.msb3.api.glyph.compile.ResourceProducer; -import ru.dragonestia.msb3.api.glyph.glyph.image.multicharacter.LanguageGlyphCollection; -import ru.dragonestia.msb3.api.glyph.glyph.space.SpacesGlyphResourceProducer; - -public interface ResourceIdentifier { - - @NotNull StringIdentifier<@NotNull SpacesGlyphResourceProducer> SPACES = StringIdentifier.of("spaces", SpacesGlyphResourceProducer.class); - - @NotNull StringIdentifier<@NotNull LanguageGlyphCollection> MINECRAFT_FONT = StringIdentifier.of("minecraft_font", LanguageGlyphCollection.class); - - String STRING_IDENTIFIER_NAMESPACE = "glyphs"; - - @NotNull String key(); - - @NotNull Class getType(); -} diff --git a/api/src/main/java/ru/dragonestia/msb3/api/glyph/pack/StringIdentifier.java b/api/src/main/java/ru/dragonestia/msb3/api/glyph/pack/StringIdentifier.java deleted file mode 100644 index 52e8621..0000000 --- a/api/src/main/java/ru/dragonestia/msb3/api/glyph/pack/StringIdentifier.java +++ /dev/null @@ -1,37 +0,0 @@ -package ru.dragonestia.msb3.api.glyph.pack; - -import org.jetbrains.annotations.NotNull; -import ru.dragonestia.msb3.api.glyph.compile.ResourceProducer; -import ru.dragonestia.msb3.api.glyph.glyph.image.ImageGlyph; - -public class StringIdentifier implements ResourceIdentifier { - - private final @NotNull String id; - - private final @NotNull Class type; - - protected StringIdentifier(@NotNull String id, @NotNull Class type) { - this.id = id; - this.type = type; - } - - @Override - public @NotNull Class getType() { - return type; - } - - @Override - public @NotNull String key() { - return id; - } - - public static @NotNull StringIdentifier<@NotNull T> of( - @NotNull String id, - @NotNull Class type) { - return new StringIdentifier<>(id, type); - } - - public static @NotNull StringIdentifier<@NotNull ImageGlyph> image(@NotNull String id) { - return new StringIdentifier<>(id, ImageGlyph.class); - } -} diff --git a/api/src/main/java/ru/dragonestia/msb3/api/glyph/util/ArrayUtil.java b/api/src/main/java/ru/dragonestia/msb3/api/glyph/util/ArrayUtil.java deleted file mode 100644 index f7029b5..0000000 --- a/api/src/main/java/ru/dragonestia/msb3/api/glyph/util/ArrayUtil.java +++ /dev/null @@ -1,19 +0,0 @@ -package ru.dragonestia.msb3.api.glyph.util; - -import org.jetbrains.annotations.NotNull; - -import lombok.experimental.UtilityClass; - -import java.util.List; - -@UtilityClass -public class ArrayUtil { - - public char[] toCharArray(@NotNull List list) { - char[] arr = new char[list.size()]; - for (int i = 0; i < list.size(); i++) { - arr[i] = list.get(i); - } - return arr; - } -} diff --git a/api/src/main/java/ru/dragonestia/msb3/api/glyph/util/ImageUtil.java b/api/src/main/java/ru/dragonestia/msb3/api/glyph/util/ImageUtil.java deleted file mode 100644 index 1bf4c28..0000000 --- a/api/src/main/java/ru/dragonestia/msb3/api/glyph/util/ImageUtil.java +++ /dev/null @@ -1,28 +0,0 @@ -package ru.dragonestia.msb3.api.glyph.util; - -import lombok.experimental.UtilityClass; - -import java.awt.*; -import java.awt.image.BufferedImage; - -@UtilityClass -public class ImageUtil { - - public int calculateWidth(BufferedImage image, int xFrom, int yFrom, int xTo, int yTo) { - int width; - for (width = xTo - 1; width > xFrom; width--) { - for (int height = yFrom; height < yTo; height++) { - if (new Color(image.getRGB(width, height), true) - .getAlpha() == 255) { - return width - xFrom + 1; - } - } - } - - return width - xFrom + 1; - } - - public int calculateWidth(BufferedImage image) { - return calculateWidth(image, 0, 0, image.getWidth(), image.getHeight()); - } -} diff --git a/api/src/main/java/ru/dragonestia/msb3/api/glyph/util/KyoriUtil.java b/api/src/main/java/ru/dragonestia/msb3/api/glyph/util/KyoriUtil.java deleted file mode 100644 index 0bea98b..0000000 --- a/api/src/main/java/ru/dragonestia/msb3/api/glyph/util/KyoriUtil.java +++ /dev/null @@ -1,57 +0,0 @@ -package ru.dragonestia.msb3.api.glyph.util; - -import lombok.experimental.UtilityClass; -import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.flattener.ComponentFlattener; -import net.kyori.adventure.text.flattener.FlattenerListener; -import net.kyori.adventure.text.format.NamedTextColor; -import net.kyori.adventure.text.format.Style; -import net.kyori.adventure.text.format.TextColor; -import org.jetbrains.annotations.NotNull; - -import java.util.ArrayList; -import java.util.Deque; -import java.util.LinkedList; -import java.util.List; - -@UtilityClass -public class KyoriUtil { - - public @NotNull List toColoredParts(@NotNull Component component) { - var listener = new ColoredPartsFlattenerListener(); - ComponentFlattener.basic().flatten(component, listener); - return listener.result(); - } - - public static class ColoredPartsFlattenerListener implements FlattenerListener { - - private final Deque colors = new LinkedList<>(); - private final List result = new ArrayList<>(); - - public void pushStyle(@NotNull Style style) { - var color = style.color(); - if (color != null) colors.add(color); - } - - public void component(@NotNull String text) { - result.add(new ColoredComponentTextPart(text, current())); - } - - public void popStyle(@NotNull Style style) { - var color = style.color(); - if (color != null) colors.removeLast(); - - } - - private TextColor current() { - var color = colors.peekLast(); - return color != null ? color : NamedTextColor.WHITE; - } - - public @NotNull List result() { - return result; - } - - public record ColoredComponentTextPart(String text, TextColor color) {} - } -} diff --git a/api/src/main/java/ru/dragonestia/msb3/api/item/BlankSlotItem.java b/api/src/main/java/ru/dragonestia/msb3/api/item/BlankSlotItem.java index 8c1ada0..0d15c26 100644 --- a/api/src/main/java/ru/dragonestia/msb3/api/item/BlankSlotItem.java +++ b/api/src/main/java/ru/dragonestia/msb3/api/item/BlankSlotItem.java @@ -3,8 +3,7 @@ package ru.dragonestia.msb3.api.item; import net.kyori.adventure.key.Key; import net.minestom.server.item.ItemStack; import net.minestom.server.item.Material; -import ru.dragonestia.msb3.api.ServerBootstrap; -import ru.dragonestia.msb3.api.glyph.glyph.Glyph; +import ru.dragonestia.msb3.api.boot.ServerBootstrap; import ru.dragonestia.msb3.api.util.ResourceFromJar; import team.unnamed.creative.base.Writable; import team.unnamed.creative.model.*; @@ -32,7 +31,7 @@ public class BlankSlotItem { } public static Collection compile() { - var modelKey = Key.key(Glyph.DEFAULT_NAMESPACE, "blank_slot"); + var modelKey = Key.key("msb3", "blank_slot"); var itemKey = Key.key("item/paper"); Model blankSlotModel = Model.model() @@ -52,7 +51,7 @@ public class BlankSlotItem { .overrides(ItemOverride.of(modelKey, ItemPredicate.customModelData(1))) .build(); - Texture texture = Texture.texture(Key.key(Glyph.DEFAULT_NAMESPACE, "blank_slot.png"), BLANK_SLOT_IMAGE_WRITABLE); + Texture texture = Texture.texture(Key.key("msb3", "blank_slot.png"), BLANK_SLOT_IMAGE_WRITABLE); return Arrays.asList(blankSlotModel, paperItemModel, texture); } } diff --git a/api/src/main/java/ru/dragonestia/msb3/api/item/ItemPrefabManager.java b/api/src/main/java/ru/dragonestia/msb3/api/item/ItemPrefabManager.java index 575f2b3..4a5bb7a 100644 --- a/api/src/main/java/ru/dragonestia/msb3/api/item/ItemPrefabManager.java +++ b/api/src/main/java/ru/dragonestia/msb3/api/item/ItemPrefabManager.java @@ -1,7 +1,8 @@ package ru.dragonestia.msb3.api.item; +import lombok.experimental.UtilityClass; import lombok.extern.log4j.Log4j2; -import ru.dragonestia.msb3.api.ServerBootstrap; +import ru.dragonestia.msb3.api.boot.ServerBootstrap; import ru.dragonestia.msb3.api.item.prefab.ItemPrefab; import java.util.HashMap; @@ -9,12 +10,11 @@ import java.util.Map; import java.util.Optional; @Log4j2 +@UtilityClass public final class ItemPrefabManager { private final Map prefabs = new HashMap<>(); - public ItemPrefabManager() {} - public synchronized void register(ItemPrefab prefab) { if (ServerBootstrap.isStarted()) { throw new IllegalStateException("Server is already started"); diff --git a/api/src/main/java/ru/dragonestia/msb3/api/item/prefab/ItemPrefab.java b/api/src/main/java/ru/dragonestia/msb3/api/item/prefab/ItemPrefab.java index 465537d..3ade5f1 100644 --- a/api/src/main/java/ru/dragonestia/msb3/api/item/prefab/ItemPrefab.java +++ b/api/src/main/java/ru/dragonestia/msb3/api/item/prefab/ItemPrefab.java @@ -3,7 +3,7 @@ package ru.dragonestia.msb3.api.item.prefab; import net.kyori.adventure.nbt.BinaryTag; import net.minestom.server.item.ItemStack; import net.minestom.server.tag.Tag; -import ru.dragonestia.msb3.api.ServerBootstrap; +import ru.dragonestia.msb3.api.item.ItemPrefabManager; import java.util.Optional; import java.util.function.Supplier; @@ -22,12 +22,12 @@ public class ItemPrefab { } public static Optional of(String identifier) { - return ServerBootstrap.getInstance().getItemPrefabManager().getPrefab(identifier); + return ItemPrefabManager.getPrefab(identifier); } public static Optional of(ItemStack item) { if (item == null || item.hasTag(TAG_IDENTIFIER)) return Optional.empty(); - return ServerBootstrap.getInstance().getItemPrefabManager().getPrefab(item.getTag(TAG_IDENTIFIER)); + return ItemPrefabManager.getPrefab(item.getTag(TAG_IDENTIFIER)); } public final String getIdentifier() { diff --git a/api/src/main/java/ru/dragonestia/msb3/api/module/ResourcePackRepositoryModule.java b/api/src/main/java/ru/dragonestia/msb3/api/module/ResourcePackRepositoryModule.java index 43559c5..38792a3 100644 --- a/api/src/main/java/ru/dragonestia/msb3/api/module/ResourcePackRepositoryModule.java +++ b/api/src/main/java/ru/dragonestia/msb3/api/module/ResourcePackRepositoryModule.java @@ -1,13 +1,13 @@ package ru.dragonestia.msb3.api.module; import lombok.SneakyThrows; +import lombok.experimental.UtilityClass; import net.kyori.adventure.resource.ResourcePackCallback; import net.kyori.adventure.resource.ResourcePackInfo; import net.kyori.adventure.resource.ResourcePackRequest; import net.kyori.adventure.text.Component; import net.minestom.server.MinecraftServer; import net.minestom.server.event.player.PlayerSpawnEvent; -import ru.dragonestia.msb3.api.ServerBootstrap; import team.unnamed.creative.BuiltResourcePack; import team.unnamed.creative.base.Writable; import team.unnamed.creative.server.ResourcePackServer; @@ -22,19 +22,16 @@ import java.util.UUID; import static net.kyori.adventure.text.format.NamedTextColor.RED; +@UtilityClass public class ResourcePackRepositoryModule { - private static boolean used = false; - - private ResourcePackRepositoryModule() {} + private boolean used = false; @SneakyThrows - public static synchronized void init(ServerBootstrap bootstrap, String address, int port) { + public synchronized void init(String address, int port) { if (used) return; used = true; - bootstrap.getResourcePackManager().compile(); - var file = new File("./resource-pack.zip"); var hash = calculateHash(file); var uuid = UUID.randomUUID(); @@ -59,7 +56,7 @@ public class ResourcePackRepositoryModule { } @SneakyThrows - private static String calculateHash(File file) { + private String calculateHash(File file) { MessageDigest digest = MessageDigest.getInstance("SHA-1"); try (InputStream fis = new FileInputStream(file)) { @@ -68,7 +65,7 @@ public class ResourcePackRepositoryModule { } } - private static String byteArray2Hex(final byte[] hash) { + private String byteArray2Hex(final byte[] hash) { Formatter formatter = new Formatter(); for (byte b: hash) formatter.format("%02x", b); return formatter.toString(); diff --git a/api/src/main/java/ru/dragonestia/msb3/api/resource/DialogueResources.java b/api/src/main/java/ru/dragonestia/msb3/api/resource/DialogueResources.java index 3033a7d..b150c62 100644 --- a/api/src/main/java/ru/dragonestia/msb3/api/resource/DialogueResources.java +++ b/api/src/main/java/ru/dragonestia/msb3/api/resource/DialogueResources.java @@ -1,21 +1,12 @@ package ru.dragonestia.msb3.api.resource; +import lombok.experimental.UtilityClass; import net.kyori.adventure.key.Key; -import ru.dragonestia.msb3.api.glyph.font.GlyphFont; -import ru.dragonestia.msb3.api.glyph.glyph.image.ImageGlyph; -import ru.dragonestia.msb3.api.glyph.glyph.image.TextureProperties; -import ru.dragonestia.msb3.api.glyph.glyph.image.multicharacter.LanguageGlyphCollection; -import ru.dragonestia.msb3.api.glyph.pack.GlyphResourcePack; -import ru.dragonestia.msb3.api.glyph.pack.StringIdentifier; -import ru.dragonestia.msb3.api.resource.dialog.Background; -import ru.dragonestia.msb3.api.resource.dialog.Button; -import ru.dragonestia.msb3.api.resource.dialog.Substrate; -import ru.dragonestia.msb3.api.resource.dialog.TextField; -import ru.dragonestia.msb3.api.talk.dialogue.DialogGlyphPositions; -import ru.dragonestia.msb3.api.util.ImageUtil; -import ru.dragonestia.msb3.api.util.ResourceFromJar; +import ru.dragonestia.msb3.api.resource.dialog.*; +import ru.dragonestia.msb3.resource.Resources; +import ru.dragonestia.msb3.resource.glyph.GlyphImage; +import ru.dragonestia.msb3.resource.utils.ImageUtils; import team.unnamed.creative.base.Writable; -import team.unnamed.creative.texture.Texture; import javax.imageio.ImageIO; import java.awt.image.BufferedImage; @@ -24,95 +15,59 @@ import java.io.IOException; import java.util.HashMap; import java.util.Map; import java.util.Optional; -import java.util.stream.IntStream; -import java.util.stream.Stream; +@UtilityClass public class DialogueResources { - private static final Key DIALOGUE_FONT_KEY = Key.key("msb3", "dialog"); public static final String DEFAULT = "default"; - private final GlyphResourcePack glyphResourcePack; - private final Map avatars = new HashMap<>(); - private final Map avatarFrames = new HashMap<>(); - private final Map scrollUp = new HashMap<>(); - private final Map scrollDown = new HashMap<>(); + private final Map avatars = new HashMap<>(); + private final Map avatarFrames = new HashMap<>(); + private final Map scrollUp = new HashMap<>(); + private final Map scrollDown = new HashMap<>(); private final Map backgrounds = new HashMap<>(); private final Map substrates = new HashMap<>(); - private final Map fonts = new HashMap<>(); private final Map buttons = new HashMap<>(); private final Map activeFields = new HashMap<>(); private final Map notActiveFields = new HashMap<>(); - public DialogueResources(GlyphResourcePack glyphResourcePack) { - this.glyphResourcePack = glyphResourcePack; - - registerAvatar(DEFAULT, ResourceFromJar.of("glyphs/dialogue/default_avatar.png")); - registerAvatarFrame(DEFAULT, ResourceFromJar.of("glyphs/dialogue/avatar_frame.png")); - registerScrollTextUp(DEFAULT, ResourceFromJar.of("glyphs/dialogue/scroll_phrase_up_button.png")); - registerScrollTextDown(DEFAULT, ResourceFromJar.of("glyphs/dialogue/scroll_phrase_down_button.png")); - registerBackground(DEFAULT, ResourceFromJar.of("glyphs/dialogue/background.png")); - registerSubstrate(DEFAULT, ResourceFromJar.of("glyphs/dialogue/phrase_substrate.png")); - registerActiveTextField(DEFAULT, ResourceFromJar.of("glyphs/dialogue/answer_active_text_field.png")); - registerNotActiveTextField(DEFAULT, ResourceFromJar.of("glyphs/dialogue/answer_not_active_text_field.png")); - registerButton(DEFAULT + 1, ResourceFromJar.of("glyphs/dialogue/answer_button_active_1.png")); - registerButton(DEFAULT + 2, ResourceFromJar.of("glyphs/dialogue/answer_button_active_2.png")); - registerButton(DEFAULT + 3, ResourceFromJar.of("glyphs/dialogue/answer_button_active_3.png")); - registerButton(DEFAULT + 4, ResourceFromJar.of("glyphs/dialogue/answer_button_active_4.png")); - registerFont(DEFAULT, ResourceFromJar.of("glyphs/defaults/minecraft_font.png")); - } - - public void compile(GlyphResourcePack resourcePack) {} - public void registerAvatar(String identifier, Writable writable) { - registerAvatar(identifier, writable, DialogGlyphPositions.DEFAULT); - } - - public void registerAvatar(String identifier, Writable writable, DialogGlyphPositions positions) { - var glyph = createGlyph(identifier, writable, "avatar", positions.avatar().height(), positions.avatar().y()); - var glyphIdentifier = StringIdentifier.image("dialog_avatar__" + identifier); - avatars.put(identifier, new GlyphEntry(glyphIdentifier, glyph)); - glyphResourcePack.with(glyphIdentifier, glyph); + avatars.put(identifier, Resources.createGlyph( + Key.key("msb3", "dialogue/avatar/" + identifier), + writable, + GlyphPositions.avatar.height(), + GlyphPositions.avatar.y() + )); } public void registerAvatarFrame(String identifier, Writable writable) { - registerAvatarFrame(identifier, writable, DialogGlyphPositions.DEFAULT); + avatarFrames.put(identifier, Resources.createGlyph( + Key.key("msb3", "dialogue/avatar_frame/" + identifier), + writable, + GlyphPositions.avatar.frameHeight(), + GlyphPositions.avatar.y() + GlyphPositions.avatar.frameBorderSize() + )); } - public void registerAvatarFrame(String identifier, Writable writable, DialogGlyphPositions positions) { - var glyph = createGlyph(identifier, writable, "avatar_frame", positions.avatar().frameHeight(), positions.avatar().y() + positions.avatar().frameBorderSize()); - var glyphIdentifier = StringIdentifier.image("dialog_avatar_frame__" + identifier); - avatarFrames.put(identifier, new GlyphEntry(glyphIdentifier, glyph)); - glyphResourcePack.with(glyphIdentifier, glyph); + public void registerScrollUp(String identifier, Writable writable) { + scrollUp.put(identifier, Resources.createGlyph( + Key.key("msb3", "dialogue/scroll_up/" + identifier), + writable, + GlyphPositions.scrollPhraseButton.height(), + GlyphPositions.scrollPhraseButton.buttonY() + )); } - public void registerScrollTextUp(String identifier, Writable writable) { - registerScrollTextUp(identifier, writable, DialogGlyphPositions.DEFAULT); - } - - public void registerScrollTextUp(String identifier, Writable writable, DialogGlyphPositions positions) { - var glyph = createGlyph(identifier, writable, "scroll_up", positions.scrollPhraseButton().height(), positions.scrollPhraseButton().buttonY()); - var glyphIdentifier = StringIdentifier.image("dialog_scroll_up__" + identifier); - scrollUp.put(identifier, new GlyphEntry(glyphIdentifier, glyph)); - glyphResourcePack.with(glyphIdentifier, glyph); - } - - public void registerScrollTextDown(String identifier, Writable writable) { - registerScrollTextDown(identifier, writable, DialogGlyphPositions.DEFAULT); - } - - public void registerScrollTextDown(String identifier, Writable writable, DialogGlyphPositions positions) { - var glyph = createGlyph(identifier, writable, "scroll_down", positions.scrollPhraseButton().height(), positions.scrollPhraseButton().buttonY()); - var glyphIdentifier = StringIdentifier.image("dialog_scroll_down__" + identifier); - scrollDown.put(identifier, new GlyphEntry(glyphIdentifier, glyph)); - glyphResourcePack.with(glyphIdentifier, glyph); + public void registerScrollDown(String identifier, Writable writable) { + scrollDown.put(identifier, Resources.createGlyph( + Key.key("msb3", "dialogue/scroll_down/" + identifier), + writable, + GlyphPositions.scrollPhraseButton.height(), + GlyphPositions.scrollPhraseButton.buttonY() + )); } public void registerBackground(String identifier, Writable writable) { - registerBackground(identifier, writable, DialogGlyphPositions.DEFAULT); - } - - public void registerBackground(String identifier, Writable writable, DialogGlyphPositions positions) { BufferedImage image; Writable part1; Writable part2; @@ -124,43 +79,43 @@ public class DialogueResources { var w = image.getWidth(); var h = image.getHeight(); - part1 = ImageUtil.imageToWritable(image.getSubimage(0, 0, w / 2, h / 2)); - part2 = ImageUtil.imageToWritable(image.getSubimage(w / 2, 0, w / 2, h / 2)); - part3 = ImageUtil.imageToWritable(image.getSubimage(0, h / 2, w / 2, h / 2)); - part4 = ImageUtil.imageToWritable(image.getSubimage(w / 2, h / 2, w / 2, h / 2)); + part1 = ImageUtils.imageToWritable(image.getSubimage(0, 0, w / 2, h / 2)); + part2 = ImageUtils.imageToWritable(image.getSubimage(w / 2, 0, w / 2, h / 2)); + part3 = ImageUtils.imageToWritable(image.getSubimage(0, h / 2, w / 2, h / 2)); + part4 = ImageUtils.imageToWritable(image.getSubimage(w / 2, h / 2, w / 2, h / 2)); } catch (IOException ex) { throw new RuntimeException(ex); } - var glyph1 = new GlyphEntry( - StringIdentifier.image("dialog_background1__" + identifier), - createGlyph(identifier, part1, "background1", positions.guiBackground().height() / 2, positions.guiBackground().topPartsY()) + var glyph1 = Resources.createGlyph( + Key.key("msb3", "dialogue/background/" + identifier + "__1"), + part1, + GlyphPositions.guiBackground.height() / 2, + GlyphPositions.guiBackground.topPartsY() ); - var glyph2 = new GlyphEntry( - StringIdentifier.image("dialog_background2__" + identifier), - createGlyph(identifier, part2, "background2", positions.guiBackground().height() / 2, positions.guiBackground().topPartsY()) + var glyph2 = Resources.createGlyph( + Key.key("msb3", "dialogue/background/" + identifier + "__2"), + part2, + GlyphPositions.guiBackground.height() / 2, + GlyphPositions.guiBackground.topPartsY() ); - var glyph3 = new GlyphEntry( - StringIdentifier.image("dialog_background3__" + identifier), - createGlyph(identifier, part3, "background3", positions.guiBackground().height() / 2, positions.guiBackground().bottomPartsY()) + var glyph3 = Resources.createGlyph( + Key.key("msb3", "dialogue/background/" + identifier + "__3"), + part3, + GlyphPositions.guiBackground.height() / 2, + GlyphPositions.guiBackground.bottomPartsY() ); - var glyph4 = new GlyphEntry( - StringIdentifier.image("dialog_background4__" + identifier), - createGlyph(identifier, part4, "background4", positions.guiBackground().height() / 2, positions.guiBackground().bottomPartsY()) + var glyph4 = Resources.createGlyph( + Key.key("msb3", "dialogue/background/" + identifier + "__4"), + part4, + GlyphPositions.guiBackground.height() / 2, + GlyphPositions.guiBackground.bottomPartsY() ); - backgrounds.put(identifier, new Background(glyph1.glyph(), glyph2.glyph(), glyph3.glyph(), glyph4.glyph())); - glyphResourcePack.with(glyph1.identifier(), glyph1.glyph()); - glyphResourcePack.with(glyph2.identifier(), glyph2.glyph()); - glyphResourcePack.with(glyph3.identifier(), glyph3.glyph()); - glyphResourcePack.with(glyph4.identifier(), glyph4.glyph()); + backgrounds.put(identifier, new Background(glyph1, glyph2, glyph3, glyph4)); } public void registerSubstrate(String identifier, Writable writable) { - registerSubstrate(identifier, writable, DialogGlyphPositions.DEFAULT); - } - - public void registerSubstrate(String identifier, Writable writable, DialogGlyphPositions positions) { BufferedImage image; Writable part1; Writable part2; @@ -170,168 +125,129 @@ public class DialogueResources { var w = image.getWidth(); var h = image.getHeight(); - part1 = ImageUtil.imageToWritable(image.getSubimage(0, 0, w / 2, h)); - part2 = ImageUtil.imageToWritable(image.getSubimage(w / 2, 0, w / 2, h)); + part1 = ImageUtils.imageToWritable(image.getSubimage(0, 0, w / 2, h)); + part2 = ImageUtils.imageToWritable(image.getSubimage(w / 2, 0, w / 2, h)); } catch (IOException ex) { throw new RuntimeException(ex); } - var glyph1 = new GlyphEntry( - StringIdentifier.image("dialog_substrate1__" + identifier), - createGlyph(identifier, part1, "substrate1", positions.phraseSubstrate().height(), positions.phraseSubstrate().y()) + var glyph1 = Resources.createGlyph( + Key.key("msb3", "dialogue/substrate/" + identifier + "__1"), + part1, + GlyphPositions.phraseSubstrate.height(), + GlyphPositions.phraseSubstrate.y() ); - var glyph2 = new GlyphEntry( - StringIdentifier.image("dialog_substrate2__" + identifier), - createGlyph(identifier, part2, "substrate2", positions.phraseSubstrate().height(), positions.phraseSubstrate().y()) + var glyph2 = Resources.createGlyph( + Key.key("msb3", "dialogue/substrate/" + identifier + "__2"), + part2, + GlyphPositions.phraseSubstrate.height(), + GlyphPositions.phraseSubstrate.y() ); - substrates.put(identifier, new Substrate(glyph1.glyph(), glyph2.glyph())); - glyphResourcePack.with(glyph1.identifier(), glyph1.glyph()); - glyphResourcePack.with(glyph2.identifier(), glyph2.glyph()); - } - - public void registerFont(String identifier, Writable writable) { - registerFont(identifier, writable, DialogGlyphPositions.DEFAULT); - } - - public void registerFont(String identifier, Writable writable, DialogGlyphPositions positions) { - var propertiesList = Stream.concat(Stream.concat(IntStream.range(0, positions.phraseText().maxLines()).map((idx) -> { - return idx * (positions.phraseText().fontHeight() + 1) + positions.phraseText().firstLineAscent() * -1; - }).boxed().map((ascent) -> { - return new TextureProperties(positions.phraseText().fontHeight(), ascent * -1); - }), IntStream.range(0, positions.answerText().maxLines()).map((idx) -> { - return idx * (positions.answerText().fontHeight() + 1) + positions.answerText().topFirstLineAscent() * -1; - }).boxed().map((ascent) -> { - return new TextureProperties(positions.answerText().fontHeight(), ascent * -1); - })), IntStream.range(0, positions.answerText().maxLines()).map((idx) -> { - return idx * (positions.answerText().fontHeight() + 1) + positions.answerText().bottomFirstLineAscent() * -1; - }).boxed().map((ascent) -> { - return new TextureProperties(positions.answerText().fontHeight(), ascent * -1); - })).toList(); - - var glyphIdentifier = StringIdentifier.of("dialog_font", LanguageGlyphCollection.class); - var font = GlyphFont.minecraftFontGlyphCollection(DIALOGUE_FONT_KEY, Key.key("dialog/font.png"), writable, propertiesList); - - fonts.put(identifier, new FontGlyphEntry(glyphIdentifier, font)); - glyphResourcePack.with(glyphIdentifier, font); + substrates.put(identifier, new Substrate(glyph1, glyph2)); } public void registerButton(String identifier, Writable writable) { - registerButton(identifier, writable, DialogGlyphPositions.DEFAULT); - } - - public void registerButton(String identifier, Writable writable, DialogGlyphPositions positions) { - var glyph1 = createGlyph(identifier, + var glyph1 = Resources.createGlyph( + Key.key("msb3", "dialogue/button/" + identifier), writable, - "button1", - positions.answerButton().height(), - positions.answerButton().topButtonY()); - var glyph2 = createGlyph(identifier, + GlyphPositions.answerButton.height(), + GlyphPositions.answerButton.topButtonY() + ); + var glyph2 = Resources.createGlyph( + Key.key("msb3", "dialogue/button/" + identifier), writable, - "button2", - positions.answerButton().height(), - positions.answerButton().topButtonY()); - var glyph3 = createGlyph(identifier, + GlyphPositions.answerButton.height(), + GlyphPositions.answerButton.topButtonY() + ); + var glyph3 = Resources.createGlyph( + Key.key("msb3", "dialogue/button/" + identifier), writable, - "button3", - positions.answerButton().height(), - positions.answerButton().bottomButtonY()); - var glyph4 = createGlyph(identifier, + GlyphPositions.answerButton.height(), + GlyphPositions.answerButton.bottomButtonY() + ); + var glyph4 = Resources.createGlyph( + Key.key("msb3", "dialogue/button/" + identifier), writable, - "button4", - positions.answerButton().height(), - positions.answerButton().bottomButtonY()); + GlyphPositions.answerButton.height(), + GlyphPositions.answerButton.bottomButtonY() + ); buttons.put(identifier, new Button(glyph1, glyph2, glyph3, glyph4)); - glyphResourcePack - .with(StringIdentifier.image("dialog_button1__" + identifier), glyph1) - .with(StringIdentifier.image("dialog_button2__" + identifier), glyph2) - .with(StringIdentifier.image("dialog_button3__" + identifier), glyph3) - .with(StringIdentifier.image("dialog_button4__" + identifier), glyph4); } public void registerActiveTextField(String identifier, Writable writable) { - registerActiveTextField(identifier, writable, DialogGlyphPositions.DEFAULT); - } - - public void registerActiveTextField(String identifier, Writable writable, DialogGlyphPositions positions) { - var glyph1 = createGlyph(identifier, + var glyph1 = Resources.createGlyph( + Key.key("msb3", "dialogue/text_field/" + identifier), writable, - "active_field1", - positions.answerField().height(), - positions.answerField().topFieldY()); - var glyph2 = createGlyph(identifier, + GlyphPositions.answerField.height(), + GlyphPositions.answerField.topFieldY() + ); + var glyph2 = Resources.createGlyph( + Key.key("msb3", "dialogue/text_field/" + identifier), writable, - "active_field2", - positions.answerField().height(), - positions.answerField().topFieldY()); - var glyph3 = createGlyph(identifier, + GlyphPositions.answerField.height(), + GlyphPositions.answerField.topFieldY() + ); + var glyph3 = Resources.createGlyph( + Key.key("msb3", "dialogue/text_field/" + identifier), writable, - "active_field3", - positions.answerField().height(), - positions.answerField().bottomFieldY()); - var glyph4 = createGlyph(identifier, + GlyphPositions.answerField.height(), + GlyphPositions.answerField.bottomFieldY() + ); + var glyph4 = Resources.createGlyph( + Key.key("msb3", "dialogue/text_field/" + identifier), writable, - "active_field4", - positions.answerField().height(), - positions.answerField().bottomFieldY()); + GlyphPositions.answerField.height(), + GlyphPositions.answerField.bottomFieldY() + ); activeFields.put(identifier, new TextField(glyph1, glyph2, glyph3, glyph4)); - glyphResourcePack - .with(StringIdentifier.image("active_field1__" + identifier), glyph1) - .with(StringIdentifier.image("active_field2__" + identifier), glyph2) - .with(StringIdentifier.image("active_field3__" + identifier), glyph3) - .with(StringIdentifier.image("active_field4__" + identifier), glyph4); } public void registerNotActiveTextField(String identifier, Writable writable) { - registerNotActiveTextField(identifier, writable, DialogGlyphPositions.DEFAULT); - } - - public void registerNotActiveTextField(String identifier, Writable writable, DialogGlyphPositions positions) { - var glyph1 = createGlyph(identifier, + var glyph1 = Resources.createGlyph( + Key.key("msb3", "dialogue/inactive_text_field/" + identifier), writable, - "not_active_field1", - positions.answerField().height(), - positions.answerField().topFieldY()); - var glyph2 = createGlyph(identifier, + GlyphPositions.answerField.height(), + GlyphPositions.answerField.topFieldY() + ); + var glyph2 = Resources.createGlyph( + Key.key("msb3", "dialogue/inactive_text_field/" + identifier), writable, - "not_active_field2", - positions.answerField().height(), - positions.answerField().topFieldY()); - var glyph3 = createGlyph(identifier, + GlyphPositions.answerField.height(), + GlyphPositions.answerField.topFieldY() + ); + var glyph3 = Resources.createGlyph( + Key.key("msb3", "dialogue/inactive_text_field/" + identifier), writable, - "not_active_field3", - positions.answerField().height(), - positions.answerField().bottomFieldY()); - var glyph4 = createGlyph(identifier, + GlyphPositions.answerField.height(), + GlyphPositions.answerField.bottomFieldY() + ); + var glyph4 = Resources.createGlyph( + Key.key("msb3", "dialogue/inactive_text_field/" + identifier), writable, - "not_active_field4", - positions.answerField().height(), - positions.answerField().bottomFieldY()); + GlyphPositions.answerField.height(), + GlyphPositions.answerField.bottomFieldY() + ); notActiveFields.put(identifier, new TextField(glyph1, glyph2, glyph3, glyph4)); - glyphResourcePack - .with(StringIdentifier.image("not_active_field1__" + identifier), glyph1) - .with(StringIdentifier.image("not_active_field2__" + identifier), glyph2) - .with(StringIdentifier.image("not_active_field3__" + identifier), glyph3) - .with(StringIdentifier.image("not_active_field4__" + identifier), glyph4); } - public Optional getAvatar(String identifier) { - return getGlyphFromMap(identifier, avatars); + public Optional getAvatar(String identifier) { + return Optional.ofNullable(avatars.get(identifier)); } - public Optional getAvatarFrame(String identifier) { - return getGlyphFromMap(identifier, avatarFrames); + public Optional getAvatarFrame(String identifier) { + return Optional.ofNullable(avatarFrames.get(identifier)); } - public Optional getScrollUp(String identifier) { - return getGlyphFromMap(identifier, scrollUp); + public Optional getScrollUp(String identifier) { + return Optional.ofNullable(scrollUp.get(identifier)); } - public Optional getScrollDown(String identifier) { - return getGlyphFromMap(identifier, scrollDown); + public Optional getScrollDown(String identifier) { + return Optional.ofNullable(scrollDown.get(identifier)); } public Optional getBackground(String identifier) { @@ -342,10 +258,6 @@ public class DialogueResources { return Optional.ofNullable(substrates.get(identifier)); } - public Optional getFont(String identifier) { - return Optional.ofNullable(fonts.get(identifier)).map(FontGlyphEntry::glyph); - } - public Optional