//============================================================================= // TRP_ParticleMZ_GroupEditor.js //============================================================================= /*: * @target MZ * @author Thirop * @plugindesc グループ設定の編集[開発用] * @base TRP_ParticleMZ_Group * @orderAfter TRP_ParticleMZ_Group * * @help * 【更新履歴】 * 1.31 2022/01/22 Ctrl+Shift+Sで別名で一度だけ保存する機能の追加 * 1.28 2022/09/11 カーソル位置がずれる不具合修正 * 1.18 2022/02/02 エディタからアツマールにアップロードできない不具合修正 * 1.12 2021/10/23 カーソル位置がずれる不具合修正 * 1.10 2021/09/21 プリセットピッカー呼び出し時の不具合修正 * 1.09 2021/08/18 一覧プラグインが正しく保存されない不具合修正 * 1.06 2021/06/01 デプロイメント時に含まれてると発生する不具合修正 * 1.04 2021/04/19 ペースト操作、スペースキーの不具合修正 * 1.03 2021/04/14 表示の微修正 * 1.01 2021/04/12 sub/edit簡易コマンドの不具合修正 * 1.00 2021/04/10 初版 * * */ //============================================================================= //PRAGMA_END: groupEditorHeader //PRAGMA: englishHeader //PRAGMA_END: englishHeader function ParticleGroupEditor(){ this.initialize.apply(this, arguments); } if (Utils.isNwjs() && Utils.isOptionValid('test')){ //PRAGMA: groupEditorPathSetting ParticleGroupEditor.FILE_PATH = 'dataEx/TrpParticleGroups.json'; ParticleGroupEditor.HELP_PATH = 'js/plugins/TRP_ParticleMZ_List.js'; //PRAGMA_END: groupEditorPathSetting }; ParticleGroupEditor.DEFAULT_DATA = { repeat:-1, list:[''], targetType:0, comment:'', }; (function(){ "use strict"; if (!Utils.isNwjs() || !Utils.isOptionValid('test')){ return; } var fs = require('fs'); var path = require('path'); var base = path.dirname(process.mainModule.filename); var filePath = path.join(base, ParticleGroupEditor.FILE_PATH); if(!fs.existsSync(filePath)){ var defData = JSON.stringify(JsonEx.makeDeepCopy(ParticleGroupEditor.DEFAULT_DATA)); var file = '{"test":'+defData+'}'; fs.writeFileSync(filePath,file); } })(); (function(){ 'use strict'; if (!Utils.isNwjs() || !Utils.isOptionValid('test')){ return; } //PRAGMA: groupEditorPluginNames var parameters = PluginManager.parameters('TRP_ParticleMZ_GroupEditor'); var baseParameters = PluginManager.parameters('TRP_ParticleMZ'); //PRAGMA_END: groupEditorPluginNames var LC = TRP_Localize.localize.bind(TRP_Localize,'parGe'); var NLC = TRP_Localize.noLocalize; var isMac = navigator.userAgent.match(/Macintosh|Mac/); var ParticleGroup = Game_Particle.ParticleGroup; function supplement(defaultValue,optionArg){ if(optionArg === undefined){ return defaultValue; } return optionArg; }; function supplementNum(defaultValue,optionArg){ return Number(supplement(defaultValue,optionArg)); }; var _supplementDefWords = ['default','def','d']; function supplementDef(defaultValue, optionArg, otherWords) { var value = supplement(defaultValue,optionArg); var defTargetWords = otherWords ||[]; if(defTargetWords){ defTargetWords = defTargetWords.concat(_supplementDefWords); }else{ defTargetWords = _supplementDefWords; } var length = defTargetWords.length; for(var i=0; i0){ str += separator; } str += args[i]; } return str; }; Game_Particle.prototype.particleGroupEdit = function(eventId,id,target,tag,name,x,y){ name = supplementDef(id,name)||id; id = this.idWithSuffix(id); var data = this._groups[id]; if(!$dataTrpParticleGroups[name]){ if($dataTrpParticleGroupsPreset[name]){ $dataTrpParticleGroups[name] = JsonEx.makeDeepCopy($dataTrpParticleGroupsPreset[name]); }else{ $dataTrpParticleGroups[name] = JsonEx.makeDeepCopy(ParticleGroupEditor.DEFAULT_DATA); } } if(!data){ this.particleGroupSet(eventId,id,target,tag,name,x,y); data = this._groups[id]; } data.editing = true; SceneManager._scene.startParticleGroupEdit(this,id); return data; }; //============================================================================= // ParticleGroup //============================================================================= var _ParticleGroup_initialize = ParticleGroup.prototype.initialize; ParticleGroup.prototype.initialize = function(eventId,id,target,tag,name,x,y){ this._editing = false; _ParticleGroup_initialize.apply(this,arguments) }; Object.defineProperty(ParticleGroup.prototype, 'editing', { get: function() { return this._editing; },set: function(value){ if(value){ this._editing = true; }else{ delete this._editing; } this.applyData(); }, configurable: true }); var _ParticleGroup_applyData = ParticleGroup.prototype.applyData ParticleGroup.prototype.applyData = function(){ _ParticleGroup_applyData.call(this); if(this.editing){ if(this.repeat<0){ this.repeat = 0; } } }; //============================================================================= // Scenes //============================================================================= Scene_Base.prototype.startParticleGroupEdit = function(particle,id){ if(this._particleGroupEditor){ this.addChild(this._particleGroupEditor); return; } if(!this._particleSystem)return; this._particleGroupEditor = new ParticleGroupEditor(particle,id); this.addChild(this._particleGroupEditor); }; var _Scene_Base_startParticleEdit = Scene_Base.prototype.startParticleEdit; Scene_Base.prototype.startParticleEdit = function(particle,id,exData=null){ if(this._particleGroupEditor){ this._particleGroupEditor.willStartParticleEdit(); } _Scene_Base_startParticleEdit.call(this,particle,id,exData); }; var _Scene_Base_update = Scene_Base.prototype.update; Scene_Base.prototype.update = function(){ if(!!this._particleGroupEditor){ if(!!this._particleEditor){ this.updateForParticleEdit(); if(!this._particleEditor){ this._particleGroupEditor.didEndParticleEditing(); } }else{ this.updateForParticleGroupEdit(); } }else{ _Scene_Base_update.call(this); } }; Scene_Base.prototype.updateForParticleGroupEdit = function(){ $gameScreen._particle.update(); this._particleSystem.updateForEditor(this); this._particleGroupEditor.update(); if(this._particleGroupEditor.isTerminated()){ this.removeChild(this._particleGroupEditor); this._particleGroupEditor = null; } }; var _Scene_Map_update = Scene_Map.prototype.update; Scene_Map.prototype.update = function() { if(!!this._particleGroupEditor){ Scene_Base.prototype.update.call(this); this._spriteset._destinationSprite.update(); }else{ _Scene_Map_update.call(this); } }; var _Scene_Battle_update = Scene_Battle.prototype.update; Scene_Battle.prototype.update = function() { if(!!this._particleGroupEditor){ Scene_Base.prototype.update.call(this); }else{ _Scene_Battle_update.call(this); } }; //============================================================================= // ParticleEditor //============================================================================= ParticleGroupEditor.prototype = Object.create(ParticleEditor.prototype); ParticleGroupEditor.prototype.constructor = ParticleGroupEditor; ParticleGroupEditor.GUIDE_TEXTS = { repeat:[LC('【リピート設定】',0),LC('-1:リピート無し',1),LC('0以上:リピートするまでの待機フレーム',2),null,LC('ctrl/cmd+C:グループ全体をコピー',3)], command:[LC('【コマンド】',4),LC('particleを抜かしたコマンドを入力',5),LC('Enter:コマンドを反映',6),LC('Shift+←(→):行頭(行末)へ',7),LC('alt/opt+←(→):前(次)の項目へ',8),LC('alt/opt+↑(↓):上(下)にコマンド挿入',9),null,LC('alt/opt+E(S|P):edit(set,play)切り替え',10),LC('Shift+alt/opt+P:設定名をプリセットから変更',11),LC('Shift+alt/opt+L:設定名を保存データから変更',12)], }; ParticleGroupEditor.prototype.guideTexts = function(title){ if(title.contains('command')){ title = 'command'; } return ParticleGroupEditor.GUIDE_TEXTS[title]; }; Game_Particle.EDITING_GROUP = null; ParticleGroupEditor.prototype.initMembers = function(){ ParticleEditor.prototype.initMembers.call(this); this._isParticleEditing = false; this._isJustParticleEditingDone = false; this._lastList = null; this._lastSubCommand = 'play'; this._presetConfigPicker = null; this._loadConfigPicker = null; }; ParticleGroupEditor.prototype.initialize = function(particle,id){ Game_Particle.GROUP_EDITOR = this; PIXI.Container.call(this); this.initMembers(); this.width = Graphics.width; this.height = Graphics.height; Input.clear(); var data = particle._groups[id]; var config = Game_Particle.groupData(data); if(data.image){ this.checkImageExists(data); }else if(config.image){ this.checkImageExists(config); } data.editing = true; this._id = id; this._particle = particle; this._data = data; this._config = config; this._lastList = data.list.concat(); this.createSelectorSprite(); this.createParts(data,config); this.createMenuButtons(); this.createGuideSprite(); this.registerKeyListeners(); this.resetInputingWords(); this.refreshPartsHidden(); }; ParticleGroupEditor.prototype.terminate = function(){ Game_Particle.GROUP_EDITOR = null; this._terminated = true; if(this._data){ this._data.editing = false; } this._particle = null; this._data = null; this._config = null; this.removeEventListeners(); }; ParticleGroupEditor.prototype.willStartParticleEdit = function(){ this._isParticleEditing = true; this._isJustParticleEditingDone = false; this.visible = false; }; ParticleGroupEditor.prototype.didEndParticleEditing = function(){ this._isParticleEditing = false; this._isJustParticleEditingDone = true; this.visible = true; Input.clear(); TouchInput.clear(); var needsSave = false; var list = this._data.list; var length = list.length; for(var i=0; i=0; i=(i-1)|0){ var command = list[i]; var args = command.split(' '); var sub = ParticleGroup.processParticleSubCommand(args); if(Game_Particle.isPlayCommands(sub)){ var id = args[1]; var match = id?id.match(regExp):null; if(match){ autoNameIdxes = autoNameIdxes||[]; autoNameIdxes.push(Number(match[1])); } } } var autoIndex = 0; if(autoNameIdxes){ autoNameIdxes.sort(function(a,b){ return a-b; }); var length = autoNameIdxes.length; autoIndex = -1; for(var i=0; i=0; i=(i-1)|0){ var command = list[i]; var args = command.split(' '); var sub = ParticleGroup.processParticleSubCommand(args); if(i0){ parts._title = title+(i+1); parts._configNames = ['list.'+i]; parts.y -= deletedNum*parts._height; parts.refreshTitleSprite(); parts.refresh(); } } return deletedNum>0; }; /* parts ===================================*/ ParticleGroupEditor.LINE_MARGIN = 15; ParticleGroupEditor.prototype.createParts = function(data,config){ var title,configNames,headers; var y = 10; title = 'repeat'; configNames = ['repeat']; headers = null; y += this.addValueParts(y,data,config,configNames,title,headers); y += 15; this._commandPartsIdx = this._parts.length; var list = data.list; this.addAllCommmandParts(data,config,list,y); }; ParticleGroupEditor.prototype.addAllCommmandParts = function(data,config,list,y){ var title = ParticleGroupEditor.COMMAND_TITLE; var headers = null; var length = list.length||1; for(var i=0; i0){ texts += '\n'; } var targetType = data.targetType; var comment = data.comment; texts += ' * '+ParticleEditor.helpFileListText(key,targetType,comment); } texts += '\n *'; return texts; }; var _ParticleEditor_helpPluginCommandTexts = ParticleEditor.prototype.helpPluginCommandTexts; ParticleEditor.prototype.helpPluginCommandTexts = function(database){ var texts = _ParticleEditor_helpPluginCommandTexts.call(this,database); texts += '\n *\n *'; texts += ParticleGroupEditor._helpPluginCommandTexts(); return texts; }; ParticleGroupEditor.prototype._helpPluginCommandTexts = function(database = $dataTrpParticleGroups){ var allKeys = Object.keys(database); allKeys.sort(); var length = allKeys.length; var allData = []; var allNames = []; PresetPicker.setCategoriedList(database,allData,allNames); var texts = ''; var categoryLen = allNames.length; for(var i=0; i ',14)+categoryText+'('+keysLen+')'; texts += LC('\n * @desc グループ呼び出し',15); texts += '\n * @arg id'; texts += LC('\n * @text グループ管理ID',16); texts += LC('\n * @desc 他と被らないグループ用管理ID。「def」でIDは設定名、「-EID」で設定名-EID。',17); texts += '\n * @default def'; texts += '\n * @arg target'; texts += LC('\n * @text 対象',18); texts += LC('\n * @desc 対象。this,player,weatherなど。対象をtargetとしたコマンドで有効',19); texts += '\n * @default this'; texts += '\n * @arg name'; texts += LC('\n * @text 《グループ設定名》',20); texts += LC('\n * @desc 呼び出すグループの設定名',21); texts += '\n * @type select'; texts += LC('\n * @default 《呼び出す設定を選択》',22); for(var j = 0; j=2*CommandParam.CURSOR_ANIMATION_BASE){ this._cursorFrame = 0; this._cursorSprite.opacity = 200; }else if(this._cursorFrame===CommandParam.CURSOR_ANIMATION_BASE){ this._cursorSprite.opacity = 100; } }; CommandParam.prototype.createCursorSprite = function(){ var bitmap = CommandParam.CURSOR_BITMAP = new Bitmap(3,ParticleParam.LINE_HEIGHT); bitmap.fillAll('rgb(200,255,255)'); var sprite = new Sprite(bitmap); this._cursorSprite = sprite; return sprite; }; CommandParam.prototype.setCursor = function(index,force){ var sprite = this._cursorSprite; if(this._editingIndex<0){ sprite.visible = false; return; } sprite.visible = true; sprite.opacity = 255; this._cursorFrame = 0; var parts = this._parts[0]; if(!parts || parts.length===0)return; parts.addChild(sprite); index = index.clamp(0,this._inputting.length); if(!force && this._cursorIndex===index)return; this._cursorIndex = index; if(index<0){ sprite.visible = false; return; } var text = this._inputting.substring(0,index); var width = parts.bitmap.measureTextWidth(text); sprite.x = width; }; CommandParam.prototype.setCursorTail = function(force=false){ this.setCursor(this._inputting.length,force); }; CommandParam.prototype.setCursorToNextArg = function(){ var index = this._cursorIndex; var tail = this._inputting.substring(index); if(tail.length===0)return; var args = tail.split(' '); var top = args.shift(); if(!top){ top = args.shift(); index += 1; } index += top.length; this.setCursor(index); }; CommandParam.prototype.setCursorToPreviousArg = function(){ var index = this._cursorIndex; var header = this._inputting.substring(0,index); if(header.length===0)return; var args = header.split(' '); var last = args.pop(); if(!last){ last = args.pop(); index -= 1; } index -= last.length; this.setCursor(index); }; /*===================================*/ CommandParam.prototype.defaultValue = function(){ return ''; }; CommandParam.prototype.isDataInputting = function(){ return this._inputting !== this._savedValue; }; CommandParam.prototype.processInput = function(keyCode,key){ if(Input.isRepeated('left')){ if(this._cursorIndex>0){ if(Input.isPressed('shift')){ this.setCursor(0); }else if(Input.isPressed('control')){ this.setCursorToPreviousArg(); }else{ this.setCursor(this._cursorIndex-1); } } }else if(Input.isRepeated('right')){ if(this._cursorIndex0 && this._cursorIndex>0){ this._inputting = ( this._inputting.substring(0,this._cursorIndex-1) + this._inputting.substring(this._cursorIndex) ); this.applyEditing(); this.setCursor(this._cursorIndex-1); } }else if(Input.isTriggered('ok')){ this._needsSave = true; this.applyEditing(); SoundManager.playCursor(); }else{ return ParticleParam.prototype.processInput.call(this,keyCode,key); } return true; }; CommandParam.prototype.deleteTailArgOfInputting = function(){ var target = this._inputting.substring(0,this._cursorIndex); var tail = this._inputting.substring(this._cursorIndex); var args = target.split(' '); if(args.pop() === ''){ args.pop(); } target = concatToString(args); if(target.length>0){ target += ' '; } this._inputting = target+tail; this.setCursor(target.length); }; CommandParam.prototype.isPlaySomeCommand = function(){ var command = this._inputting; var args = command.split(' '); var sub = ParticleGroup.processParticleSubCommand(args); return Game_Particle.isPlayCommands(sub); }; CommandParam.prototype.isSubSetCommand = function(){ var command = this._inputting; var args = command.split(' '); var sub = ParticleGroup.processParticleSubCommand(args); return sub==='sub'; }; CommandParam.prototype.changeSubCommand = function(value){ var command = this._inputting; var args = command.split(' '); var sub = ParticleGroup.processParticleSubCommand(args); if(!sub || sub===value)return ''; var subIndex = -1; if(Game_Particle.isPlayCommands(sub)){ subIndex = 0; }else if(sub==='sub'){ subIndex = 1; }else{ return false; } var lastSub = args[subIndex]; args[subIndex] = value; this._inputting = concatToString(args);; this._needsSave = true; this.applyEditing(); return lastSub; }; CommandParam.prototype.changePlayCommandConfigName = function(newName){ var command = this._inputting; var args = command.split(' '); var sub = ParticleGroup.processParticleSubCommand(args); if(!sub)return false; if(sub==='sub'){ args[3] = newName; }else{ var id = args[1]; var name = args[3]; if(name && name!=='def'){ //change config name args[3] = newName; }else{ //change id args[1] = newName; if(/-EID$/.test(id)){ args[1] += '-EID'; } } } this._inputting = concatToString(args); this._needsSave = true; this.applyEditing(); return true; }; CommandParam.prototype.changeSubEmitterParams = function(timing,endTiming,speedRate,inheritAngle,inheritScale){ var command = this._inputting; var args = command.split(' '); var sub = ParticleGroup.processParticleSubCommand(args); //sub, edit, id, name, timing, endTiming, speedRate args[4] = String(timing); args[5] = String(endTiming); args[6] = String(speedRate); args[7] = String(inheritAngle); args[8] = String(inheritScale); this._inputting = concatToString(args); this._needsSave = true; this.applyEditing(); return true; }; CommandParam.prototype.clearInputting = function(deleteFlag){ this._lastInputting = this._inputting; this._inputting = this.value(0); this._textsCache.length = 0; this.setCursorTail(); }; CommandParam.prototype._processCharacterInput = function(keyCode,key){ if(keyCode && key && key.length===1){ this._inputting = ( this._inputting.substring(0,this._cursorIndex) + key + this._inputting.substring(this._cursorIndex) ); this.applyEditing(); this.setCursor(this._cursorIndex+1); } }; CommandParam.prototype.addText = function(text){ this._inputting = ( this._inputting.substring(0,this._cursorIndex) + text + this._inputting.substring(this._cursorIndex) ); this.setCursor(this._cursorIndex+text.length) this._needsSave = true; this.applyEditing(); }; CommandParam.prototype.valueWithInputting = function(){ var input = this._inputting; return input; }; CommandParam.prototype.layout = function(){ ParticleParam.prototype.layout.call(this); this._width = this._titleWidth + this.maxPartsWidth(); }; CommandParam.prototype.partsText = function(index){ var text = this._inputting; var header = this.partsHeader(index); if(header){ text = header + ':'+ text; } return text }; CommandParam.prototype.endEditing = function(){ var index = this._editingIndex; if(index<0)return; var value = this.valueWithInputting(); this._needsSave = true; this.applyEditing(); ParticleParam.prototype.endEditing.call(this); this._cursorSprite.visible = false; this._cursorIndex = -1; this._cursorFrame = 0; }; CommandParam.prototype.shouldSave = function(data){ if(!this._needsSave){ return false; } this._needsSave = false; if(this._inputting === this._lastInputting)return false; this._lastInputting = this._inputting; this._needsSave = false; return true; }; CommandParam.prototype.paramSaveData = function(index,value){ var values = this.values(); if(value !== undefined){ values[index] = value; } return values; }; CommandParam.prototype.didSaveParams = function(){ var cursorIndex = this._cursorIndex; this.clearInputting(); this.refresh(); this.setCursor(cursorIndex,true); }; CommandParam.MAX_PARTS_WIDTH = 512; CommandParam.prototype.maxPartsWidth = function(){ return CommandParam.MAX_PARTS_WIDTH; }; CommandParam.prototype.refresh = function(){ ValueParam.prototype.refresh.call(this); this.setCursorTail(true); }; CommandParam.prototype.refreshPartsText = function(sprite,text,i){ var bitmap = sprite.bitmap; if(this.isCommandValid(i)){ if(this._inputting === this._lastInputting){ bitmap.textColor = 'white'; }else{ bitmap.textColor = 'rgb(200,200,255)' } }else{ bitmap.textColor = 'red'; } ParticleParam.prototype.refreshPartsText.apply(this,arguments); bitmap.textColor = 'white'; }; CommandParam.prototype.isCommandValid = function(i){ var index = this.listIndex; var command = this._inputting; var commandValidFunc = ParticleGroup.isCommandTargetIdValid; ParticleGroup.isCommandTargetIdValid = ParticleGroup.isCommandTargetIdValidForEdit.bind(this,this._data.list,index); var ret = ParticleGroup.isCommandValid(command,this._data.id,this._data.name,null); ParticleGroup.isCommandTargetIdValid = commandValidFunc; return ret; }; ParticleGroup.isCommandTargetIdValidForEdit = function(list,index,groupId,groupName,id){ if(id===undefined){ return false; } if(id==='' || id===' '){ return false; } if(id.contains(':')){ return true; } if($gameScreen._particle._data[id+ParticleGroup.idSuffix(groupId)]){ return true; } var length = list.length; for(var i=0; i