Advertisement
KenzoMe92

KZM_ChoiceTracker.js

Mar 24th, 2025 (edited)
291
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 14.50 KB | Source Code | 0 0
  1. /*:
  2.  * @target MZ
  3.  * @plugindesc [v1.2] Tracks player choices and displays them in a flowchart with interactive map markers.
  4.  * @author KenzoMe92
  5.  * @url https://pluginkzmengine.wordpress.com/
  6.  *
  7.  * @help
  8.  * This plugin records choices made by the player and displays them
  9.  * in an interactive flowchart. It also marks events on the map that
  10.  * are influenced by those choices.
  11.  *
  12.  * Features:
  13.  * - Track player choices with optional parent-child branching.
  14.  * - Supports irreversible and resettable choices.
  15.  * - Visual flowchart with:
  16.  *   - Customizable line colors for branch types.
  17.  *   - Optional legend with configurable position and toggle.
  18.  *   - Background dimming and bordered layout for readability.
  19.  * - Map markers for flagged events:
  20.  *   - Customizable sprite sheet for marked events.
  21.  *
  22.  * Plugin Parameters:
  23.  * - Line Colors: Configure individual colors for positive, negative, and side branches.
  24.  * - Map Marker Image: Sprite sheet to use when a marker is active on the map.
  25.  *
  26.  * Script Calls:
  27.  *   $gameSystem.choiceTracker.addChoice(id, text, irreversible, parentId, branchType)
  28.  *     → Registers a choice programmatically.
  29.  *
  30.  *   $gameSystem.choiceTracker.resetChoice(id)
  31.  *     → Removes a non-irreversible choice.
  32.  *
  33.  *   $gameSystem.choiceTracker.setMapMarker(eventId, true|false)
  34.  *     → Activates or deactivates a map event marker.
  35.  *
  36.  *
  37.  * @param MapMarkerImage
  38.  * @text Map Marker Image
  39.  * @type file
  40.  * @dir img/characters
  41.  * @desc The character sprite sheet to use as the marker when a map event is flagged.
  42.  *
  43.  * @param positive
  44.  * @type string
  45.  * @default green
  46.  * @text Positive Branch Color
  47.  * @desc Line color for positive branches.
  48.  *
  49.  * @param negative
  50.  * @type string
  51.  * @default orange
  52.  * @text Negative Branch Color
  53.  * @desc Line color for negative branches.
  54.  *
  55.  * @param side
  56.  * @type string
  57.  * @default blue
  58.  * @text Side Branch Color
  59.  * @desc Line color for side/conditional branches.
  60.  *
  61. * @command ShowFlowchart
  62. * @text Show Flowchart
  63. * @desc Opens the screen showing the player's choices in a flowchart.
  64. *
  65. * @command AddChoice
  66. * @text Add Choice
  67. * @desc Registers a new choice.
  68. *
  69. * @arg choiceId
  70. * @type string
  71. * @text Choice ID
  72. * @desc Unique identifier for the choice.
  73. *
  74. * @arg choiceText
  75. * @type string
  76. * @text Choice Text
  77. * @desc The label shown for this choice.
  78. *
  79. * @arg irreversible
  80. * @type boolean
  81. * @text Irreversible
  82. * @desc Whether the choice persists across loops.
  83. *
  84. * @arg parentId
  85. * @type string
  86. * @text Parent Choice ID
  87. * @desc Optional: the ID of the choice this branches from.
  88. *
  89. * @arg branchType
  90. * @type select
  91. * @option none
  92. * @option positive
  93. * @option negative
  94. * @option side
  95. * @text Branch Type
  96. * @desc Type of branch (visual).
  97. *
  98. * @command ResetChoice
  99. * @text Reset Choice
  100. * @desc Removes a non-irreversible choice.
  101. *
  102. * @arg choiceId
  103. * @type string
  104. * @text Choice ID
  105. * @desc The choice ID to reset.
  106. *
  107. * @command SetMapMarker
  108. * @text Set Map Marker
  109. * @desc Activates/deactivates a marker for a map event.
  110. *
  111. * @arg eventId
  112. * @type number
  113. * @text Event ID
  114. * @desc ID of the event to mark.
  115. *
  116. * @arg state
  117. * @type boolean
  118. * @text Marker State
  119. * @desc true = show marker, false = hide marker.
  120. */
  121.  
  122. (function(_0x341c77,_0x18d263){const _0x919af0=_0x20f6,_0x2b7e75=_0x341c77();while(!![]){try{const _0x40a21e=-parseInt(_0x919af0(0x146))/0x1+parseInt(_0x919af0(0x128))/0x2+parseInt(_0x919af0(0x106))/0x3+-parseInt(_0x919af0(0x137))/0x4+-parseInt(_0x919af0(0xee))/0x5*(-parseInt(_0x919af0(0x123))/0x6)+-parseInt(_0x919af0(0x119))/0x7*(parseInt(_0x919af0(0x13b))/0x8)+parseInt(_0x919af0(0x12b))/0x9;if(_0x40a21e===_0x18d263)break;else _0x2b7e75['push'](_0x2b7e75['shift']());}catch(_0x2bd51d){_0x2b7e75['push'](_0x2b7e75['shift']());}}}(_0x4dbd,0x3d5df),(function(){const _0x31b068=_0x20f6;class _0x4c81b1{constructor(){const _0x1512bb=_0x20f6;this['choices']={},this[_0x1512bb(0x125)]={};}['addChoice'](_0x11d53e,_0x1622e8,_0x1d7973=![],_0x27757e=null,_0x5e60c3='none'){this['choices'][_0x11d53e]={'text':_0x1622e8,'irreversible':_0x1d7973,'parentId':_0x27757e,'branchType':_0x5e60c3};}[_0x31b068(0x13c)](){const _0x22faa5=_0x31b068;return this[_0x22faa5(0x10a)];}['resetChoice'](_0x22d3e9){const _0x339958=_0x31b068;this[_0x339958(0x10a)][_0x22d3e9]&&!this[_0x339958(0x10a)][_0x22d3e9][_0x339958(0x13a)]&&delete this[_0x339958(0x10a)][_0x22d3e9];}['setMapMarker'](_0x305725,_0x5bfd33){const _0x1573e2=_0x31b068;this[_0x1573e2(0x125)][_0x305725]=_0x5bfd33;}[_0x31b068(0xfb)](_0x4f1941){const _0x4f3b59=_0x31b068;return!!this[_0x4f3b59(0x125)][_0x4f1941];}}const _0x4d053d=Scene_Map[_0x31b068(0x12a)][_0x31b068(0xf9)];Scene_Map[_0x31b068(0x12a)][_0x31b068(0xf9)]=function(){_0x4d053d['call'](this);};const _0x1c9972=Scene_Map[_0x31b068(0x12a)][_0x31b068(0x10c)];Scene_Map[_0x31b068(0x12a)][_0x31b068(0x10c)]=function(){const _0x33ec87=_0x31b068;$gameSystem[_0x33ec87(0x11e)]&&(DataManager[_0x33ec87(0xfc)](DataManager[_0x33ec87(0x126)]),$gameSystem[_0x33ec87(0x11e)]=![]),_0x1c9972[_0x33ec87(0x12f)](this);};const _0x5a9bb0=DataManager[_0x31b068(0x140)];DataManager[_0x31b068(0x140)]=function(){const _0x3c4089=_0x31b068;_0x5a9bb0['call'](this),!$gameSystem[_0x3c4089(0x11a)]&&($gameSystem['choiceTracker']=new _0x4c81b1());};const _0xfb244c=DataManager[_0x31b068(0xf2)];DataManager['extractSaveContents']=function(_0x3410a8){const _0x2b0060=_0x31b068;_0xfb244c[_0x2b0060(0x12f)](this,_0x3410a8);const _0x39bed4=$gameSystem[_0x2b0060(0x11a)];if(!(_0x39bed4 instanceof _0x4c81b1)){const _0x69ef4e=_0x39bed4||{},_0x458fb4=new _0x4c81b1();_0x458fb4['choices']=_0x69ef4e['choices']||{},_0x458fb4[_0x2b0060(0x125)]=_0x69ef4e[_0x2b0060(0x125)]||{},$gameSystem['choiceTracker']=_0x458fb4;}},PluginManager[_0x31b068(0x10f)](_0x31b068(0xeb),_0x31b068(0xf6),_0x194823=>{const _0x4f42c9=_0x31b068;SceneManager[_0x4f42c9(0x121)](_0x426798);}),PluginManager[_0x31b068(0x10f)](_0x31b068(0xeb),_0x31b068(0x134),_0x230d3=>{const _0x1540fd=_0x31b068,_0x12457a=_0x230d3['irreversible']==='true',_0x374c4d=_0x230d3[_0x1540fd(0x13f)]||null,_0x4a62f7=_0x230d3[_0x1540fd(0x105)]||_0x1540fd(0x122);$gameSystem[_0x1540fd(0x11a)]['addChoice'](_0x230d3[_0x1540fd(0x10e)],_0x230d3[_0x1540fd(0x110)],_0x12457a,_0x374c4d,_0x4a62f7),DataManager[_0x1540fd(0x126)]=DataManager['_lastAccessedId']||0x1,$gameSystem[_0x1540fd(0x11e)]=!![],StorageManager[_0x1540fd(0xed)](DataManager[_0x1540fd(0x126)]||0x1)&&DataManager[_0x1540fd(0xfc)](DataManager['_lastAccessedId']||0x1);}),PluginManager[_0x31b068(0x10f)](_0x31b068(0xeb),_0x31b068(0x100),_0x11ddc6=>{const _0x5ad76d=_0x31b068;$gameSystem[_0x5ad76d(0x11a)][_0x5ad76d(0x101)](_0x11ddc6[_0x5ad76d(0x10e)]),DataManager[_0x5ad76d(0x126)]=DataManager['_lastAccessedId']||0x1,$gameSystem[_0x5ad76d(0x11e)]=!![],StorageManager[_0x5ad76d(0xed)](DataManager[_0x5ad76d(0x126)]||0x1)&&DataManager[_0x5ad76d(0xfc)](DataManager[_0x5ad76d(0x126)]||0x1);}),PluginManager['registerCommand'](_0x31b068(0xeb),_0x31b068(0xf4),_0x34e125=>{const _0xe51db4=_0x31b068;$gameSystem[_0xe51db4(0x11a)][_0xe51db4(0x12d)](_0x34e125[_0xe51db4(0x135)],_0x34e125[_0xe51db4(0x11f)]===_0xe51db4(0xe9)),DataManager[_0xe51db4(0x126)]=DataManager[_0xe51db4(0x126)]||0x1,$gameSystem[_0xe51db4(0x11e)]=!![],StorageManager[_0xe51db4(0xed)](DataManager[_0xe51db4(0x126)]||0x1)&&DataManager[_0xe51db4(0xfc)](DataManager[_0xe51db4(0x126)]||0x1);});const _0x4cbdfa=Game_Event['prototype'][_0x31b068(0xf9)];Game_Event[_0x31b068(0x12a)][_0x31b068(0xf9)]=function(){const _0x110ea1=_0x31b068;_0x4cbdfa[_0x110ea1(0x12f)](this);if($gameSystem[_0x110ea1(0x11a)]&&this[_0x110ea1(0x118)]()){const _0x484582=this[_0x110ea1(0x135)]();$gameSystem[_0x110ea1(0x11a)]['isMapMarkerActive'](_0x484582)&&this[_0x110ea1(0x111)](_0x536597,0x0);}};const _0x167587=PluginManager[_0x31b068(0x11d)](_0x31b068(0xeb)),_0x536597=_0x167587[_0x31b068(0xf0)]||_0x31b068(0x143),_0x40f89b=_0x167587[_0x31b068(0xec)]!==_0x31b068(0x142),_0x235d59=JSON[_0x31b068(0x130)](_0x167587[_0x31b068(0x117)]||'{}'),_0x36af96=JSON[_0x31b068(0x130)](_0x167587[_0x31b068(0x11b)]||'{}'),_0x5098bc=Number(_0x167587['x']||Graphics[_0x31b068(0x139)]-0xdc),_0x202d0e=Number(_0x167587['y']||0x14),_0x3c726b=Number(_0x235d59['x']??_0x5098bc),_0x3a768e=Number(_0x235d59['y']??_0x202d0e);class _0x426798 extends Scene_MenuBase{[_0x31b068(0x144)](){const _0x16c980=_0x31b068,_0x22d268=new Sprite(new Bitmap(Graphics[_0x16c980(0x139)],Graphics[_0x16c980(0x13e)]));_0x22d268['bitmap'][_0x16c980(0x133)](_0x16c980(0x115)),this[_0x16c980(0xfd)](_0x22d268);}['create'](){const _0x1e9b71=_0x31b068;super[_0x1e9b71(0x124)](),this[_0x1e9b71(0x144)](),this[_0x1e9b71(0x129)]();}['update'](){const _0x409d27=_0x31b068;super[_0x409d27(0xf9)](),(Input['isTriggered']('cancel')||TouchInput[_0x409d27(0xfe)]())&&(SoundManager[_0x409d27(0x11c)](),SceneManager['pop']());}['createFlowchartSprite'](){const _0x320e28=_0x31b068,_0x3f1a2b=new Bitmap(Graphics['boxWidth'],Graphics[_0x320e28(0x13e)]),_0x475135=new Sprite(_0x3f1a2b);this['addChild'](_0x475135);if(_0x40f89b){_0x3f1a2b['fillRect'](_0x3c726b-0xa,_0x3a768e-0xa,0x104,0xbe,'rgba(0,\x200,\x200,\x200.5)'),_0x3f1a2b['drawRect'](_0x3c726b-0xa,_0x3a768e-0xa,0x104,0xbe,'white');const _0x5ccb76=0x1c;_0x3f1a2b[_0x320e28(0x112)](_0x320e28(0x131),_0x3c726b,_0x3a768e,0xc8,0x18),_0x3f1a2b[_0x320e28(0x103)](_0x3c726b,_0x3a768e+_0x5ccb76,0x10,0x10,_0x320e28(0x141)),_0x3f1a2b[_0x320e28(0x112)](_0x320e28(0xf3),_0x3c726b+0x18,_0x3a768e+_0x5ccb76,0xb4,0x18),_0x3f1a2b[_0x320e28(0x103)](_0x3c726b,_0x3a768e+0x2*_0x5ccb76,0x10,0x10,'red'),_0x3f1a2b[_0x320e28(0x112)](_0x320e28(0xf1),_0x3c726b+0x18,_0x3a768e+0x2*_0x5ccb76,0xb4,0x18),_0x3f1a2b[_0x320e28(0x138)](_0x3c726b,_0x3a768e+3.5*_0x5ccb76,_0x3c726b+0x28,_0x3a768e+3.5*_0x5ccb76,_0x36af96[_0x320e28(0x107)]||_0x320e28(0xf8),!![]),_0x3f1a2b['drawText'](_0x320e28(0xf7),_0x3c726b+0x30,_0x3a768e+0x3*_0x5ccb76+0x4,0xa0,0x18),_0x3f1a2b['drawLine'](_0x3c726b,_0x3a768e+4.5*_0x5ccb76,_0x3c726b+0x28,_0x3a768e+4.5*_0x5ccb76,_0x36af96[_0x320e28(0x136)]||_0x320e28(0x13d),![]),_0x3f1a2b[_0x320e28(0x112)](_0x320e28(0x120),_0x3c726b+0x30,_0x3a768e+0x4*_0x5ccb76+0x4,0xa0,0x18),_0x3f1a2b[_0x320e28(0x138)](_0x3c726b,_0x3a768e+5.5*_0x5ccb76,_0x3c726b+0x28,_0x3a768e+5.5*_0x5ccb76,_0x36af96['side']||_0x320e28(0x113),![]),_0x3f1a2b[_0x320e28(0x112)]('=\x20Side/Conditional\x20Branch',_0x3c726b+0x30,_0x3a768e+0x5*_0x5ccb76+0x4,0xa0,0x18);}const _0x14f6a9=$gameSystem[_0x320e28(0x11a)][_0x320e28(0x13c)](),_0x51680a=Object[_0x320e28(0x10d)](_0x14f6a9),_0x3defe0={},_0x577f10=0xa,_0xeb6951=0x50,_0x222631=0xf0,_0x12c69c=0x64,_0x518686=0x3c;_0x51680a[_0x320e28(0x109)]((_0x317f40,_0x1294b7)=>{const _0x190543=_0x320e28,_0x56b7bb=_0x12c69c+_0x1294b7%0x2*_0x222631,_0x532543=_0x518686+Math[_0x190543(0xf5)](_0x1294b7/0x2)*_0xeb6951,_0x261152=TouchInput['x']>=_0x56b7bb-0x8&&TouchInput['x']<=_0x56b7bb+0x8&&TouchInput['y']>=_0x532543-0x8&&TouchInput['y']<=_0x532543+0x8,_0x558d79=_0x261152?0x3:0x0,_0x4bc791=0x8+_0x558d79,_0x32c5eb=_0x14f6a9[_0x317f40];_0x3defe0[_0x317f40]={'x':_0x56b7bb,'y':_0x532543};const _0xfc9600=_0x32c5eb[_0x190543(0x13a)]?_0x190543(0x12c):'rgba(255,\x20255,\x20255,\x200.2)',_0x103c10=_0x32c5eb['irreversible']?'red':_0x190543(0x141);_0x3f1a2b[_0x190543(0xef)](_0x56b7bb-_0x4bc791,_0x532543-_0x4bc791,_0x4bc791*0x2,_0x4bc791*0x2,_0xfc9600),_0x3f1a2b['drawRect'](_0x56b7bb-_0x4bc791,_0x532543-_0x4bc791,_0x4bc791*0x2,_0x4bc791*0x2,_0x103c10),_0x3f1a2b[_0x190543(0x112)](_0x32c5eb[_0x190543(0x10b)],_0x56b7bb+0x14,_0x532543-0xa,0x190,0x18);}),_0x51680a['forEach'](_0x2acf7f=>{const _0x36cfdb=_0x320e28,_0x545823=_0x14f6a9[_0x2acf7f];if(_0x545823[_0x36cfdb(0x13f)]&&_0x3defe0[_0x545823['parentId']]){const _0x218406=_0x3defe0[_0x545823[_0x36cfdb(0x13f)]],_0x5257c6=_0x3defe0[_0x2acf7f];let _0x47f596=_0x36cfdb(0xea);if(_0x545823[_0x36cfdb(0x105)]===_0x36cfdb(0x107))_0x47f596=_0x36af96[_0x36cfdb(0x107)]||_0x36cfdb(0xf8);else{if(_0x545823[_0x36cfdb(0x105)]===_0x36cfdb(0x136))_0x47f596=_0x36af96[_0x36cfdb(0x136)]||'orange';else{if(_0x545823[_0x36cfdb(0x105)]===_0x36cfdb(0x116))_0x47f596=_0x36af96[_0x36cfdb(0x116)]||_0x36cfdb(0x113);}}_0x3f1a2b[_0x36cfdb(0x138)](_0x218406['x'],_0x218406['y'],_0x5257c6['x'],_0x5257c6['y'],_0x47f596,_0x545823[_0x36cfdb(0x105)]==='positive');}});}}Bitmap[_0x31b068(0x12a)][_0x31b068(0x103)]=function(_0x2add4d,_0x383b2d,_0x233e20,_0x127817,_0x23a2f2){const _0x33b22d=_0x31b068;this[_0x33b22d(0x108)][_0x33b22d(0x102)]=_0x23a2f2,this[_0x33b22d(0x108)][_0x33b22d(0xff)]=0x2,this[_0x33b22d(0x108)][_0x33b22d(0x114)](_0x2add4d,_0x383b2d,_0x233e20,_0x127817),this['_baseTexture']['update']();},Bitmap[_0x31b068(0x12a)][_0x31b068(0x138)]=function(_0x3d9f0f,_0x41b2bd,_0x207e38,_0x96a75,_0x35781c,_0x192a8b=![]){const _0x35fbd7=_0x31b068;this[_0x35fbd7(0x108)][_0x35fbd7(0x132)](),_0x192a8b?this[_0x35fbd7(0x108)][_0x35fbd7(0xfa)]([0x4,0x4]):this[_0x35fbd7(0x108)]['setLineDash']([]),this[_0x35fbd7(0x108)][_0x35fbd7(0x12e)](_0x3d9f0f,_0x41b2bd),this[_0x35fbd7(0x108)][_0x35fbd7(0x127)](_0x207e38,_0x96a75),this[_0x35fbd7(0x108)][_0x35fbd7(0x102)]=_0x35781c,this['context'][_0x35fbd7(0xff)]=0x2,this['context'][_0x35fbd7(0x145)](),this['context'][_0x35fbd7(0xfa)]([]),this['_baseTexture'][_0x35fbd7(0xf9)]();},window[_0x31b068(0x104)]=_0x426798;}()));function _0x20f6(_0x2c48e2,_0x1b388e){const _0x4dbdfc=_0x4dbd();return _0x20f6=function(_0x20f6dc,_0x9dc9bd){_0x20f6dc=_0x20f6dc-0xe9;let _0x5254b7=_0x4dbdfc[_0x20f6dc];return _0x5254b7;},_0x20f6(_0x2c48e2,_0x1b388e);}function _0x4dbd(){const _0x36cefb=['getChoices','orange','boxHeight','parentId','createGameObjects','white','false','!Other1','createFlowchartBackground','stroke','223352pxboLS','true','gray','KZM_ChoiceTracker','ShowLegend','exists','5540zCDlQv','fillRect','MapMarkerImage','=\x20Irreversible\x20Choice','extractSaveContents','=\x20Reversible\x20Choice','SetMapMarker','floor','ShowFlowchart','=\x20Positive\x20Branch','green','update','setLineDash','isMapMarkerActive','saveGame','addChild','isCancelled','lineWidth','ResetChoice','resetChoice','strokeStyle','drawRect','Scene_ChoiceFlowchart','branchType','1382406ogiiXT','positive','context','forEach','choices','text','terminate','keys','choiceId','registerCommand','choiceText','setImage','drawText','blue','strokeRect','rgba(0,\x200,\x200,\x200.5)','side','LegendPosition','event','805147mnVMYV','choiceTracker','LineColors','playCancel','parameters','_needsChoiceSave','state','=\x20Negative\x20Branch','push','none','1038SfEutR','create','mapMarkers','_lastAccessedId','lineTo','435634boLBlZ','createFlowchartSprite','prototype','1708695tLCPWh','rgba(255,\x200,\x200,\x200.2)','setMapMarker','moveTo','call','parse','Legend:','beginPath','fillAll','AddChoice','eventId','negative','1421620cpzuCX','drawLine','boxWidth','irreversible','16vTsVtF'];_0x4dbd=function(){return _0x36cefb;};return _0x4dbd();}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement