-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkot_levelparser.html
More file actions
196 lines (169 loc) · 9.05 KB
/
Copy pathkot_levelparser.html
File metadata and controls
196 lines (169 loc) · 9.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>KoT Decoder - Dual Tolerance Scan</title>
<style>
body { font-family: 'Segoe UI', sans-serif; background: #0f0f0f; color: #e0e0e0; display: flex; flex-direction: column; align-items: center; padding: 20px; }
.container { max-width: 1100px; width: 100%; background: #1a1a1a; padding: 25px; border-radius: 12px; border: 1px solid #333; box-shadow: 0 10px 50px rgba(0,0,0,0.9); }
.controls { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 15px; margin-bottom: 20px; background: #222; padding: 15px; border-radius: 8px; }
canvas { width: 100%; height: auto; border-radius: 4px; border: 1px solid #444; background: #000; margin-top: 15px; }
.result-box { background: #000; padding: 20px; border-radius: 8px; margin-top: 20px; border-left: 5px solid #00ff88; text-align: center; display: flex; flex-direction: column; align-items: center; }
.binary-string { font-family: 'Courier New', monospace; letter-spacing: 4px; color: #00ff88; font-size: 1.5rem; word-break: break-all; margin: 10px 0; }
label { font-size: 0.7rem; text-transform: uppercase; color: #888; font-weight: bold; display: block; margin-bottom: 5px; }
input[type="range"] { width: 100%; cursor: pointer; accent-color: #00ff88; }
.hidden { display: none; }
.copy-btn { background: #00ff88; color: #000; border: none; padding: 8px 16px; border-radius: 4px; font-weight: bold; cursor: pointer; margin-top: 10px; transition: 0.2s; }
.copy-btn:hover { background: #00cc6e; transform: scale(1.05); }
.tile-stats { font-size: 0.75rem; color: #aaa; margin-top: 5px; }
.col-group { background: #2a2a2a; padding: 10px; border-radius: 6px; border: 1px solid #333; }
</style>
</head>
<body>
<div class="container">
<h2 style="margin:0 0 15px 0; text-align: center;">KoT Layout Decoder <small style="color:#00ff88">DUAL-TOLERANCE</small></h2>
<div class="controls">
<div>
<label>1. Screenshot</label>
<input type="file" id="upload" accept="image/*">
</div>
<div class="col-group">
<label>2. Border (Grid)</label>
<input type="color" id="borderColor" value="#fcfc73" style="width:100%; height:25px; cursor:pointer;">
<label style="margin-top:8px;">Border Tol: <span id="tolBorderVal">40</span></label>
<input type="range" id="tolBorder" min="5" max="150" value="40">
</div>
<div class="col-group">
<label>3. Solid (Inside)</label>
<input type="color" id="solidColor" value="#3b3f09" style="width:100%; height:25px; cursor:pointer;">
<label style="margin-top:8px;">Solid Tol: <span id="tolSolidVal">50</span></label>
<input type="range" id="tolSolid" min="5" max="150" value="50">
</div>
<div>
<label>Fill Threshold: <span id="fillValue">10</span>%</label>
<input type="range" id="fillThreshold" min="1" max="100" value="10">
<p style="font-size: 10px; color: #666; margin-top: 10px;">Area checked with 4% tile margin.</p>
</div>
</div>
<div id="results" class="hidden">
<div class="result-box">
<div id="binaryOutput" class="binary-string">0000...</div>
<button class="copy-btn" onclick="copyBinary()">COPY BINARY STRING</button>
</div>
<canvas id="mainCanvas"></canvas>
</div>
</div>
<script>
const upload = document.getElementById('upload');
const canvas = document.getElementById('mainCanvas');
const ctx = canvas.getContext('2d', { willReadFrequently: true });
const binaryOutput = document.getElementById('binaryOutput');
const resultsDiv = document.getElementById('results');
const borderColorEl = document.getElementById('borderColor');
const solidColorEl = document.getElementById('solidColor');
const tolBorderEl = document.getElementById('tolBorder');
const tolSolidEl = document.getElementById('tolSolid');
const fillThresholdEl = document.getElementById('fillThreshold');
let currentImg = null;
[borderColorEl, solidColorEl, tolBorderEl, tolSolidEl, fillThresholdEl].forEach(el => {
el.addEventListener('input', () => {
document.getElementById('tolBorderVal').innerText = tolBorderEl.value;
document.getElementById('tolSolidVal').innerText = tolSolidEl.value;
document.getElementById('fillValue').innerText = fillThresholdEl.value;
if (currentImg) process(currentImg);
});
});
upload.addEventListener('change', (e) => {
const reader = new FileReader();
reader.onload = (ev) => {
currentImg = new Image();
currentImg.onload = () => { resultsDiv.classList.remove('hidden'); process(currentImg); };
currentImg.src = ev.target.result;
};
reader.readAsDataURL(e.target.files[0]);
});
function copyBinary() {
navigator.clipboard.writeText(binaryOutput.innerText);
const btn = document.querySelector('.copy-btn');
btn.innerText = "COPIED!";
setTimeout(() => btn.innerText = "COPY BINARY STRING", 2000);
}
function getDistance(r1, g1, b1, r2, g2, b2) {
return Math.sqrt(Math.pow(r1-r2, 2) + Math.pow(g1-g2, 2) + Math.pow(b1-b2, 2));
}
function hexToRgb(hex) {
return { r: parseInt(hex.slice(1, 3), 16), g: parseInt(hex.slice(3, 5), 16), b: parseInt(hex.slice(5, 7), 16) };
}
function process(img) {
const W = img.width; const H = img.height;
canvas.width = W; canvas.height = H;
ctx.drawImage(img, 0, 0);
const imgData = ctx.getImageData(0, 0, W, H);
const pixels = imgData.data;
const borderRGB = hexToRgb(borderColorEl.value);
const solidRGB = hexToRgb(solidColorEl.value);
const tB = parseInt(tolBorderEl.value);
const tS = parseInt(tolSolidEl.value);
const fillThresholdPct = parseInt(fillThresholdEl.value) / 100;
// 1. BOUNDARY SEARCH (using Border Hex + Border Tolerance)
let wallPixels = [];
let lowestY = 0;
const mX = Math.floor(W * 0.05), mY = Math.floor(H * 0.05);
for (let y = mY; y < H - mY; y += 4) {
for (let x = mX; x < W - mX; x += 4) {
const i = (y * W + x) * 4;
if (getDistance(pixels[i], pixels[i+1], pixels[i+2], borderRGB.r, borderRGB.g, borderRGB.b) < tB) {
wallPixels.push({x, y});
if (y > lowestY) lowestY = y;
}
}
}
if (wallPixels.length < 5) return;
const minX = Math.min(...wallPixels.map(p => p.x));
const maxX = Math.max(...wallPixels.map(p => p.x));
const gridW = maxX - minX;
const gridH = gridW * (4 / 7);
const minY = lowestY - gridH;
// 2. PRECISION AREA ANALYSIS (using Solid Hex + Solid Tolerance)
ctx.fillStyle = "#000"; ctx.fillRect(0,0, W, H);
ctx.globalAlpha = 0.3; ctx.drawImage(img, 0, 0); ctx.globalAlpha = 1.0;
const tW = gridW / 7; const tH = gridH / 4;
let binary = "";
for (let r = 0; r < 4; r++) {
for (let c = 0; c < 7; c++) {
const startX = Math.floor(minX + (c * tW) + (tW * 0.04));
const endX = Math.floor(minX + ((c+1) * tW) - (tW * 0.04));
const startY = Math.floor(minY + (r * tH) + (tH * 0.04));
const endY = Math.floor(minY + ((r+1) * tH) - (tH * 0.04));
let matches = 0, total = 0;
for(let py = startY; py < endY; py += 2) {
for(let px = startX; px < endX; px += 2) {
total++;
const pi = (py * W + px) * 4;
// Checking against Solid Tolerance specifically
if (getDistance(pixels[pi], pixels[pi+1], pixels[pi+2], solidRGB.r, solidRGB.g, solidRGB.b) < tS) {
matches++;
ctx.fillStyle = "rgba(0,255,136,0.5)";
ctx.fillRect(px, py, 1, 1);
}
}
}
const ratio = matches / total;
const isSolid = ratio >= fillThresholdPct;
binary += isSolid ? "1" : "0";
ctx.strokeStyle = "rgba(0, 255, 136, 0.4)";
ctx.strokeRect(startX, startY, endX - startX, endY - startY);
ctx.fillStyle = isSolid ? "rgba(255, 68, 68, 0.35)" : "rgba(68, 68, 255, 0.15)";
ctx.fillRect(minX + (c * tW), minY + (r * tH), tW, tH);
ctx.fillStyle = "#fff";
ctx.fillText(Math.round(ratio * 100) + "%", startX + 2, startY + 12);
}
}
binaryOutput.innerText = binary;
ctx.strokeStyle = "#ff4444"; ctx.lineWidth = 2;
ctx.strokeRect(minX, minY, gridW, gridH);
}
</script>
</body>
</html>