diff --git a/.eslintrc b/.eslintrc index 277bd816b9..0807c0a952 100644 --- a/.eslintrc +++ b/.eslintrc @@ -26,6 +26,7 @@ "jquery": true, }, "parserOptions": { + "requireConfigFile": false, "ecmaVersion": 2020, "sourceType": "module", "ecmaFeatures": { diff --git a/.prettierrc b/.prettierrc index d1e8d2bf65..4d259589c4 100644 --- a/.prettierrc +++ b/.prettierrc @@ -5,5 +5,6 @@ "trailingComma": "es5", "bracketSpacing": true, "semi": true, - "arrowParens": "always" + "arrowParens": "always", + "endOfLine": "auto" } diff --git a/extern/lang/en.js b/extern/lang/en.js index b7bcf525d8..d523c91441 100644 --- a/extern/lang/en.js +++ b/extern/lang/en.js @@ -5635,6 +5635,11 @@ Lang.Workspace = { variable_name_auto_edited_content: 'variable name cannot exceed 10 characters', list_name_auto_edited_title: 'list name auto-edited', list_name_auto_edited_content: 'list name cannot exceed 10 characters', + list_cant_add_item: 'Warning', + list_max_length_exceeded: 'You can add up to 5,000 items to a list.', + list_truncated_on_load: + 'The number of list items in this project exceeds 5,000, so some may not be displayed.\n\nFor stable use,\nplease reduce the list to 5,000 or fewer.', + list_truncated_on_load_title: 'Notice', cloned_scene: 'Cloned_', default_mode: 'Standard', practical_course_mode: 'Textbook', diff --git a/extern/lang/ko.js b/extern/lang/ko.js index 59f0c7182b..ea4d2f7f5e 100644 --- a/extern/lang/ko.js +++ b/extern/lang/ko.js @@ -6014,6 +6014,11 @@ Lang.Workspace = { variable_name_auto_edited_content: '변수의 이름은 10글자를 넘을 수 없습니다.', list_name_auto_edited_title: '리스트 이름 자동 변경', list_name_auto_edited_content: '리스트의 이름은 10글자를 넘을 수 없습니다.', + list_cant_add_item: '경고', + list_max_length_exceeded: '리스트 항목은 최대 5,000개까지 추가할 수 있어요.', + list_truncated_on_load: + '이 작품의 리스트 항목 수가 5,000개를 초과하여 일부가 표시되지 않을 수 있습니다.\n\n안정적인 이용을 위해\n리스트를 5,000개 이하로 줄여주세요.', + list_truncated_on_load_title: '알림', cloned_scene: '복제본_', default_mode: '기본형', practical_course_mode: '교과형', diff --git a/src/class/variable/listVariable.js b/src/class/variable/listVariable.js index e1126d8161..70a59c30cc 100644 --- a/src/class/variable/listVariable.js +++ b/src/class/variable/listVariable.js @@ -7,10 +7,37 @@ class ListVariable extends Variable { return 5000; } + _trimToMaxLength() { + if (this.array_ && this.array_.length > this.LIST_MAX_LENGTH) { + this.array_ = this.array_.slice(-this.LIST_MAX_LENGTH); + this._showListFullWarning(); + } + } + + _showListFullWarning() { + Entry.toast?.alert( + Lang?.Workspace?.list_cant_add_item || 'Warning', + Lang?.Workspace?.list_max_length_exceeded || + `You can add up to ${this.LIST_MAX_LENGTH} items to a list.` + ); + } + constructor(variable) { Entry.assert(variable.variableType === 'list', 'Invalid variable type given'); super(variable); - this.array_ = variable.array ? variable.array : []; + + let array = variable.array ? variable.array : []; + if (array.length > this.LIST_MAX_LENGTH) { + array = array.slice(-this.LIST_MAX_LENGTH); + setTimeout(() => { + Entry.modal?.alert( + Lang?.Workspace?.list_truncated_on_load || + `The list exceeded ${this.LIST_MAX_LENGTH} items.`, + Lang?.Workspace?.list_truncated_on_load_title || 'Notice' + ); + }, 100); + } + this.array_ = array; if (!variable.isClone) { this.width_ = variable.width ? variable.width : 100; @@ -62,11 +89,11 @@ class ListVariable extends Variable { this.resizeHandle_.list = this; GEDragHelper.handleDrag(this.resizeHandle_); - this.resizeHandle_.on(GEDragHelper.types.OVER, function() { + this.resizeHandle_.on(GEDragHelper.types.OVER, function () { this.cursor = 'nwse-resize'; }); - this.resizeHandle_.on(GEDragHelper.types.DOWN, function(evt) { + this.resizeHandle_.on(GEDragHelper.types.DOWN, function (evt) { // if(Entry.type != 'workspace') return; this.list.isResizing = true; this.offset = { @@ -75,18 +102,18 @@ class ListVariable extends Variable { }; this.parent.cursor = 'nwse-resize'; }); - this.resizeHandle_.on(GEDragHelper.types.MOVE, function(evt) { + this.resizeHandle_.on(GEDragHelper.types.MOVE, function (evt) { // if(Entry.type != 'workspace') return; this.list.setWidth(evt.stageX * 0.75 - this.offset.x); this.list.setHeight(evt.stageY * 0.75 - this.offset.y); this.list.updateView(); }); - this.view_.on(GEDragHelper.types.OVER, function() { + this.view_.on(GEDragHelper.types.OVER, function () { this.cursor = 'move'; }); - this.view_.on(GEDragHelper.types.DOWN, function(evt) { + this.view_.on(GEDragHelper.types.DOWN, function (evt) { if (Entry.type !== 'workspace' || this.variable.isResizing) { return; } @@ -97,12 +124,12 @@ class ListVariable extends Variable { this.cursor = 'move'; }); - this.view_.on(GEDragHelper.types.UP, function() { + this.view_.on(GEDragHelper.types.UP, function () { this.cursor = 'initial'; this.variable.isResizing = false; }); - this.view_.on(GEDragHelper.types.MOVE, function(evt) { + this.view_.on(GEDragHelper.types.MOVE, function (evt) { if (Entry.type !== 'workspace' || this.variable.isResizing) { return; } @@ -122,12 +149,12 @@ class ListVariable extends Variable { this.scrollButton_.y = 25; this.scrollButton_.list = this; - this.scrollButton_.on(GEDragHelper.types.DOWN, function(evt) { + this.scrollButton_.on(GEDragHelper.types.DOWN, function (evt) { // if(Entry.type != 'workspace') return; this.list.isResizing = true; this.offsetY = evt.stageY - this.y / 0.75; }); - this.scrollButton_.on(GEDragHelper.types.MOVE, function(evt) { + this.scrollButton_.on(GEDragHelper.types.MOVE, function (evt) { // if(Entry.type != 'workspace') return; const stageY = evt.stageY; @@ -200,6 +227,7 @@ class ListVariable extends Variable { this.array_.push({ data: value, }); + this._trimToMaxLength(); this.updateView(); } else { return new Promise(async (resolve, reject) => { @@ -256,6 +284,7 @@ class ListVariable extends Variable { insertValue(index, data) { if (!this.isRealTime_) { this.array_.splice(index - 1, 0, { data }); + this._trimToMaxLength(); this.updateView(); } else { return new Promise(async (resolve, reject) => { diff --git a/src/class/variable_container.js b/src/class/variable_container.js index 36d9a29605..2b44250c3a 100644 --- a/src/class/variable_container.js +++ b/src/class/variable_container.js @@ -3053,6 +3053,11 @@ Entry.VariableContainer = class VariableContainer { if (value >= limitValue) { value = limitValue; + Entry.toast?.alert( + Lang?.Workspace?.list_cant_add_item || 'Warning', + Lang?.Workspace?.list_max_length_exceeded || + 'You can add up to 5,000 items to a list.' + ); } Entry.do('listChangeLength', v.id_, Number(value)); @@ -3079,6 +3084,11 @@ Entry.VariableContainer = class VariableContainer { const selectedLength = array_.length; if (selectedLength >= limitValue) { + Entry.toast?.alert( + Lang?.Workspace?.list_cant_add_item || 'Warning', + Lang?.Workspace?.list_max_length_exceeded || + 'You can add up to 5,000 items to a list.' + ); Entry.do('listChangeLength', id_, ''); } else { Entry.do('listChangeLength', id_, 'plus');