Pixel-Composer/scripts/meta_data/meta_data.gml

243 lines
6.7 KiB
Text
Raw Normal View History

2023-02-14 02:48:33 +01:00
#region tags
globalvar META_TAGS;
META_TAGS = [ "3D", "Disappear", "Effect", "Filter", "Generator", "Transform", "Transition", "Utility" ];
2023-02-23 07:02:19 +01:00
enum FILE_TYPE {
project,
collection,
assets
}
2023-11-27 14:50:20 +01:00
enum FILE_STEAM_TYPE {
local,
steamUpload,
steamOpen
}
2023-02-14 02:48:33 +01:00
#endregion
function MetaDataManager() constructor {
name = "";
description = "";
author = "";
contact = "";
alias = "";
2023-02-23 07:02:19 +01:00
type = FILE_TYPE.collection;
2024-08-12 13:42:05 +02:00
2023-02-14 02:48:33 +01:00
author_steam_id = 0;
file_id = 0;
tags = [];
2023-08-04 13:12:32 +02:00
version = SAVE_VERSION;
2023-11-27 14:50:20 +01:00
steam = FILE_STEAM_TYPE.local;
2023-02-14 02:48:33 +01:00
static displays = [
[ "Description", function(meta) { return meta.description; } , 5],
[ "Author", function(meta) { return meta.author; } , 1],
[ "Contact info", function(meta) { return meta.contact; } , 1],
[ "Alias", function(meta) { return meta.alias; } , 1],
[ "Tags", function(meta) { return meta.tags; } , 1],
2023-02-14 02:48:33 +01:00
];
static serialize = function() {
2023-06-13 14:42:06 +02:00
var m = {};
2023-08-04 13:12:32 +02:00
m.description = description;
m.author = author;
m.contact = contact;
m.alias = alias;
m.aut_id = author_steam_id;
m.file_id = file_id;
m.tags = tags;
m.version = version;
2023-02-14 02:48:33 +01:00
return m;
}
static deserialize = function(m, readonly = false) {
2023-06-13 14:42:06 +02:00
description = struct_try_get(m, "description", description);
author = struct_try_get(m, "author", author);
contact = struct_try_get(m, "contact", contact);
alias = struct_try_get(m, "alias", alias);
author_steam_id = struct_try_get(m, "aut_id", author_steam_id);
file_id = struct_try_get(m, "file_id", file_id);
tags = struct_try_get(m, "tags", tags);
2023-08-04 13:12:32 +02:00
version = struct_try_get(m, "version", version);
2023-02-14 02:48:33 +01:00
return self;
}
static clone = function() {
var m = new MetaDataManager();
m.description = description;
m.author = author;
m.contact = contact;
m.alias = alias;
return m;
}
static drawTooltip = function() {
2023-11-24 14:48:19 +01:00
var _pd = ui(10);
2023-02-14 02:48:33 +01:00
var ww = ui(320), _w = 0;
var _h = 0;
2023-02-23 07:02:19 +01:00
if(type == FILE_TYPE.assets) {
draw_set_font(f_p1);
2023-02-23 07:02:19 +01:00
_h = string_height(name);
_w = string_width(name);
2024-09-12 05:27:42 +02:00
var mx = min(__mouse_tx + _pd * 2, __win_tw - (_w + _pd * 2));
var my = min(__mouse_ty + _pd * 2, __win_th - (_h + _pd * 2));
2023-02-23 07:02:19 +01:00
2023-11-24 14:48:19 +01:00
draw_sprite_stretched(THEME.textbox, 3, mx, my, _w + _pd * 2, _h + _pd * 2);
draw_sprite_stretched(THEME.textbox, 0, mx, my, _w + _pd * 2, _h + _pd * 2);
2023-02-23 07:02:19 +01:00
draw_set_text(f_p1, fa_left, fa_top, COLORS._main_text);
2023-11-24 14:48:19 +01:00
draw_text(mx + _pd, my + _pd, name);
2023-02-23 07:02:19 +01:00
return;
}
2023-11-24 14:48:19 +01:00
var _own = author_steam_id == STEAM_USER_ID;
var _ont = "Your creation";
var _aut = $"{__txt("By")} {author}";
2023-12-05 04:28:49 +01:00
var _ver = floor(version) < floor(SAVE_VERSION)? __txtx("meta_old_version", "Created on an older version") : __txtx("meta_new_version", "Created on a newer version");
2023-02-14 02:48:33 +01:00
draw_set_font(f_h5);
_h += string_height_ext(name, -1, ww) - ui(4);
_w = max(_w, string_width_ext(name, -1, ww));
draw_set_font(f_p1);
2023-02-14 02:48:33 +01:00
_h += string_height_ext(_aut, -1, ww);
2023-11-24 14:48:19 +01:00
_w = max(_w, string_width_ext(_aut, -1, ww) + _own * (ui(24) + string_width(_ont)));
2023-02-14 02:48:33 +01:00
if(contact != "") {
draw_set_font(f_p2);
2023-11-24 14:48:19 +01:00
_h += string_height_ext(contact, -1, ww);
2023-02-14 02:48:33 +01:00
_w = max(_w, string_width_ext(contact, -1, ww));
}
draw_set_font(f_p1);
2023-02-14 02:48:33 +01:00
_h += ui(8);
_h += string_height_ext(description, -1, ww);
_w = max(_w, string_width_ext(description, -1, ww));
if(alias != "") {
_h += ui(16);
draw_set_font(f_p2);
_h += string_height_ext(alias, -1, ww);
_w = max(_w, string_width_ext(alias, -1, ww));
}
2023-12-05 04:28:49 +01:00
if(floor(version) != floor(SAVE_VERSION)) {
2023-02-14 02:48:33 +01:00
draw_set_font(f_p2);
_h += ui(8);
_h += string_height_ext(_ver, -1, ww);
_w = max(_w, string_width_ext(_ver, -1, ww));
}
2023-02-17 11:31:33 +01:00
if(array_length(tags)) {
draw_set_font(f_p1);
2023-02-17 11:31:33 +01:00
_h += ui(8);
var tx = 0;
var hh = line_get_height(f_p1, ui(4));
2023-02-17 11:31:33 +01:00
var th = hh;
2023-07-25 20:12:40 +02:00
for( var i = 0, n = array_length(tags); i < n; i++ ) {
2023-02-17 11:31:33 +01:00
var ww = string_width(tags[i]) + ui(16);
if(tx + ww + ui(2) > _w - ui(16)) {
tx = 0;
th += hh + ui(2);
}
tx += ww + ui(2);
}
_h += th;
}
2024-09-12 05:27:42 +02:00
var mx = min(__mouse_tx + _pd * 2, __win_tw - (_w + _pd * 2));
var my = min(__mouse_ty + _pd * 2, __win_th - (_h + _pd * 2));
2023-02-14 02:48:33 +01:00
////////////////////////////////////////////////////////////////////////////////////////////////////
2023-11-24 14:48:19 +01:00
draw_sprite_stretched(THEME.textbox, 3, mx, my, _w + _pd * 2, _h + _pd * 2);
draw_sprite_stretched(THEME.textbox, 0, mx, my, _w + _pd * 2, _h + _pd * 2);
2023-02-14 02:48:33 +01:00
var ty = my + ui(8);
draw_set_text(f_h5, fa_left, fa_top, COLORS._main_text);
2023-11-24 14:48:19 +01:00
draw_text_line(mx + _pd, ty, name, -1, _w);
2023-02-14 02:48:33 +01:00
ty += string_height_ext(name, -1, _w) - ui(4);
draw_set_text(f_p1, fa_left, fa_top, COLORS._main_text_sub);
2023-11-24 14:48:19 +01:00
draw_text_line(mx + _pd, ty, _aut, -1, _w);
if(_own) {
var _owX = mx + _pd + string_width_ext(_aut, -1, _w) + ui(12);
draw_set_font(f_p2);
var _owW = string_width( _ont);
var _owH = string_height(_ont);
draw_sprite_stretched_ext(THEME.s_box_r2, 0, _owX - ui(4), ty + ui(1) - ui(2), _owW + ui(8), _owH + ui(4), COLORS._main_icon_dark, 1);
2023-11-24 14:48:19 +01:00
draw_set_color(COLORS._main_text_accent);
draw_text_line(_owX, ty + ui(1), _ont, -1, _w);
}
2023-02-14 02:48:33 +01:00
ty += string_height_ext(_aut, -1, _w);
if(contact != "") {
draw_set_text(f_p2, fa_left, fa_top, COLORS._main_text_sub);
2023-11-24 14:48:19 +01:00
draw_text_line(mx + _pd, ty, contact, -1, _w);
2023-02-14 02:48:33 +01:00
ty += string_height_ext(contact, -1, _w);
}
ty += ui(8);
draw_set_text(f_p1, fa_left, fa_top, COLORS._main_text);
2023-11-24 14:48:19 +01:00
draw_text_line(mx + _pd, ty, description, -1, _w);
2023-02-14 02:48:33 +01:00
ty += string_height_ext(description, -1, _w);
if(alias != "") {
ty += ui(16);
draw_set_text(f_p2, fa_left, fa_top, COLORS._main_text_sub);
2023-11-24 14:48:19 +01:00
draw_text_line(mx + _pd, ty, alias, -1, _w);
2023-02-14 02:48:33 +01:00
ty += string_height_ext(alias, -1, _w);
}
2023-12-05 04:28:49 +01:00
if(floor(version) != floor(SAVE_VERSION)) {
2023-02-14 02:48:33 +01:00
ty += ui(8);
draw_set_text(f_p2, fa_left, fa_top, COLORS._main_accent);
2023-11-24 14:48:19 +01:00
draw_text_line(mx + _pd, ty, _ver, -1, _w);
2023-02-14 02:48:33 +01:00
ty += string_height_ext(_ver, -1, _w);
}
2023-02-17 11:31:33 +01:00
if(array_length(tags)) {
draw_set_text(f_p1, fa_left, fa_center, COLORS._main_text);
2023-02-17 11:31:33 +01:00
ty += ui(8);
var tx = 0;
var hh = line_get_height(f_p1, ui(4));
2023-02-17 11:31:33 +01:00
2023-07-25 20:12:40 +02:00
for( var i = 0, n = array_length(tags); i < n; i++ ) {
2023-02-17 11:31:33 +01:00
var ww = string_width(tags[i]) + ui(16);
if(tx + ww + ui(2) > _w - ui(16)) {
tx = 0;
ty += hh + ui(2);
}
draw_sprite_stretched_ext(THEME.s_box_r5_clr, 0, mx + ui(8) + tx, ty, ww, hh, COLORS._main_icon, 1);
2023-02-17 11:31:33 +01:00
draw_text(mx + ui(8) + tx + ui(8), ty + hh / 2, tags[i]);
tx += ww + ui(2);
}
}
2023-02-14 02:48:33 +01:00
}
}
#region
function __getdefaultMetaData() {
var meta = new MetaDataManager();
2023-03-22 08:29:29 +01:00
var path = DIRECTORY + "meta.json";
2023-04-21 19:08:10 +02:00
2023-12-08 03:50:09 +01:00
if(!file_exists_empty(path)) return meta;
2023-08-06 16:00:59 +02:00
var over = json_load_struct(path);
2023-02-14 02:48:33 +01:00
return meta.deserialize(over);
}
#endregion