/*:
* @plugindesc Adds a tool to the Super Tools Engine that checks for updates on plugins from SumRndmDde's library.
* @author SumRndmDde
* @help
*
* Plugin Updater
* Version 1.21
* SumRndmDde
*
*
* This plugin adds a tool to the Super Tools Engine that checks for updates on
* plugins from SumRndmDde's library.
*
*
* ==============================================================================
* How it Works
* ==============================================================================
*
* This adds the "Plugin Updater" tool. This tool lists out all of the SRD
* plugins installed in the project. It gives their current version in the
* project and the latest version available. It also leaves a link to the
* plugin's page for easy accessibility.
*
* The plugin also notifies the developer if an update is available for a
* plugin. The description for the tool will inform the developer if any plugins
* have new updates. Furthermore, the plugins with updates available will have
* a red "N" next to them in the list.
*
* Once the desired plugins are updated, one may reload the game to make sure
* the plugins have been registered as updated.
*
*
* ==============================================================================
* End of Help File
* ==============================================================================
*
* Welcome to the bottom of the Help file.
*
*
* Thanks for reading!
* If you have questions, or if you enjoyed this Plugin, please check
* out my YouTube channel!
*
* https://www.youtube.com/c/SumRndmDde
*
*
* Until next time,
* ~ SumRndmDde
*
*/
/*:ja
* @plugindesc SumRndmDde のライブラリからプラグインの更新をチェックするツールを Super Tools Engine に追加します。
* @author SumRndmDde
* @help
* 翻訳:ムノクラ
* https://fungamemake.com/
* https://twitter.com/munokura/
*
* 元プラグイン: http://sumrndm.site/plugin-updater/
*
*
* Plugin Updater
* Version 1.21
* SumRndmDde
*
*
* SumRndmDdeのライブラリからプラグインの更新をチェックするツールを
* Super Tools Engineに追加します。
*
* このプラグインを使用するにはSRD_SuperToolsEngineが必要です。
* プラグイン管理でこのプラグインを
* SRD_SuperToolsEngineの下側に配置してください。
*
* テストプレイ中にF12を押してテストプレイエディタから使用します。
*
*
* ==========================================================================
* 機能概要
* ==========================================================================
*
* "Plugin Updater"ツールが追加されます。
* このツールは、
* プロジェクトにインストールされている全てのSRDプラグインをリストアップします。
* プロジェクトにインストールされているプラグインの現在のバージョンと、
* 利用可能な最新バージョンが表示されます。
* また、簡単にアクセスできるようにプラグインのページへのリンクを表示します。
*
* また、プラグインにアップデートがある場合は開発者に通知します。
* ツールの説明では、
* プラグインに新しいアップデートがあるかどうかを開発者に通知します。
* さらに、アップデートが利用可能なプラグインには、
* リストの横に赤い'N'が表示されます。
*
* 目的のプラグインが更新されたら、
* プラグインが更新されたと登録されていることを確認するために
* ゲームをリロードすることができます。
*
*
* ==========================================================================
* ヘルプファイルの終わり
* ==========================================================================
*
* ヘルプファイルの終わりへようこそ。
*
* 読んでくれてありがとう!
* 質問があったり、このプラグインを楽しめたら、
* 私のYouTubeチャンネルを登録してください!!
*
* https://www.youtube.com/c/SumRndmDde
*
*
* 次の機会まで
* ~ SumRndmDde
*
*/
var SRD = SRD || {};
SRD.PluginUpdater = SRD.PluginUpdater || {};
var Imported = Imported || {};
Imported["SumRndmDde Plugin Updater"] = 1.21;
function PluginUpdateManager() {
throw new Error('PluginUpdateManager is a static class! You\'ll learn lots about electricity there!');
}
(function (_) {
"use strict";
if (!SRD.SuperToolsEngine.isPlaytest) return;
_.description = "A tool that checks for updates for SumRndmDde's plugins.";
_.alertNeedSuperToolsEngine = function (update) {
if (update) {
alert("The 'SRD_SuperToolsEngine' needs to be version 1.11 or greater to use the 'SRD_PluginUpdater' plugin.");
} else {
alert("The 'SRD_SuperToolsEngine' plugin is required for using the 'SRD_PluginUpdater' plugin.");
}
if (confirm("Do you want to open the download page to 'SRD_SuperToolsEngine'?")) {
window.open('http://sumrndm.site/super-tools-engine/');
}
};
if (!Imported["SumRndmDde Super Tools Engine"]) {
_.alertNeedSuperToolsEngine(false);
return;
} else if (Imported["SumRndmDde Super Tools Engine"] < 1.12) {
_.alertNeedSuperToolsEngine(true);
return;
}
//-----------------------------------------------------------------------------
// MakerManager
//-----------------------------------------------------------------------------
_.MakerManager_assignWindow = MakerManager.assignWindow;
MakerManager.assignWindow = function () {
_.MakerManager_assignWindow.apply(this, arguments);
this._window.window.PluginUpdateManager = PluginUpdateManager;
};
_.MakerManager_getLauncherButtonsRaw = MakerManager.getLauncherButtonsRaw;
MakerManager.getLauncherButtonsRaw = function () {
let result = _.MakerManager_getLauncherButtonsRaw.apply(this, arguments);
result.push(`${this.generateLauncherRow("Plugin Updater", _.description, "PluginUpdateManager.setupWindowHtml()", "#e67300")}`);
return result;
};
_.MakerManager_onFinish = MakerManager.onFinish;
MakerManager.onFinish = function () {
if (this.mode === 'plugin_updater') {
PluginUpdateManager.onFinish();
}
_.MakerManager_onFinish.apply(this, arguments);
};
_.MakerManager_refreshTable = MakerManager.refreshTable;
MakerManager.refreshTable = function () {
_.MakerManager_refreshTable.apply(this, arguments);
const element = this.document.getElementById('LaunchDescription Plugin Updater');
element.innerHTML = '';
if (!PluginUpdateManager._pluginInfo || PluginUpdateManager._pluginInfo.length === 0) {
element.innerHTML = 'It appears no data has been obtained from online. If you are connected, this may be a parsing error. Please try again later!';
} else {
if (PluginUpdateManager._needsUpdate > 1) {
element.innerHTML += `${PluginUpdateManager._needsUpdate} plugins have updates available.
`;
} else if (PluginUpdateManager._needsUpdate === 1) {
element.innerHTML += `1 plugin has an update available.
`;
} else {
element.innerHTML += `All plugins are up to date!
`;
}
element.innerHTML += _.description;
}
};
//-----------------------------------------------------------------------------
// PluginUpdateManager
//-----------------------------------------------------------------------------
PluginUpdateManager._pluginInfo = null;
PluginUpdateManager._needsUpdate = 0;
PluginUpdateManager._internet = false;
PluginUpdateManager._checkComplete = false;
PluginUpdateManager.initManager = function () {
this._listIndex = 0;
this.checkInternet();
};
/*
* Checking Information
*/
PluginUpdateManager.checkInternet = function () {
require('dns').lookup('www.google.com', function (err) {
if (err && err.code == "ENOTFOUND") {
this._internet = false;
} else {
this._internet = true;
}
this._checkComplete = true;
this.checkForUpdates();
}.bind(this));
};
PluginUpdateManager.checkForUpdates = function () {
if (!this._internet) return;
this.getInfo('https://raw.githubusercontent.com/SumRndmDde/PluginUpdater/master/SRD_PluginInfos.json');
this.getLog('https://raw.githubusercontent.com/SumRndmDde/PluginUpdater/master/SRD_PluginLog.json');
};
PluginUpdateManager.getInfo = function (url) {
const xhr = new XMLHttpRequest();
xhr.open('GET', url);
xhr.overrideMimeType('application/json');
xhr.onload = function () {
if (xhr.status < 400) {
this.storeUpdates(xhr.responseText);
this.applyUpdates();
}
}.bind(this);
xhr.onerror = function () { };
xhr.send();
};
PluginUpdateManager.storeUpdates = function (content) {
try {
this._infos = JsonEx.parse(content);
} catch (e) {
this._infos = {};
}
};
PluginUpdateManager.applyUpdates = function () {
this._pluginInfo = [];
Object.keys(this._infos).forEach(function (key) {
const current = Imported[key];
if (current !== undefined) {
const info = this._infos[key];
const latest = info[0];
const filename = info[1];
const url = info[2];
const newInfo = {
name: key,
filename: filename,
url: url,
current: parseFloat(current) || 1.00,
latest: parseFloat(latest)
};
if (current < latest) {
this._needsUpdate++;
newInfo.needsUpdate = true;
}
this._pluginInfo.push(newInfo);
}
}.bind(this));
this._finished = true;
};
PluginUpdateManager.getLog = function (url) {
const xhr = new XMLHttpRequest();
xhr.open('GET', url);
xhr.overrideMimeType('application/json');
xhr.onload = function () {
if (xhr.status < 400) {
this.storeLog(xhr.responseText);
}
}.bind(this);
xhr.onerror = function () { };
xhr.send();
};
PluginUpdateManager.storeLog = function (content) {
try {
this._log = JsonEx.parse(content);
} catch (e) {
this._log = [
[
"Error",
"0.00",
"There was an error parsing the online data",
"Please try again in an hour or so",
"If the error still persists, please contact SumRndmDde!"
]
]
}
};
/*
* Window Manipulation
*/
PluginUpdateManager.setupWindowHtml = function () {
if (!this._internet) {
alert("No internet connection detected. Please check your connection and try again later.");
return;
}
if (!this._finished) {
alert("Update data has not finished loading. Please try again in a bit.");
return;
}
MakerManager.window.title = "Super Tools Engine - Plugin Updater | SumRndmDde";
MakerManager.mode = 'plugin_updater';
this.setBasicPage();
};
PluginUpdateManager.setBasicPage = function () {
MakerManager.mainHTML = this.topBar(0) + this.getBasicHtml();
this.refreshEverything();
};
PluginUpdateManager.setLogPage = function () {
this._filter = '';
MakerManager.mainHTML = this.topBar(1) + this.getLogHtml();
};
PluginUpdateManager.refreshEverything = function () {
this.refreshTable();
this.refreshPages();
};
PluginUpdateManager.topBar = function (index) {
const active = ['', ''];
active[index] = 'class="active"';
return `
${info[0]}
Version ${info[1]} Update
`; for (let i = 2; i < info.length; i++) { result += ` - ${info[i]}
`; } result += `