Search in sources :

Example 11 with Asset

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

the class MeshStore method getMesh.

@Override
public Mesh getMesh(String meshName) {
    Mesh mesh = meshes.get(meshName);
    if (mesh == null) {
        Asset a = modsManager.getAsset(meshName);
        try {
            // mesh = loader.loadMeshFromAsset(a);
            mesh = loader.load(a);
        } catch (MeshLoadException e) {
            e.printStackTrace();
            logger().error("Mesh " + meshName + " couldn't be load using MeshLoader " + loader.getClass().getName() + " ,stack trace above.");
            return null;
        }
        meshes.put(meshName, mesh);
    }
    return mesh;
}
Also used : AnimatableMesh(io.xol.chunkstories.api.mesh.AnimatableMesh) Mesh(io.xol.chunkstories.api.mesh.Mesh) Asset(io.xol.chunkstories.api.content.Asset) MeshLoadException(io.xol.chunkstories.api.exceptions.content.MeshLoadException)

Example 12 with Asset

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

the class GLSLPreprocessor method loadRecursivly.

public static void loadRecursivly(ModsManager modsManager, Asset asset, StringBuilder into, boolean type, Set<String> alreadyIncluded) throws IOException {
    if (alreadyIncluded == null)
        alreadyIncluded = new HashSet<String>();
    Reader fileReader = asset.reader();
    BufferedReader reader = new BufferedReader(fileReader);
    // List<String> blockingDef = new ArrayList<String>();
    String l;
    while ((l = reader.readLine()) != null) {
        String strippedLine = l.replace("	", "");
        if (strippedLine.startsWith("#")) {
            String[] line = strippedLine.substring(1).replace(">", "").replace("<", "").split(" ");
            if (line.length == 2) {
                if (line[0].equals("include")) {
                    String fn = line[1];
                    String shaderInclude = asset.getName().substring(0, asset.getName().lastIndexOf("/") + 1) + fn;
                    while (shaderInclude.indexOf("..") != -1) {
                        int indexOf = shaderInclude.indexOf("..");
                        if (indexOf <= 0) {
                            System.out.println("Irresolvable path; going too far back in parents folder; " + shaderInclude);
                            break;
                        }
                        String lowerHalf = shaderInclude.substring(0, indexOf - 1);
                        String upperHalf = shaderInclude.substring(indexOf + 2);
                        lowerHalf = lowerHalf.substring(0, lowerHalf.lastIndexOf("/"));
                        shaderInclude = lowerHalf + upperHalf;
                    }
                    Asset asset2include = modsManager.getAsset(shaderInclude);
                    if (asset2include == null) {
                        System.out.println("Couldn't find shader include: " + shaderInclude);
                        continue;
                    }
                    // Prevents including same file twice and retarded loops
                    if (alreadyIncluded.add(asset2include.getName()))
                        loadRecursivly(modsManager, asset2include, into, type, alreadyIncluded);
                    else
                        System.out.println("Shader include : " + asset2include.getName() + " already included, skipping");
                    continue;
                } else if (line[0].equals("version")) {
                    into.append(l).append("\n");
                    // <- append the defines stuff after the version tag
                    defineConfiguration(into);
                    continue;
                }
            }
        }
        into.append(l).append("\n");
    }
    reader.close();
// return into;
}
Also used : BufferedReader(java.io.BufferedReader) BufferedReader(java.io.BufferedReader) Reader(java.io.Reader) Asset(io.xol.chunkstories.api.content.Asset) HashSet(java.util.HashSet)

Example 13 with Asset

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

the class CubemapGL method loadCubemapFromDisk.

public int loadCubemapFromDisk() {
    bind();
    ByteBuffer temp;
    String[] names = { "right", "left", "top", "bottom", "front", "back" };
    if (Client.getInstance().getContent().getAsset((name + "/front.png")) == null) {
        logger().info("Can't find front.png from CS-format skybox, trying MC format.");
        names = new String[] { "panorama_1", "panorama_3", "panorama_4", "panorama_5", "panorama_0", "panorama_2" };
    }
    try {
        for (int i = 0; i < 6; i++) {
            Asset pngFile = Client.getInstance().getContent().getAsset(name + "/" + names[i] + ".png");
            if (pngFile == null)
                throw new FileNotFoundException(name + "/" + names[i] + ".png");
            PNGDecoder decoder = new PNGDecoder(pngFile.read());
            temp = ByteBuffer.allocateDirect(4 * decoder.getWidth() * decoder.getHeight());
            decoder.decode(temp, decoder.getWidth() * 4, Format.RGBA);
            temp.flip();
            this.size = decoder.getHeight();
            glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, type.getInternalFormat(), decoder.getWidth(), decoder.getHeight(), 0, type.getFormat(), type.getType(), temp);
            // Anti alias
            glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
            glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
            // Anti seam
            glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
            glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
        }
    } catch (FileNotFoundException e) {
        logger().warn("Couldn't find file : " + e.getMessage());
    } catch (IOException e) {
        logger().error("Failed to load properly cubemap : " + name);
    }
    return glId;
}
Also used : PNGDecoder(de.matthiasmann.twl.utils.PNGDecoder) FileNotFoundException(java.io.FileNotFoundException) Asset(io.xol.chunkstories.api.content.Asset) IOException(java.io.IOException) ByteBuffer(java.nio.ByteBuffer)

Example 14 with Asset

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

the class ModsManagerImplementation method loadModAssets.

private ClassLoader loadModAssets(ModImplementation mod, ClassLoader parentClassLoader) {
    List<File> jarFiles = new LinkedList<File>();
    // For each asset in the said mod
    for (Asset asset : mod.assets()) {
        // Skips mod.txt
        if (asset.getName().equals("./mod.txt"))
            continue;
        // Special case for .jar files : we extract them in the cache/ folder and make them avaible through secure ClassLoaders
        if (asset.getName().endsWith(".jar")) {
            File jarFile = loadJarFile(asset);
            if (jarFile != null)
                jarFiles.add(jarFile);
            continue;
        }
        // Look for it's entry
        ModsAssetHierarchy entry = avaibleAssets.get(asset.getName());
        if (entry == null) {
            entry = new ModsAssetHierarchy(asset);
            avaibleAssets.put(asset.getName(), entry);
        } else {
            System.out.println("Adding asset " + asset + ", overriding previous stuff (top=" + entry.topInstance() + ")");
            entry.addAssetInstance(asset);
        }
    }
    // No jar files ? Just return the parent class loader.
    if (jarFiles.size() == 0)
        return parentClassLoader;
    // Build a specialized class loader based on the parent one and the jars found within the mod
    ForeignCodeClassLoader classLoader;
    try {
        classLoader = new ForeignCodeClassLoader(mod, parentClassLoader, jarFiles);
    } catch (IOException e1) {
        e1.printStackTrace();
        System.out.println("Error whilst creating a ForeignCodeClassLoader for " + mod);
        return parentClassLoader;
    }
    for (String className : classLoader.classes()) {
        avaibleForeignClasses.put(className, classLoader);
    }
    // Load any plugins those jar files might be
    for (File jarFile : jarFiles) {
        try {
            PluginInformationImplementation pluginInformation = new PluginInformationImplementation(jarFile, classLoader);
            logger.info("Found plugin " + pluginInformation + " in " + mod);
            pluginsWithinEnabledMods.add(pluginInformation);
        } catch (NotAPluginException nap) {
        // Discard silently
        } catch (PluginLoadException | IOException e) {
            System.out.println("Something went wrong loading the plugin " + jarFile + " from " + mod);
            e.printStackTrace();
        }
    }
    return classLoader;
}
Also used : NotAPluginException(io.xol.chunkstories.plugin.NotAPluginException) PluginLoadException(io.xol.chunkstories.api.exceptions.plugins.PluginLoadException) Asset(io.xol.chunkstories.api.content.Asset) IOException(java.io.IOException) File(java.io.File) ForeignCodeClassLoader(io.xol.chunkstories.content.sandbox.ForeignCodeClassLoader) LinkedList(java.util.LinkedList) PluginInformationImplementation(io.xol.chunkstories.plugin.PluginInformationImplementation)

Example 15 with Asset

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

the class ItemDefinitionsStore method reload.

public void reload() {
    dictionary.clear();
    Iterator<Asset> i = modsManager.getAllAssetsByExtension("items");
    while (i.hasNext()) {
        Asset f = i.next();
        logger().debug("Reading items definitions in : " + f);
        readItemsDefinitions(f);
    }
}
Also used : Asset(io.xol.chunkstories.api.content.Asset)

Aggregations

Asset (io.xol.chunkstories.api.content.Asset)22 IOException (java.io.IOException)6 AssetHierarchy (io.xol.chunkstories.api.content.mods.AssetHierarchy)5 File (java.io.File)3 ArrayList (java.util.ArrayList)3 IterableIterator (io.xol.chunkstories.api.util.IterableIterator)2 BufferedReader (java.io.BufferedReader)2 Iterator (java.util.Iterator)2 PNGDecoder (de.matthiasmann.twl.utils.PNGDecoder)1 ClientInterface (io.xol.chunkstories.api.client.ClientInterface)1 IllegalVoxelDeclarationException (io.xol.chunkstories.api.exceptions.content.IllegalVoxelDeclarationException)1 MeshLoadException (io.xol.chunkstories.api.exceptions.content.MeshLoadException)1 PluginLoadException (io.xol.chunkstories.api.exceptions.plugins.PluginLoadException)1 AnimatableMesh (io.xol.chunkstories.api.mesh.AnimatableMesh)1 Mesh (io.xol.chunkstories.api.mesh.Mesh)1 VoxelRenderer (io.xol.chunkstories.api.rendering.voxel.VoxelRenderer)1 ForeignCodeClassLoader (io.xol.chunkstories.content.sandbox.ForeignCodeClassLoader)1 NotAPluginException (io.xol.chunkstories.plugin.NotAPluginException)1 PluginInformationImplementation (io.xol.chunkstories.plugin.PluginInformationImplementation)1 BufferedImage (java.awt.image.BufferedImage)1