Fukki 7 years ago
parent
commit
510f2aad92
2 changed files with 27 additions and 4 deletions
  1. 26 3
      index.js
  2. 1 1
      manifest.json

+ 26 - 3
index.js

@@ -20,6 +20,24 @@ module.exports = function AutoPOT(mod) {
 				config.notice = !config.notice;
 				msg(`Notice has ${config.notice ? 'Enable' : 'Disable'}.`);
 				break;
+			case 're':
+			case 'load':
+			case 'reload':
+				switch (arg2) {
+					case 'hp':
+						hpPot = getHP();
+						msg(`HP.json has been reloaded.`);
+						break;
+					case 'mp':
+						hpPot = getMP();
+						msg(`MP.json has been reloaded.`);
+						break;
+					case 'config':
+						hpPot = getConfig();
+						msg(`Config.json has been reloaded.`);
+						break;
+				}
+				break;
 			case 'slay':
 			case 'slaying':
 				isSlaying = !isSlaying;
@@ -113,7 +131,7 @@ module.exports = function AutoPOT(mod) {
 	function getConfig() {
 		let data = {};
 		try {
-			data = require('./config.json');
+			data = jsonRequire('./config.json');
 		} catch (e) {
 			data = {
 				enabled: true,
@@ -129,7 +147,7 @@ module.exports = function AutoPOT(mod) {
 	function getHP() {
 		let data = {};
 		try {
-			data = require('./hp.json');
+			data = jsonRequire('./hp.json');
 		} catch (e) {
 			data[6552] = {
 				name: 'Prime Recovery Potable',
@@ -147,7 +165,7 @@ module.exports = function AutoPOT(mod) {
 	function getMP() {
 		let data = {};
 		try {
-			data = require('./mp.json');
+			data = jsonRequire('./mp.json');
 		} catch (e) {
 			data[6562] = {
 				name: 'Prime Replenishment Potable',
@@ -165,6 +183,11 @@ module.exports = function AutoPOT(mod) {
 		cmd.message(msg);
 	}
 	
+	function jsonRequire(p) {
+		delete require.cache[require.resolve(p)];
+		return require(p);
+	}
+	
 	function jsonSort(data, sortby){
 		let key = Object.keys(data).sort(function(a,b) {return parseFloat(data[b][sortby]) - parseFloat(data[a][sortby])});
 		let s2a = []; for(let i = 0; i < key.length; i++) s2a.push([key[i], data[key[i]]]);

+ 1 - 1
manifest.json

@@ -1,6 +1,6 @@
 {
 	"files": {
-		"index.js": "5d4e6e7b1c7cf535da3583b07f20b77a1a2eb529db8ac0873d3dee6f1022aff4"
+		"index.js": "6ae4c23316e604584408b28f5837849e1a74235a951098d320bae124255b206c"
 	},
 	"defs": {
 		"C_USE_ITEM": 3,