<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<el:level xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://enigma-game.org/schema/level/1 level.xsd" xmlns:el="http://enigma-game.org/schema/level/1">
  <el:protected >
    <el:info el:type="multilevel" el:quantity="12">
      <el:identity el:title="Unknowns #" el:subtitle="" el:id="opal_dance_unknowns"/>
      <el:version el:score="1" el:release="1" el:revision="1" el:status="released"/>
      <el:author el:name="Andreas Lochmann" el:email="" el:homepage=""/>
      <el:copyright>Copyright © 2024 by Andreas Lochmann</el:copyright>
      <el:license el:type="GPL v2.0 or above" el:open="true"/>
      <el:compatibility el:enigma="1.31">
        <el:dependency el:path="lib/libimport" el:id="lib/libimport" el:release="1" el:preload="true"/>
        <el:externaldata el:path="./opal_dance_unknowns" el:url=""/>
      </el:compatibility>
      <el:modes el:easy="false" el:single="true" el:network="false"/>
      <el:score el:easy="-" el:difficult="-"/>
    </el:info>
    <el:luamain><![CDATA[

sublevel = wo["SublevelNumber"]

if sublevel ==  1 then wo["SublevelTitle"] = "Unknowns #1: Triangles II";        minp =   4  end
if sublevel ==  2 then wo["SublevelTitle"] = "Unknowns #2: Squares II";          minp =  50  end
if sublevel ==  3 then wo["SublevelTitle"] = "Unknowns #3: Parallelograms II";   minp =  40  end
if sublevel ==  4 then wo["SublevelTitle"] = "Unknowns #4: Grid II";             minp =  70  end
if sublevel ==  5 then wo["SublevelTitle"] = "Unknowns #5: Narrow Passages II";  minp =  40  end
if sublevel ==  6 then wo["SublevelTitle"] = "Unknowns #6: Wide Holes II";       minp =  60  end
if sublevel ==  7 then wo["SublevelTitle"] = "Unknowns #7: Concentric II";       minp =  80  end
if sublevel ==  8 then wo["SublevelTitle"] = "Unknowns #8: Semipermeable II";    minp =  70  end
if sublevel ==  9 then wo["SublevelTitle"] = "Unknowns #9: Bubbles II";          minp =  35  end
if sublevel == 10 then wo["SublevelTitle"] = "Unknowns #10: Boxed Diamonds II";  minp =  40  end
if sublevel == 11 then wo["SublevelTitle"] = "Unknowns #11: Tribute II";         minp =  30  end
if sublevel == 12 then wo["SublevelTitle"] = "Unknowns #12: Finale II";          minp = 144  end

wo["FollowGrid"] = false
wo["FollowMethod"] = FOLLOW_SCROLL

ti[" "] = {"fl_abyss"}
ti["."] = {"fl_concrete"}
ti["%"] = ti["."]
ti["#"] = {"st_brick", cluster=1}
ti["d"] = {"st_concrete"}
ti["f"] = {"st_nil"}
ti["1"] = {"st_oxyd_e", "opals1#", oxydcolor=1, selection={"=d", "=f"}}
ti["2"] = {"st_oxyd_e", "opals2#", oxydcolor=2, selection={"=d", "=f"}}
ti["3"] = {"st_oxyd_e", "opals3#", oxydcolor=3, selection={"=d", "=f"}}
ti["4"] = {"st_oxyd_e", "opals4#", oxydcolor=4, selection={"=d", "=f"}}
ti["5"] = {"st_oxyd_e", "opals5#", oxydcolor=5, selection={"=d", "=f"}}
ti["6"] = {"st_oxyd_e", "opals6#", oxydcolor=6, selection={"=d", "=f"}}
ti["7"] = {"st_oxyd_e", "opals7#", oxydcolor=7, selection={"=d", "=f"}}
ti["8"] = {"st_oxyd_e", "opals8#", oxydcolor=8, selection={"=d", "=f"}}
ti["@"] = {"#ac_pearl_black"} .. ti{"it_remote", "remote", action="callback", target="remotecontrol", text="text2"}

lib.import.line_regexp["opaldance"] =
      "[ \#%\.@\*12345678]*"  -- all allowed characters except line ending
   .. "[\#%\.@\*12345678]+"   -- at least one non-space character
   .. "[ \#%\.@\*12345678]*"  -- again all allowed characters except line ending
   .. "[\r]?"             -- maybe a carriage return from line ending

levelstring = lib.import.unpack_multilevel(wo:externalData("./opal_dance_unknowns"), sublevel, "opaldance")
levelmap = lib.import.level_to_map(levelstring, "\n", " ")
wo(ti, ".", levelmap)
opals = no["opals1#*"] + no["opals2#*"] + no["opals3#*"] + no["opals4#*"] + no["opals5#*"] + no["opals6#*"] + no["opals7#*"] + no["opals8#*"]
opals:peepall()
total = #(opals)

text2 = "You opened $n pairs, you need at least $m, then you might use this remote. Each remaining oxyd then adds one minute to your time."
text3 = "You successfully opened $n pairs. $r oxyd(s) are left, adding one minute each."
text4 = "You opened all of them? Congratulations!"

function remotecontrol()
    remaining_oxyds = #(no["opals1#*"]) + #(no["opals2#*"]) + #(no["opals3#*"]) + #(no["opals4#*"]) + #(no["opals5#*"]) + #(no["opals6#*"]) + #(no["opals7#*"]) + #(no["opals8#*"])
    opened_oxyd_pairs = (total - remaining_oxyds)/2
    if remaining_oxyds == 0 then
        text = text4
    elseif opened_oxyd_pairs >= minp then
        text = text3
    else
        text = text2
    end
    text = string.gsub(text, "$m", ""..minp)
    text = string.gsub(text, "$n", ""..opened_oxyd_pairs)
    text = string.gsub(text, "$r", ""..remaining_oxyds)
    no["remote"].text = text
    if opened_oxyd_pairs >= minp then
        wo["AddSecondsToScore"] = 60*remaining_oxyds
        no["opals1#*"]:open()
        no["opals2#*"]:open()
        no["opals3#*"]:open()
        no["opals4#*"]:open()
        no["opals5#*"]:open()
        no["opals6#*"]:open()
        no["opals7#*"]:open()
        no["opals8#*"]:open()
    end
end

 ]]></el:luamain>
    <el:i18n>
      <el:string el:key="title">
        <el:english el:translate="false"/>
      </el:string>
    </el:i18n>
  </el:protected>
</el:level>
