0 votes

Hi, so I've got a tileset in a custom format I'm trying to import. It's more than just a texture it also has a tile type enum and a color value for a minimap.

How do I import both the custom resource and the texture?

The import script in the EditorImportPlugin:

func import(source_file, save_path, options, r_platform_variants, r_gen_files):
    var file = File.new()
    var err = file.open(source_file, File.READ)
    if err != OK:
        return err
    var colors: PoolColorArray = []
    var tile_types: PoolIntArray = []
    var tileset_type: int
    var image = Image.new()
    var header = file.get_buffer(29)
    assert(file.get_8() == 26, "Invalid magic number for tile")
    var tile_count: int = file.get_32()
    tileset_type = file.get_32()
    var width: int = 64 * min(tile_count, 16)
    var height: int = 32 * ((tile_count / 16) + 1)
    print("tileset texture is ", width, "x", height)
    image.create(width, height, false, Image.FORMAT_RGBA5551)
    if tile_count > 0:
        assert((file.get_len() - 28) / tile_count == 2051, "Wrong Size of TIL file")
        for i in range(tile_count):
            var img: PoolByteArray = file.get_buffer(2048)
            convert_to_image(image, img, i)
        for c in range(tile_count):
            var col: int = file.get_16()
        for t in range(tile_count):
    if file.get_position() != file.get_len():
        print("Not at end of " % source_file)
        return ERR_PARSE_ERROR
    return ResourceSaver.save("%s.%s" % [save_path, get_save_extension()],
        Tiles.new(tileset_type, tile_types, colors, image))

The custom resource which has a texture within it:

extends Resource

enum TileType {
    OPEN = 0
    ROAD = 2
    BUILDING = 6

enum SetType {
    FLATS = 0 # minimum of 1 tile, first 15 tiles are transitions
    SLOPE_ONLY = 1 # 15 tiles minimum
    OPEN = 2 # 30 tiles minimum
    FULL_SET = 3 # 45 tiles minimum

export(SetType) var set_type
export(Array, TileType) var tile_type
export(Array, Color) var minimap_color
export(ImageTexture) var tex

func _init(
        p_set_type: int=0,
        p_tile_type: Array=[],
        p_minimap_color: Array=[],
        p_data: Image=Image.new()):
    set_type = p_set_type
    tile_type = p_tile_type
    minimap_color = p_minimap_color
    tex = ImageTexture.new()

The only problem is I cannot select the texture to go into a tilemap?

Godot version v3.3.1
in Engine by (104 points)

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.