/*
* @title 近接戦闘マスター
* @description アイコンサイズを小さくして近接戦闘を非運ゲー化する
* @private
*/
javascript:(function(){
const cvs = document.querySelector('canvas');
if(!cvs) return;
const ctx = cvs.getContext('2d');
/* --- 設定値 --- */
const ICON_CHAR_SCALE = 0.4; /* アイコン内の絵文字・文字の大きさ */
const ICON_RADIUS_SCALE = 0.5; /* アイコンの円自体の大きさ */
const LINE_SCALE = 0.4; /* 線の太さ */
/* 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, counterclockwise) {
let r = radius;
/* プレイヤー本体の円(だいたい10〜30px)を縮小 */
if (radius > 5 && radius < 40) r = radius * ICON_RADIUS_SCALE;
return originalArc.call(this, x, y, r, sAngle, eAngle, counterclockwise);
};
/* 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_RADIUS_SCALE, nDH = dh * ICON_RADIUS_SCALE;
let nDX = dx + (dw - nDW) / 2, nDY = dy + (dh - nDH) / 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;
/* 判定ロジック:
1. 文字数が2文字以内(絵文字や短いID)
2. または、明らかにフォントサイズが大きい(アイコン内用)
これに該当する場合のみ小さくする
*/
const fontSize = parseFloat(oldFont) || 0;
const isIconChar = text.length <= 2 || fontSize > 16;
if (isIconChar) {
this.font = oldFont.replace(/(\d+)px/, (match, size) => {
return (parseFloat(size) * ICON_CHAR_SCALE) + 'px';
});
}
/* 名前(3文字以上など)の場合は oldFont のまま描画される */
const result = originalFillText.apply(this, arguments);
this.font = oldFont;
return result;
};
console.log('視界確保パッチ(名前維持版):適用完了');
})();