@@ -9,8 +9,8 @@
const ctx = cvs.getContext('2d');
/* --- 設定値 --- */
- const ICON_SCALE = 0.4; /* アイコン本体・絵文字のサイズ */
- const LINE_SCALE = 0.4; /* 線の太さ */
+ const ICON_SCALE = 0.6; /* アイコン本体・絵文字のサイズ */
+ const LINE_SCALE = 0.6; /* 線の太さ */
/* 最後に描画されたアイコン(arc)の座標を記録する変数 */
let lastArcX = 0;
@@ -76,5 +76,4 @@
};
console.log('精密座標検知パッチ:稼働中');
- alert('【修正完了】\n名前が1文字でも大丈夫です!\nアイコンに重なる文字だけを小さくし、名前のサイズは維持します。');
})();
/*
* @title 近接戦闘マスター
* @description アイコンサイズを小さくして近接戦闘を非運ゲー化する
* @private
*/
javascript:(function(){
const cvs = document.querySelector('canvas');
if(!cvs) return;
const ctx = cvs.getContext('2d');
/* --- 設定値 --- */
const ICON_SCALE = 0.6; /* アイコン本体・絵文字のサイズ */
const LINE_SCALE = 0.6; /* 線の太さ */
/* 最後に描画されたアイコン(arc)の座標を記録する変数 */
let lastArcX = 0;
let lastArcY = 0;
/* 1. 線の太さをハック */
const originalStroke = ctx.stroke;
ctx.stroke = function() {
const oldWidth = this.lineWidth;
if (oldWidth > 2) this.lineWidth = oldWidth * LINE_SCALE;
const result = originalStroke.apply(this, arguments);
this.lineWidth = oldWidth;
return result;
};
/* 2. アイコン(円)の座標を記録しつつ縮小 */
const originalArc = ctx.arc;
ctx.arc = function(x, y, radius, sAngle, eAngle, counter) {
let r = radius;
if (radius > 5 && radius < 40) {
r = radius * ICON_SCALE;
/* この座標を記録しておく */
lastArcX = x;
lastArcY = y;
}
return originalArc.call(this, x, y, r, sAngle, eAngle, counter);
};
/* 3. 画像も座標記録しつつ縮小 */
const originalDrawImage = ctx.drawImage;
ctx.drawImage = function(img, sx, sy, sw, sh, dx, dy, dw, dh) {
if (arguments.length >= 9) {
let nDW = dw * ICON_SCALE, nDH = dh * ICON_SCALE;
let nDX = dx + (dw - nDW) / 2, nDY = dy + (dh - nDH) / 2;
/* 中心の座標を記録 */
lastArcX = dx + dw/2;
lastArcY = dy + dh/2;
return originalDrawImage.call(this, img, sx, sy, sw, sh, nDX, nDY, nDW, nDH);
}
return originalDrawImage.apply(this, arguments);
};
/* 4. テキスト:座標がアイコンの中心とほぼ一致する場合のみ縮小 */
const originalFillText = ctx.fillText;
ctx.fillText = function(text, x, y, maxWidth) {
const oldFont = this.font;
/* 判定:今から描く文字のy座標が、直前に描いたアイコンの中心とほぼ同じか?
名前は通常 y-20 とか y+30 とかにオフセットされるので、
差が 5px 以内なら「アイコン内の文字」とみなす */
const isInsideIcon = Math.abs(y - lastArcY) < 5;
if (isInsideIcon) {
this.font = oldFont.replace(/(\d+)px/, (match, size) => {
return (parseFloat(size) * ICON_SCALE) + 'px';
});
/* アイコン内の文字は、小さくなった円の中心に合うよう座標も微調整 */
}
const result = originalFillText.apply(this, arguments);
this.font = oldFont;
return result;
};
console.log('精密座標検知パッチ:稼働中');
})();