The Wiki for Tale 6 is in read-only mode and is available for archival and reference purposes only. Please visit the current Tale 11 Wiki in the meantime.

If you have any issues with this Wiki, please post in #wiki-editing on Discord or contact Brad in-game.

Difference between revisions of "User:Selune"

From ATITD6
Jump to navigationJump to search
Line 840: Line 840:
 
{{Collapse top|title=New Raeli Oven Monitor (IN TESTING)}}
 
{{Collapse top|title=New Raeli Oven Monitor (IN TESTING)}}
 
<pre>
 
<pre>
 
 
loadfile("luaScripts/screen_reader_common.inc")();
 
loadfile("luaScripts/screen_reader_common.inc")();
 
loadfile("luaScripts/common.inc")();
 
loadfile("luaScripts/common.inc")();
Line 846: Line 845:
  
 
askText = singleLine([[
 
askText = singleLine([[
   Raeli Color Monitor v1.1a (edit by Selune) --
+
   Raeli Color Monitor v1.1b (edit by Selune) --
 
   Make sure the Raeli Oven is pinned, then select the ATITD window and press shift.
 
   Make sure the Raeli Oven is pinned, then select the ATITD window and press shift.
 
]]);
 
]]);
Line 853: Line 852:
 
take_screenshots = true;
 
take_screenshots = true;
 
stop_at_color = "White";
 
stop_at_color = "White";
 +
confidence_threshold = 15;
 
saved_x = 0;
 
saved_x = 0;
 
saved_y = 0;
 
saved_y = 0;
Line 987: Line 987:
 
local lab_l, lab_a, lab_b, lab_tst_l, lab_tst_a, lab_tst_b;
 
local lab_l, lab_a, lab_b, lab_tst_l, lab_tst_a, lab_tst_b;
 
local hsl_h, hsl_s, hsl_l, hsl_tst_h, hsl_tst_s, hsl_tst_l;
 
local hsl_h, hsl_s, hsl_l, hsl_tst_h, hsl_tst_s, hsl_tst_l;
local offset, best_name, best_offset;
+
local offset, best_name, best_offset, next_best_offset, confidence;
 
best_offset = 100000;
 
best_offset = 100000;
rgb_r = (math.floor(px/256/256/256) % 256);
+
next_best_offset = 1000000;
rgb_g = (math.floor(px/256/256) % 256);
+
rgb_r = ((math.floor(px/256/256/256) % 256) - 7) * 255/248;
rgb_b = (math.floor(px/256) % 256);
+
rgb_g = ((math.floor(px/256/256) % 256) - 7) * 255/248;
 +
rgb_b = ((math.floor(px/256) % 256) - 6) * 255/248;
 
lab_l, lab_a, lab_b = rgb2lab(rgb_r, rgb_g, rgb_b);
 
lab_l, lab_a, lab_b = rgb2lab(rgb_r, rgb_g, rgb_b);
 
hsl_h, hsl_s, hsl_l = rgb2hsl(rgb_r, rgb_g, rgb_b);
 
hsl_h, hsl_s, hsl_l = rgb2hsl(rgb_r, rgb_g, rgb_b);
Line 1,008: Line 1,009:
 
--offset = math.abs(rgb_r - tst_r) + math.abs(rgb_g - tst_g) + math.abs(rgb_b - tst_b);
 
--offset = math.abs(rgb_r - tst_r) + math.abs(rgb_g - tst_g) + math.abs(rgb_b - tst_b);
 
--offset = math.max(math.max((math.abs(rgb_r - tst_r)), math.abs(rgb_g - tst_g)), math.abs(rgb_b - tst_b));
 
--offset = math.max(math.max((math.abs(rgb_r - tst_r)), math.abs(rgb_g - tst_g)), math.abs(rgb_b - tst_b));
--offset = (rgb_r - tst_r)^2 + (rgb_g - tst_g)^2 + (rgb_b - tst_b)^2;
+
offset = (rgb_r - tst_r)^2 + (rgb_g - tst_g)^2 + (rgb_b - tst_b)^2;
 +
--offset = math.abs(lab_l - lab_tst_l) + math.abs(lab_a - lab_tst_a) + math.abs(lab_b - lab_tst_b);
 
--offset = (lab_l - lab_tst_l)^2 + (lab_a - lab_tst_a)^2 + (lab_b - lab_tst_b)^2;
 
--offset = (lab_l - lab_tst_l)^2 + (lab_a - lab_tst_a)^2 + (lab_b - lab_tst_b)^2;
offset = math.max(math.max((math.abs(lab_l - lab_tst_l)), math.abs(lab_a - lab_tst_a)), math.abs(lab_b - lab_tst_b));
+
--offset = math.max(math.max((math.abs(lab_l - lab_tst_l)), math.abs(lab_a - lab_tst_a)), math.abs(lab_b - lab_tst_b));
 +
--offset = math.abs(hsl_h - hsl_tst_h) + math.abs(hsl_s - hsl_tst_s) + math.abs(hsl_l - hsl_tst_l);
 
--offset = (hsl_h - hsl_tst_h)^2 + (hsl_s - hsl_tst_s)^2 + (hsl_l - hsl_tst_l)^2;
 
--offset = (hsl_h - hsl_tst_h)^2 + (hsl_s - hsl_tst_s)^2 + (hsl_l - hsl_tst_l)^2;
 
--offset = math.max(math.max((math.abs(hsl_h - hsl_tst_h)), math.abs(hsl_s - hsl_tst_s)), math.abs(hsl_l - hsl_tst_l));
 
--offset = math.max(math.max((math.abs(hsl_h - hsl_tst_h)), math.abs(hsl_s - hsl_tst_s)), math.abs(hsl_l - hsl_tst_l));
+
if (offset < next_best_offset) then
if (offset < best_offset) then
+
if (offset < best_offset) then
best_name = color_names[i] .. "  Hex: " .. DEC_HEX(color_values[i]);
+
next_best_offset = best_offset;
best_offset = offset;
+
best_offset = offset;
 +
best_name = color_names[i]; -- .. "  Hex: " .. DEC_HEX(color_values[i]);
 +
else
 +
next_best_offset = offset;
 +
end
 +
confidence = ((next_best_offset - best_offset) / best_offset) * 100;
 
end
 
end
 
 
end
 
end
 
 
return best_name;
+
return best_name, math.floor(confidence);
 
end
 
end
  
 
--Check pixel against target
 
--Check pixel against target
 
function checkColor(px)
 
function checkColor(px)
local color_name = nearestColor(px);
+
local color_name, confidence;
 +
color_name, confidence = nearestColor(px);
 +
 
if (color_name:upper() == stop_at_color:upper()) then
 
if (color_name:upper() == stop_at_color:upper()) then
return true;
+
return true, confidence;
 +
else
 +
return false, 0;
 
end
 
end
 
return false;
 
 
end
 
end
  
Line 1,041: Line 1,050:
 
local color_guess = "NONE";
 
local color_guess = "NONE";
 
local tst_r, tst_g, tst_b, rgb_r, rgb_g, rgb_b;
 
local tst_r, tst_g, tst_b, rgb_r, rgb_g, rgb_b;
 +
local confidence = 0;
 
-- Display message until shift is held
 
-- Display message until shift is held
 
while not go_now do
 
while not go_now do
 
checkBreak();
 
checkBreak();
 +
srReadScreen();
 
y = 0;
 
y = 0;
 
mouse_x, mouse_y = srMousePos();
 
mouse_x, mouse_y = srMousePos();
Line 1,071: Line 1,082:
 
 
 
y = y + 15;
 
y = y + 15;
color_guess = nearestColor(px);
+
color_guess, confidence = nearestColor(px);
 
lsPrintWrapped(0, y, 1, lsScreenX, 0.7, 0.7, px,
 
lsPrintWrapped(0, y, 1, lsScreenX, 0.7, 0.7, px,
"(" .. (math.floor(px/256/256/256) % 256) .. "," .. (math.floor(px/256/256) % 256) .. "," .. (math.floor(px/256) % 256) .. "," .. (px % 256) .. ") Hex: " .. DEC_HEX(px));
+
"(" .. (math.floor(px/256/256/256) % 256) .. "," .. (math.floor(px/256/256) % 256) .. "," .. (math.floor(px/256) % 256) .. "," .. (px % 256) .. ") Hex: " .. DEC_HEX(math.floor((px/256) % 16777216)));
 
 
 +
y = y + 20;
 +
lsPrintWrapped(0, y, 1, lsScreenX, 0.7, 0.7, px, "Best guess: " .. color_guess);
 
y = y + 15;
 
y = y + 15;
lsPrintWrapped(0, y, 1, lsScreenX, 0.7, 0.7, px, "Best guess: " .. color_guess);
+
lsPrintWrapped(0, y, 1, lsScreenX, 0.7, 0.7, px, "Confidence: " .. confidence .. " (higher is better)");
y = y + 30;
 
lsPrintWrapped(0, y, 1, lsScreenX, 0.7, 0.7, px, "Dec: " .. math.floor((px/256) % 16777216) .. "  Hex: " .. DEC_HEX(math.floor((px/256) % 16777216)));
 
 
 
 
-- Testing other methods of grabbing the pixel, making sure RGBA values match
 
-- Testing other methods of grabbing the pixel, making sure RGBA values match
Line 1,114: Line 1,125:
 
end
 
end
 
 
y = y + 30;
 
 
if not color_found then
 
if not color_found then
lsPrint(10, y, z, 0.7, 0.7, 0xFF0000ff, "No such color");
+
lsPrint(130, y - 20, z, 0.7, 0.7, 0xFF0000ff, "No such color");
 
end
 
end
 
 
srReadScreen();
+
y = y + 35;
+
lsPrint(5, y, 0, 0.6, 0.6, 0xffffffff, "Confidence Required:");
y = y + 30;
+
is_done, confidence_threshold = lsEditBox("confthresh", 150, y, 0, 50, 30, 0.7, 0.7, 0x000000ff, confidence_threshold);
+
confidence_threshold = tonumber(confidence_threshold);
 +
if not confidence_threshold then
 +
lsPrint(10, y+17, 10, 0.4, 0.4, 0xFF2020ff, "MUST BE A NUMBER");
 +
confidence_threshold = 10;
 +
end
 
else
 
else
 
is_done = true;
 
is_done = true;
Line 1,163: Line 1,177:
 
local px = 0;
 
local px = 0;
 
local index=0;
 
local index=0;
 +
local color_name, confidence;
 
while 1 do
 
while 1 do
 +
local y = 0;
 
checkBreak();
 
checkBreak();
 
lsSleep(100);
 
lsSleep(100);
 
srReadScreen();
 
srReadScreen();
new_px = srReadPixel(mouse_x, mouse_y);
+
new_px = srReadPixel(saved_x, saved_y);
 
local t = (lsGetTimer() - t0) / 1000 / 60;
 
local t = (lsGetTimer() - t0) / 1000 / 60;
 
t = math.floor(t*10 + 0.5)/10;
 
t = math.floor(t*10 + 0.5)/10;
Line 1,177: Line 1,193:
 
end
 
end
 
px = new_px;
 
px = new_px;
 +
 
if stop_at_CB then
 
if stop_at_CB then
if checkColor(px) then
+
color_name, confidence = nearestColor(px);
clickAllText("Interrupt");
+
if (color_name:upper() == stop_at_color:upper()) then
lsPlaySound("Complete.wav");
+
if confidence > confidence_threshold then
break;
+
clickAllText("Interrupt");
 +
lsPlaySound("Complete.wav");
 +
error ("Stopped burn at: " .. stop_at_color .. "  Confidence: " .. confidence);
 +
else
 +
for i = 1, 3 do
 +
lsPlaySound("Clank.wav");
 +
lsSleep(50);
 +
end
 +
end
 +
else
 +
lsPlaySound("Clank.wav");
 
end
 
end
 +
else
 +
lsPlaySound("Clank.wav");
 
end
 
end
 
lsPlaySound("Clank.wav");
 
 
end
 
end
 
 
lsPrintWrapped(0, 0, 1, lsScreenX, 1, 1, 0xFFFFFFff,
+
" Color: " .. DEC_HEX(new_px) .. " screen: " .. index .. " timer: " .. t_string);
+
y = y + 5;
lsPrintWrapped(0, 60, 1, lsScreenX, 0.7, 0.7, 0xFFFFFFff,
+
lsPrintWrapped(5, y, 1, lsScreenX - 10, 0.7, 0.7, 0xFFFFFFff,
"(" .. (math.floor(px/256/256/256) % 256) .. "," .. (math.floor(px/256/256) % 256) .. "," .. (math.floor(px/256) % 256) .. "," .. (px % 256) .. ")" );
+
"Screen: " .. index .. "  Timer: " .. t_string);
 +
y = y + 15;
 +
lsPrintWrapped(5, y, 1, lsScreenX - 10, 0.7, 0.7, 0xFFFFFFff,
 +
"Color: " .. color_name .. " Confidence: " .. confidence);
 +
 +
y = y + 30;
 +
lsPrintWrapped(5, y, 1, lsScreenX - 10, 0.7, 0.7, 0xFFFFFFff,
 +
"(" .. (math.floor(px/256/256/256) % 256) .. "," .. (math.floor(px/256/256) % 256) .. "," .. (math.floor(px/256) % 256) .. "," .. (px % 256) .. ") Hex: " .. DEC_HEX(math.floor((new_px/256) % 16777216)));
 
 
 
if lsButtonText(lsScreenX - 110, lsScreenY - 30, 0, 100, 0xFFFFFFff, "Exit") then
 
if lsButtonText(lsScreenX - 110, lsScreenY - 30, 0, 100, 0xFFFFFFff, "Exit") then

Revision as of 00:16, 16 January 2013

Selune's Macros have been updated to the TaleScripts repository. Please leave any ideas for improvements or new macros here.