This commit is contained in:
恍兮惚兮 2024-05-05 20:53:51 +08:00
parent 7bdfeae9a7
commit 15849bd1a1

View File

@ -1,109 +1,107 @@
var fontface=''; var fontface = '';
var magicsend='\x01LUNAFROMJS\x01' var magicsend = '\x01LUNAFROMJS\x01'
var magicrecv='\x01LUNAFROMHOST\x01' var magicrecv = '\x01LUNAFROMHOST\x01'
function splitfonttext(transwithfont){ function splitfonttext(transwithfont) {
if(transwithfont.substr(0,magicsend.length)==magicsend) //not trans if (transwithfont.substr(0, magicsend.length) == magicsend) //not trans
{ {
split=transwithfont.search('\x02') split = transwithfont.search('\x02')
return transwithfont.substr(split+1); return transwithfont.substr(split + 1);
} }
else if(transwithfont.substr(0,magicrecv.length)==magicrecv) else if (transwithfont.substr(0, magicrecv.length) == magicrecv) {
{ transwithfont = transwithfont.substr(magicrecv.length)
transwithfont=transwithfont.substr(magicrecv.length)
//magic font \x02 text //magic font \x02 text
split=transwithfont.search('\x02') split = transwithfont.search('\x02')
fontface=transwithfont.substr(0,split) fontface = transwithfont.substr(0, split)
text=transwithfont.substr(split+1) text = transwithfont.substr(split + 1)
return text; return text;
} }
else{ else {
return transwithfont; return transwithfont;
} }
} }
function clipboardsender(s,lpsplit){ function clipboardsender(s, lpsplit) {
lpsplit = typeof lpsplit !== 'undefined' ? lpsplit : 0 lpsplit = typeof lpsplit !== 'undefined' ? lpsplit : 0
//magic split \x02 text //magic split \x02 text
s=magicsend+lpsplit.toString()+'\x02'+s; s = magicsend + lpsplit.toString() + '\x02' + s;
try{ try {
const _clipboard = require('nw.gui').Clipboard.get(); const _clipboard = require('nw.gui').Clipboard.get();
_clipboard.set(s, 'text'); _clipboard.set(s, 'text');
transwithfont=_clipboard.get('text'); transwithfont = _clipboard.get('text');
} }
catch(err){ catch (err) {
try{ try {
const clipboard = require('electron').clipboard; const clipboard = require('electron').clipboard;
clipboard.writeText(s); clipboard.writeText(s);
transwithfont= clipboard.readText(); transwithfont = clipboard.readText();
} }
catch(err2){ catch (err2) {
return s; return s;
} }
} }
if(transwithfont.length==0)return s; if (transwithfont.length == 0) return s;
return splitfonttext(transwithfont) return splitfonttext(transwithfont)
} }
function rpgmakerhook(){ function rpgmakerhook() {
if(Window_Message.prototype.originstartMessage)return; if (Window_Message.prototype.originstartMessage) return;
Window_Base.prototype.drawTextEx_origin=Window_Base.prototype.drawTextEx; Window_Base.prototype.drawTextEx_origin = Window_Base.prototype.drawTextEx;
Window_Base.prototype.drawText_origin=Window_Base.prototype.drawText; Window_Base.prototype.drawText_origin = Window_Base.prototype.drawText;
Window_Message.prototype.originstartMessage=Window_Message.prototype.startMessage; Window_Message.prototype.originstartMessage = Window_Message.prototype.startMessage;
Bitmap.prototype.origin_makeFontNameText=Bitmap.prototype._makeFontNameText; Bitmap.prototype.origin_makeFontNameText = Bitmap.prototype._makeFontNameText;
Bitmap.prototype._makeFontNameText=function(){ Bitmap.prototype._makeFontNameText = function () {
if(fontface=='')return this.origin_makeFontNameText(); if (fontface == '') return this.origin_makeFontNameText();
return (this.fontItalic ? 'Italic ' : '') + return (this.fontItalic ? 'Italic ' : '') +
this.fontSize + 'px ' + fontface; this.fontSize + 'px ' + fontface;
} }
Window_Message.prototype.startMessage = function() Window_Message.prototype.startMessage = function () {
{
gametext = $gameMessage.allText(); gametext = $gameMessage.allText();
resp=clipboardsender(gametext); resp = clipboardsender(gametext);
$gameMessage._texts=[resp] $gameMessage._texts = [resp]
this.originstartMessage(); this.originstartMessage();
}; };
Window_Base.prototype.drawText=function(text, x, y, maxWidth, align){ Window_Base.prototype.drawText = function (text, x, y, maxWidth, align) {
text=clipboardsender(text,1) text = clipboardsender(text, 1)
return this.drawText_origin(text,x,y,maxWidth,align) return this.drawText_origin(text, x, y, maxWidth, align)
} }
Window_Base.prototype.drawTextEx=function(text, x, y){ Window_Base.prototype.drawTextEx = function (text, x, y) {
text=clipboardsender(text,1) text = clipboardsender(text, 1)
return this.drawTextEx_origin(text, x, y) return this.drawTextEx_origin(text, x, y)
} }
} }
function tyranohook() { function tyranohook() {
if(tyrano.plugin.kag.tag.text.originstart)return; if (tyrano.plugin.kag.tag.text.originstart) return;
tyrano.plugin.kag.tag.text.originstart=tyrano.plugin.kag.tag.text.start; tyrano.plugin.kag.tag.text.originstart = tyrano.plugin.kag.tag.text.start;
tyrano.plugin.kag.tag.chara_ptext.startorigin=tyrano.plugin.kag.tag.chara_ptext.start; tyrano.plugin.kag.tag.chara_ptext.startorigin = tyrano.plugin.kag.tag.chara_ptext.start;
tyrano.plugin.kag.tag.text.start = function (pm) { tyrano.plugin.kag.tag.text.start = function (pm) {
if (1 != this.kag.stat.is_script && 1 != this.kag.stat.is_html) { if (1 != this.kag.stat.is_script && 1 != this.kag.stat.is_html) {
pm.val=clipboardsender(pm.val); pm.val = clipboardsender(pm.val);
if(fontface!=''){ if (fontface != '') {
this.kag.stat.font.face=fontface this.kag.stat.font.face = fontface
} }
} }
return this.originstart(pm) return this.originstart(pm)
} }
tyrano.plugin.kag.tag.chara_ptext.start = function (pm) { tyrano.plugin.kag.tag.chara_ptext.start = function (pm) {
pm.name=clipboardsender(pm.name,1) pm.name = clipboardsender(pm.name, 1)
return this.startorigin(pm) return this.startorigin(pm)
} }
} }
function retryinject(times){ function retryinject(times) {
if(times==0)return; if (times == 0) return;
try{ try {
if(window.tyrano && tyrano.plugin){ if (window.tyrano && tyrano.plugin) {
tyranohook(); tyranohook();
} }
else if(window.Utils && Utils.RPGMAKER_NAME){ else if (window.Utils && Utils.RPGMAKER_NAME) {
rpgmakerhook(); rpgmakerhook();
} }
else{ else {
setTimeout(retryinject,3000,times-1); setTimeout(retryinject, 3000, times - 1);
} }
} }
catch(err){ catch (err) {
//非主线程甚至没有window对象会弹窗报错 //非主线程甚至没有window对象会弹窗报错
} }
} }