Skip to content

Commit

Permalink
Added/Updated JSDOC, finalized some stuff and added in error checks
Browse files Browse the repository at this point in the history
  • Loading branch information
tabularelf committed Sep 6, 2021
1 parent d6e48a7 commit 6d8d069
Show file tree
Hide file tree
Showing 38 changed files with 109 additions and 100 deletions.
4 changes: 2 additions & 2 deletions datafiles/locale.csv
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Language,English,Comments,French,Japanese
Locale,"[""en-UK"", ""en-US"", ""en-AU""]",,fr-FR,ja-JP
text.test,I love you %s more since you used Lexicon. %s - %s. Thank you !%s - %s. Thank you !,This is a comment,Je vous aime %s plus depuis que vous utilisez Lexicon. %s - le %s. Merci !utilisez Lexicon. %s - le %s. Merci !,君が「lexicon」を使ってる前より%s回好きです。%s - %s。ありがとうございます !
text.test2,I love you {{loveMeter}} more since you used Lexicon. {{playerName}} - {{dateTime}}. Thank you !%s - %s. Thank you !,This is a comment,Je vous aime {{loveMeter}} plus depuis que vous utilisez Lexicon. {{playerName}} - le {{dateTime}}. Merci !utilisez Lexicon. %s - le %s. Merci !,君が「lexicon」を使ってる前より{{loveMeter}}回好きです。{{playerName}} - {{dateTime}}。ありがとうございます !
text.test,I love you %s more since you used Lexicon. %s - %s. Thank you !%s - %s. Thank you!,This is a comment,Je vous aime %s plus depuis que vous utilisez Lexicon. %s - le %s. Merci !utilisez Lexicon. %s - le %s. Merci !,君が「lexicon」を使ってる前より%s回好きです。%s - %s。ありがとうございます !
text.test2,I love you {{loveMeter}} more since you used Lexicon. {{playerName}} - {{dateTime}}. Thank you!,This is a comment,Je vous aime {{loveMeter}} plus depuis que vous utilisez Lexicon. {{playerName}} - le {{dateTime}}. Merci !utilisez Lexicon. %s - le %s. Merci !,君が「lexicon」を使ってる前より{{loveMeter}}回好きです。{{playerName}} - {{dateTime}}。ありがとうございます !
4 changes: 2 additions & 2 deletions datafiles/locale.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"language": "English",
"locale": ["en-US", "en-AU"],
"text": {
"text.test": "I love you %s more since you used Lexicon. %s - %s. Thank you !",
"text.test2": "I love you {{loveMeter}} more since you used Lexicon. {{playerName}} - {{dateTime}}. Thank you !%s - %s. Thank you !"
"text.test": "I love you %s more since you used Lexicon. %s - %s. Thank you!",
"text.test2": "I love you {{loveMeter}} more since you used Lexicon. {{playerName}} - {{dateTime}}. Thank you!"
}
}
18 changes: 10 additions & 8 deletions lexicon.yyp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 5 additions & 14 deletions objects/obj_test/Create_0.gml
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,12 @@

//Need a font supporting weird glyph (from an roman alphabet user's point of view ;) )
font = fn_fontWithJapanese;
draw_set_font(font);

lexicon_index_definitions("definitions.json");
/*var _buff = buffer_load("locale.json");
lexicon_parse_json(_buff);
show_debug_message(__LEXICON_STRUCT);
buffer_delete(_buff);*/
/*var _t = get_timer();
var _buff = buffer_load("locale.csv");
lexicon_parse_csv(buffer_read(_buff, buffer_text));
show_debug_message(string((get_timer() - _t) / 1000) + "ms");
buffer_delete(_buff);*/
lexicon_locale_set(LEXICON_DEFAULT_LOCALE);

struct = {playerName: "TabularElf", loveMeter: "100%", dateTime: string(date_get_year(date_current_datetime()))+"//"+string(date_get_month(date_current_datetime()))};
array = [100, "TabularElf", string( date_get_year(date_current_datetime()))+"/"+string(date_get_month(date_current_datetime()))];
struct = {playerName: "TabularElf", loveMeter: "100%", dateTime: string(date_get_year(date_current_datetime()))+"/"+string(date_get_month(date_current_datetime()))};
array = ["100%", "TabularElf", string( date_get_year(date_current_datetime()))+"/"+string(date_get_month(date_current_datetime()))];
languages_array = lexicon_languages_get_array();
language_index = 0;
var _buffer = buffer_load("locale.csv");
buffer_delete(_buffer);
language_index = 0;
9 changes: 4 additions & 5 deletions objects/obj_test/Draw_0.gml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/// @description Insert description here
// You can write your code in this editor
/// @description Step event


if (keyboard_check_released(vk_space)) {
Expand All @@ -8,11 +7,11 @@ if (keyboard_check_released(vk_space)) {
lexicon_locale_set(languages_array[language_index][1]);
}

draw_set_font(font)

draw_text(32,32,"Normal Version: " + lexicon_text_array("text.test",array));
draw_text(32,64,"Struct Version: " + lexicon_text_struct("text.test2",struct));


draw_text(32,96,languages_array);
draw_text(32,128,lexicon_locale_get());
draw_text(32,128,lexicon_locale_get());

draw_text(room_width div 2, room_height div 2, "Press spacebar to cycle languages");

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion scripts/__lexicon_file_load/__lexicon_file_load.gml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function __lexicon_file_load(_file) {
} else {
_buffer = buffer_load(_file.fileName);
if (_buffer = -1) {
__lexicon_throw("Invalid file " + string(_file.fileName));
if (LEXICON_DEBUG) __lexicon_throw("Invalid file " + string(_file.fileName));
return;
}

Expand Down
4 changes: 2 additions & 2 deletions scripts/__lexicon_file_load/__lexicon_file_load.yy

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions scripts/__lexicon_file_types/__lexicon_file_types.gml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

LEXICON_FILE_TYPES = {
json: {
parser: lexicon_parse_json,
parser: __lexicon_parse_json,
adder: lexicon_index_add_json
},
csv: {
parser: lexicon_parse_csv,
parser: __lexicon_parse_csv,
adder: lexicon_index_add_csv
}
}
4 changes: 2 additions & 2 deletions scripts/__lexicon_file_types/__lexicon_file_types.yy

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function __lexicon_handle_file_type(_lang, _fileStruct) {

if (_fileStruct[$ "arguments"] != undefined) {
if !(is_array(_fileStruct.arguments)) {
__lexicon_throw("Invalid arguments for file definitions. Defaulting to none.")
if (LEXICON_DEBUG) __lexicon_throw("Invalid arguments for file definitions. Defaulting to none.")
} else {
_args = _fileStruct.arguments;
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion scripts/__lexicon_init/__lexicon_init.gml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ __lexicon_init();

function __lexicon_init() {
if (__LEXICON_STRUCT != undefined) {
__lexicon_throw("Lexicon already Initialized");
if (LEXICON_DEBUG) __lexicon_throw("Lexicon already Initialized");
return false;
}

Expand Down
4 changes: 2 additions & 2 deletions scripts/__lexicon_load_entries/__lexicon_load_entries.yy

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@

/// @func lexicon_parse_csv
/// @func __lexicon_parse_csv
/// @param string
/// @param [cell_delimiter]
/// @param [string_delimiter]

// Juju made the original script (csv_to_grid). This was merely adapted to be used as a parser.
// I cannot take full credit for this as a result.
function lexicon_parse_csv(_string, _cell_delimiter = ",", _string_delimiter = "\"") {
function __lexicon_parse_csv(_string, _cell_delimiter = ",", _string_delimiter = "\"") {
var _array = __lexicon_array2D_from_csv(_string, _cell_delimiter, _string_delimiter);
var _width = array_length(_array);
var _height = array_length(_array[0]);
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
function lexicon_parse_json(_json) {
/// @func __lexicon_parse_json(json)
/// @param json
function __lexicon_parse_json(_json) {

try {
var _map = json_parse(_json);
if is_array(_map) {

} else {
if (__LEXICON_STRUCT.language != _map.language) {
__lexicon_throw("Error! language is " + __LEXICON_STRUCT.language + " where it expected " + _map.language);
if (LEXICON_DEBUG) __lexicon_throw("Error! language is " + __LEXICON_STRUCT.language + " where it expected " + _map.language);
return;
}

Expand All @@ -22,12 +24,12 @@ function lexicon_parse_json(_json) {
}

if !(_validLocale) {
__lexicon_throw("locale is " + __LEXICON_STRUCT.locale + " where it expected " + string(_locale));
if (LEXICON_DEBUG) __lexicon_throw("locale is " + __LEXICON_STRUCT.locale + " where it expected " + string(_locale));
return;
}
} else {
if (__LEXICON_STRUCT.locale != _locale) {
__lexicon_throw("locale is " + __LEXICON_STRUCT.locale + " where it expected " + _map.locale);
if (LEXICON_DEBUG) __lexicon_throw("locale is " + __LEXICON_STRUCT.locale + " where it expected " + _map.locale);
return;
}
}
Expand All @@ -40,6 +42,6 @@ function lexicon_parse_json(_json) {
}
}
} catch(_ex) {
__lexicon_throw("Language JSON invalid! " + _ex.message);
if (LEXICON_DEBUG) __lexicon_throw("Language JSON invalid! " + _ex.message);
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions scripts/lexicon_async/lexicon_async.gml
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
// Script assets have changed for v2.3.0 see
// https://help.yoyogames.com/hc/en-us/articles/360005277377 for more information
/// @func lexicon_async()
function lexicon_async() {
var _arrayFiles = __LEXICON_STRUCT.fileAsyncList;
var _len = array_length(_arrayFiles);
var _id = async_load[? "id"];
for(var _i = 0; _i < _len; ++_i) {
if (_arrayFiles[_i][0] == _id) {
if async_load[? "status"] == false {
__lexicon_throw(_arrayFiles[_i][2].filePath + " async load failed!");
if (LEXICON_DEBUG) __lexicon_throw(_arrayFiles[_i][2].filePath + " async load failed!");
buffer_delete(_arrayFiles[_i][1]);
array_delete(_arrayFiles, _i, 1);
} else {
Expand Down
5 changes: 3 additions & 2 deletions scripts/lexicon_entry_add/lexicon_entry_add.gml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Script assets have changed for v2.3.0 see
// https://help.yoyogames.com/hc/en-us/articles/360005277377 for more information
/// @func lexicon_entry_add(text_pointer, string)
// @param text_pointer
/// @param string
function lexicon_entry_add(_textPointer, _string) {
__LEXICON_STRUCT.textEntries[$ _textPointer] = _string;
}
2 changes: 1 addition & 1 deletion scripts/lexicon_flush_cache/lexicon_flush_cache.gml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/// @funct lexicon_flush_cache
/// @funct lexicon_flush_cache()
function lexicon_flush_cache() {
ds_map_clear(__LEXICON_STRUCT.cacheMap);
ds_list_clear(__LEXICON_STRUCT.cacheList);
Expand Down
12 changes: 8 additions & 4 deletions scripts/lexicon_index_add_csv/lexicon_index_add_csv.gml
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
// Script assets have changed for v2.3.0 see
// https://help.yoyogames.com/hc/en-us/articles/360005277377 for more information
/// @func lexicon_index_add_csv(language/locale, file_name, [is_async], [cell_delimiter], [string_delimiter])
/// @param language/locale
/// @param file_name
/// @param[is_async]
/// @param [cell_delimiter]
/// @param [string_delimiter]
function lexicon_index_add_csv(_lang, _fileName, _async = false, _cell_delimiter = ",", _string_delimiter = "\"") {
if !(file_exists(_fileName)) {
__lexicon_throw(_fileName + "does not exist!");
if (LEXICON_DEBUG) __lexicon_throw(_fileName + "does not exist!");
return;
}

Expand All @@ -13,7 +17,7 @@ function lexicon_index_add_csv(_lang, _fileName, _async = false, _cell_delimiter
}

if (_struct == undefined) {
__lexicon_throw(_lang + " is not a valid language or locale!");
if (LEXICON_DEBUG) __lexicon_throw(_lang + " is not a valid language or locale!");
return;
}

Expand Down
10 changes: 6 additions & 4 deletions scripts/lexicon_index_add_json/lexicon_index_add_json.gml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
// Script assets have changed for v2.3.0 see
// https://help.yoyogames.com/hc/en-us/articles/360005277377 for more information
/// @func lexicon_index_add_csv(language/locale, file_name, [is_async])
/// @param language/locale
/// @param file_name
/// @param[is_async]
function lexicon_index_add_json(_lang, _fileName, _async = false) {
if !(file_exists(_fileName)) {
__lexicon_throw(_fileName + "does not exist!");
if (LEXICON_DEBUG) __lexicon_throw(_fileName + "does not exist!");
return;
}

Expand All @@ -13,7 +15,7 @@ function lexicon_index_add_json(_lang, _fileName, _async = false) {
}

if (_struct == undefined) {
__lexicon_throw(_lang + " is not a valid language or locale!");
if (LEXICON_DEBUG) __lexicon_throw(_lang + " is not a valid language or locale!");
return;
}

Expand Down
Loading

0 comments on commit 6d8d069

Please sign in to comment.