座標ズレ修正
by
cutfloss
04/29 [2026/04/29 22:21:36]
PC、タブレットのタップずれ補正し、ブーストボタンを押せるようになる
@@ -3,64 +3,42 @@
* @description 定型文を6つまで編集・保存します
* @private
*/
-(function(){
- const old = document.getElementById('j-editor'); if(old) old.remove();
-
- // デフォルトのセリフ
- const defaultPhrases = ['味方カモン!', '引き付けておいてくれ!', '包囲するぞ!', 'ナイスゥ!!', '敵の潜水艦を発見!', '駄目だ!'];
-
- let saved = localStorage.getItem('j-phrases');
- let phrases = saved ? JSON.parse(saved) : defaultPhrases;
-
- const style = document.createElement('style');
- style.innerHTML = `
- #j-editor { position:fixed; top:50px; right:50px; background:rgba(20,30,50,0.95); border:3px solid #3b82f6; border-radius:10px; padding:15px; z-index:100001; color:#fff; width:300px; box-shadow:0 0 20px #000; }
- .je-line { display:flex; align-items:center; margin-bottom:8px; }
- .je-input { flex:1; background:#000; border:1px solid #60a5fa; color:#fff; padding:8px; border-radius:4px; font-size:12px; }
- .je-footer { display: flex; gap: 8px; margin-top: 10px; }
- .je-btn-save { flex: 2; background:#2563eb; color:#fff; border:none; border-radius:5px; padding:12px; cursor:pointer; font-weight:bold; }
- .je-btn-reset { flex: 1; background:#475569; color:#fff; border:none; border-radius:5px; padding:12px; cursor:pointer; font-size: 11px; }
- .je-btn-close { position:absolute; top:5px; right:5px; background:none; border:none; color:#aaa; cursor:pointer; font-size:16px; }
- `;
- document.head.appendChild(style);
-
- const ed = document.createElement('div'); ed.id = 'j-editor';
- ed.innerHTML = '<button class="je-btn-close" onclick="this.parentNode.remove()">✕</button><div style="text-align:center;font-weight:bold;margin-bottom:10px;">チームチャット定型文編集エディタ</div>';
-
- const inputs = [];
- for(let i=0; i<6; i++) {
- const line = document.createElement('div'); line.className = 'je-line';
- const inp = document.createElement('input'); inp.className = 'je-input';
- inp.value = phrases[i] || '';
- inp.placeholder = `ボタン ${i+1}`;
- line.appendChild(inp);
- ed.appendChild(line);
- inputs.push(inp);
- }
-
- const footer = document.createElement('div'); footer.className = 'je-footer';
-
- // 保存ボタン
- const saveBtn = document.createElement('button'); saveBtn.className = 'je-btn-save'; saveBtn.innerText = '💾 保存';
- saveBtn.onclick = () => {
- const newPhrases = inputs.map(input => input.value.trim()).filter(p => p !== '');
- localStorage.setItem('j-phrases', JSON.stringify(newPhrases));
- alert('定型文を保存しました!');
- ed.remove();
- };
+javascript:(function(){
+ const canvas = document.querySelector('canvas');
+ if(!canvas) return alert('Canvasが見つかりません');
+
+ // 本家の入力イベントを横取りして座標を補正する関数
+ const fixEvent = (e) => {
+ const rect = canvas.getBoundingClientRect();
+ // Canvasの解像度と表示サイズの比率を計算
+ const scaleX = canvas.width / rect.width;
+ const scaleY = canvas.height / rect.height;
+
+ let clientX, clientY;
+ if (e.touches && e.touches.length > 0) {
+ clientX = e.touches[0].clientX;
+ clientY = e.touches[0].clientY;
+ } else {
+ clientX = e.clientX;
+ clientY = e.clientY;
+ }
- // リセットボタン
- const resetBtn = document.createElement('button'); resetBtn.className = 'je-btn-reset'; resetBtn.innerText = '🔄 リセット';
- resetBtn.onclick = () => {
- if(confirm('全ての入力をデフォルト(味方カモン!等)に戻しますか?')) {
- inputs.forEach((inp, i) => {
- inp.value = defaultPhrases[i] || '';
- });
+ // 余白(rect.left / top)を引いて、スケールを掛けることで「Canvas内の正確な位置」を出す
+ const correctedX = (clientX - rect.left) * scaleX;
+ const correctedY = (clientY - rect.top) * scaleY;
+
+ // ゲーム側の内部変数(mouse.x, mouse.yなど)に無理やり書き込む
+ // ※client-game.js内の変数名に合わせる必要があります。
+ if(window.game && window.game.mouse) {
+ window.game.mouse.x = correctedX;
+ window.game.mouse.y = correctedY;
}
};
- footer.appendChild(resetBtn);
- footer.appendChild(saveBtn);
- ed.appendChild(footer);
- document.body.appendChild(ed);
+ // 全ての操作イベントに対して補正をかける
+ ['mousedown', 'mousemove', 'touchstart', 'touchmove'].forEach(type => {
+ window.addEventListener(type, fixEvent, true);
+ });
+
+ alert('座標補正パッチを適用しました!スティックの位置を確認してください。');
})();
/*
* @title 陣取り・エディタ
* @description 定型文を6つまで編集・保存します
* @private
*/
javascript:(function(){
const canvas = document.querySelector('canvas');
if(!canvas) return alert('Canvasが見つかりません');
// 本家の入力イベントを横取りして座標を補正する関数
const fixEvent = (e) => {
const rect = canvas.getBoundingClientRect();
// Canvasの解像度と表示サイズの比率を計算
const scaleX = canvas.width / rect.width;
const scaleY = canvas.height / rect.height;
let clientX, clientY;
if (e.touches && e.touches.length > 0) {
clientX = e.touches[0].clientX;
clientY = e.touches[0].clientY;
} else {
clientX = e.clientX;
clientY = e.clientY;
}
// 余白(rect.left / top)を引いて、スケールを掛けることで「Canvas内の正確な位置」を出す
const correctedX = (clientX - rect.left) * scaleX;
const correctedY = (clientY - rect.top) * scaleY;
// ゲーム側の内部変数(mouse.x, mouse.yなど)に無理やり書き込む
// ※client-game.js内の変数名に合わせる必要があります。
if(window.game && window.game.mouse) {
window.game.mouse.x = correctedX;
window.game.mouse.y = correctedY;
}
};
// 全ての操作イベントに対して補正をかける
['mousedown', 'mousemove', 'touchstart', 'touchmove'].forEach(type => {
window.addEventListener(type, fixEvent, true);
});
alert('座標補正パッチを適用しました!スティックの位置を確認してください。');
})();
- Permalink
- このページへの個別リンクです。
- RAW
- 書かれたコードへの直接のリンクです。
- Packed
- 文字列が圧縮された書かれたコードへのリンクです。
- Userscript
- Greasemonkey 等で利用する場合の .user.js へのリンクです。
- Loader
- @require やソースコードが長い場合に多段ロードする Loader コミのコードへのリンクです。
- Metadata
- コード中にコメントで @xxx と書かれたメタデータの JSON です。