Search in sources :

Example 1 with OnlineContentTranslator

use of io.xol.chunkstories.api.content.OnlineContentTranslator in project chunkstories by Hugobros3.

the class PacketInitializeRemoteWorld method process.

public void process(PacketSender sender, DataInputStream in, PacketReceptionContext processor) throws IOException {
    String initializationString = in.readUTF();
    ByteArrayInputStream bais = new ByteArrayInputStream(initializationString.getBytes("UTF-8"));
    BufferedReader reader = new BufferedReader(new InputStreamReader(bais, "UTF-8"));
    info = new WorldInfoImplementation(reader);
    if (processor instanceof ClientPacketsContext) {
        processor.logger().info("Received World initialization packet");
        ClientPacketsContext cpp = (ClientPacketsContext) processor;
        OnlineContentTranslator contentTranslator = cpp.getContentTranslator();
        if (contentTranslator == null) {
            processor.logger().error("Can't initialize a world without a ContentTranslator initialized first!");
            return;
        }
        // TODO should we expose this to the interface ?
        Client client = (Client) cpp.getContext();
        Fence fence = client.getGameWindow().queueSynchronousTask(new Runnable() {

            @Override
            public void run() {
                WorldClientRemote world;
                try {
                    world = new WorldClientRemote(client, info, contentTranslator, cpp.getConnection());
                    client.changeWorld(world);
                    cpp.getConnection().handleSystemRequest("world/ok");
                } catch (WorldLoadingException e) {
                    client.exitToMainMenu(e.getMessage());
                }
            }
        });
        fence.traverse();
    }
}
Also used : WorldLoadingException(io.xol.chunkstories.world.WorldLoadingException) OnlineContentTranslator(io.xol.chunkstories.api.content.OnlineContentTranslator) InputStreamReader(java.io.InputStreamReader) WorldClientRemote(io.xol.chunkstories.world.WorldClientRemote) ClientPacketsContext(io.xol.chunkstories.client.net.ClientPacketsContext) WorldInfoImplementation(io.xol.chunkstories.world.WorldInfoImplementation) ByteArrayInputStream(java.io.ByteArrayInputStream) BufferedReader(java.io.BufferedReader) Fence(io.xol.chunkstories.api.util.concurrency.Fence) Client(io.xol.chunkstories.client.Client)

Example 2 with OnlineContentTranslator

use of io.xol.chunkstories.api.content.OnlineContentTranslator in project chunkstories by Hugobros3.

the class PacketContentTranslator method process.

@Override
public void process(PacketSender sender, DataInputStream in, PacketReceptionContext context) throws IOException, PacketProcessingException {
    this.serializedText = in.readUTF();
    ByteArrayInputStream bais = new ByteArrayInputStream(serializedText.getBytes("UTF-8"));
    BufferedReader reader = new BufferedReader(new InputStreamReader(bais, "UTF-8"));
    try {
        OnlineContentTranslator translator = new LoadedContentTranslator(context.getContext().getContent(), reader);
        PacketsContextCommon cCommon = (PacketsContextCommon) context;
        cCommon.setContentTranslator(translator);
        context.logger().info("Successfully installed content translator");
        cCommon.getConnection().handleSystemRequest("world/translator_ok");
    } catch (IncompatibleContentException e) {
        e.printStackTrace();
    }
    reader.close();
}
Also used : IncompatibleContentException(io.xol.chunkstories.content.translator.IncompatibleContentException) OnlineContentTranslator(io.xol.chunkstories.api.content.OnlineContentTranslator) InputStreamReader(java.io.InputStreamReader) ByteArrayInputStream(java.io.ByteArrayInputStream) LoadedContentTranslator(io.xol.chunkstories.content.translator.LoadedContentTranslator) BufferedReader(java.io.BufferedReader) PacketsContextCommon(io.xol.chunkstories.net.PacketsContextCommon)

Aggregations

OnlineContentTranslator (io.xol.chunkstories.api.content.OnlineContentTranslator)2 BufferedReader (java.io.BufferedReader)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStreamReader (java.io.InputStreamReader)2 Fence (io.xol.chunkstories.api.util.concurrency.Fence)1 Client (io.xol.chunkstories.client.Client)1 ClientPacketsContext (io.xol.chunkstories.client.net.ClientPacketsContext)1 IncompatibleContentException (io.xol.chunkstories.content.translator.IncompatibleContentException)1 LoadedContentTranslator (io.xol.chunkstories.content.translator.LoadedContentTranslator)1 PacketsContextCommon (io.xol.chunkstories.net.PacketsContextCommon)1 WorldClientRemote (io.xol.chunkstories.world.WorldClientRemote)1 WorldInfoImplementation (io.xol.chunkstories.world.WorldInfoImplementation)1 WorldLoadingException (io.xol.chunkstories.world.WorldLoadingException)1