Pixel-Composer/scripts/binder_gamemaker/binder_gamemaker.gml

114 lines
3.3 KiB
Plaintext
Raw Normal View History

function Binder_Gamemaker(path) {
if(!file_exists_empty(path)) return noone;
if(filename_ext(path) != ".yyp") return noone;
return new __Binder_Gamemaker(path);
}
function GMSprite(_gm, _path, _info) constructor {
gmBinder = _gm;
path = $"{_gm.dir}/{_path}";
key = _path;
raw = _info;
type = _info.resourceType;
thumbnail = noone;
var _dirr = filename_dir(path);
var _frame = raw.frames;
var _layers = raw.layers;
thumbnailPath = "";
if(array_empty(_frame) || array_empty(_layers)) return;
thumbnailPath = $"{_dirr}/layers/{_frame[0].name}/{_layers[0].name}.png";
if(file_exists(thumbnailPath)) {
var _th = sprite_add(thumbnailPath, 0, 0, 0, 0, 0);
thumbnail = _th;
}
}
function GMTileset(_gm, _path, _info) constructor {
gmBinder = _gm;
path = $"{_gm.dir}/{_path}";
key = _path;
raw = _info;
type = _info.resourceType;
thumbnail = noone;
sprite = raw.spriteId.path;
}
function GMRoom(_gm, _path, _info) constructor {
gmBinder = _gm;
path = $"{_gm.dir}/{_path}";
key = _path;
raw = _info;
type = _info.resourceType;
thumbnail = noone;
}
2024-10-29 07:01:22 +01:00
function __Binder_Gamemaker(path) constructor {
2024-11-13 08:35:04 +01:00
self.path = path;
name = filename_name_only(path);
dir = filename_dir(path);
projectName = "";
resourcesRaw = [];
resourcesMap = {};
2024-11-13 08:35:04 +01:00
resources = [
{ name: "sprites", data : [], closed : false, },
{ name: "tileset", data : [], closed : false, },
{ name: "rooms", data : [], closed : false, },
];
static readYY = function(path) {
var _res = file_read_all(path);
var _resMap = json_try_parse(_res, -1);
if(_resMap == -1) return noone;
return _resMap;
}
static refreshResources = function() {
if(!file_exists(path)) return;
var _res = file_read_all(path);
var _resMap = json_try_parse(_res, -1);
if(_resMap == -1) return;
projectName = _resMap.name;
resourcesRaw = _resMap.resources;
resourcesMap = {};
var sprites = [];
var tileset = [];
var rooms = [];
for( var i = 0, n = array_length(resourcesRaw); i < n; i++ ) {
var _res = resourcesRaw[i].id;
var _name = _res.name;
var _path = _res.path;
var _info = readYY($"{dir}/{_path}");
if(_info == noone) continue;
var _asset = noone;
switch(_info.resourceType) {
case "GMSprite": _asset = new GMSprite(self, _path, _info); array_push(sprites, _asset); break;
case "GMTileSet": _asset = new GMTileset(self, _path, _info); array_push(tileset, _asset); break;
case "GMRoom": _asset = new GMRoom(self, _path, _info); array_push(rooms, _asset); break;
}
resourcesMap[$ _path] = _asset;
}
resources[0].data = sprites;
resources[1].data = tileset;
resources[2].data = rooms;
}
2024-10-29 07:01:22 +01:00
refreshResources();
2024-10-29 07:01:22 +01:00
}