Coder Social home page Coder Social logo

swflangloader's Introduction

Swf Lang Loader

Java CI codecov javadoc Maven Central

Load and parse Dofus retro swf lang files.

Installation

For installing using maven, add this dependency into the pom.xml :

<dependency>
    <groupId>fr.arakne</groupId>
    <artifactId>swf-lang-loader</artifactId>
    <version>0.3-alpha</version>
</dependency>

Usage

Simple usage

On this example, we find the nearest bank map for the given player :

public class Main {
    public MapPosition findNearestBankMap(Player player){
        // Declare the loader 
        // The first parameter is the langs location, which contains versions_xx.txt files, and swf folder
        // The second parameter is the language. Can be "fr", "en", "de", "es", "it", "nl", "pt"
        LangLoader loader = new LangLoader("http://my-cdn.dofus-server.com/lang", "fr");

        // Load maps and hints swf files
        MapsFile maps = loader.maps();
        HintsFile hints = loader.hints();

        // Get map position
        MapPosition currentPosition = maps.position(player.map().id());

        // Get all banks hints, convert to map position, and get the nearest position
        return hints.byType(Hint.TYPE_BANK)
            .map(hint -> maps.position(hint.mapId()))
            .min(Comparator.comparingInt(currentPosition::distance))
        ;
    }
}

Configure loader & cache system

The loader can be configurer to customize the version loader, and cache system. If enabled (by default), the loader will keep decompiled action script files as cache.

public class Main {
    public LangLoader getLoader() {
        return new LangLoader(
            "http://my-cdn.dofus-server.com/lang", // The lang CDN 
            "fr", // The language
            new TxtVersionsLoader(), // Define the version loading strategy. TxtVersionsLoader will parse versions_xx.txt file
            new SwfFileLoader(
                Paths.get("my/cache/directory"), // Define the cache directory
                true // Enable caching ? (i.e. keep AS files for further use)
            )
        );
    }
}

You can also clear the cache, and force reload all swf files by calling LangLoader#clear() method.

Load a custom SWF structure

You can declare a custom SWF file and load it by using SwfFileLoader.

public class Main {
    // Define the structure class. Here extends BaseLangFile to handle default (i.e. undeclared) SWF variable
    class MyCustomSwf extends BaseLangFile {
        // Declare "FOO" swf variable as string
        // When an assignation `FOO = xxx;` will be parsed, the value "xxx" will be interpreted as String, and MyCustomSwf#foo will be set. 
        @SwfVariable("FOO")
        private String foo;
    
        // The variable name is optional if the java field name match with the SWF variable.
        // The parser handle JSON objects type
        @SwfVariable
        private MySubObject SUB;

        // Handle associative assignation (i.e. `OBJ["foo"] = {...};`)
        // Extract key and value type for declaration. Can handle any primitive value as key.
        @SwfVariable("OBJ")
        final private Map<String, MyOtherObject> objects = new HashMap<>();
    }

    public static void main(String[] args) {
        // Declare the swf loader
        SwfFileLoader loader = new SwfFileLoader();

        // Declare the hydrator by parsing class annotations
        MapperHydrator<MyCustomSwf> hydrator = MapperHydrator.parseAnnotations(MyCustomSwf.class);
        
        // Instantiate the SWF structure
        MyCustomSwf swf = new MyCustomSwf();
        // Load and parse SWF file. The URL can be a local file
        loader.load(new URL("http://my-cdn.dofus-server.com/lang/swf/custom_fr_123.swf"), swf, hydrator);

        // Here, you can use swf
        System.out.println(swf.foo);
    }
}

Licence

This project is licensed under the LGPLv3 licence. See COPYING and COPYING.LESSER files for details.

Use FFDec Library which is licensed with GNU LGPL v3, for parsing SWF files.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.