diff --git a/libraries/optimizer.php b/libraries/optimizer.php index afc9b22..2573536 100644 --- a/libraries/optimizer.php +++ b/libraries/optimizer.php @@ -1,4 +1,5 @@ get_library()[$key]["path"] ?? ""; + if (!file_exists($path)) return ""; + + $name = "session/osz/" . basename($path) . ".osz"; + if (file_exists($name)) return $name; + + $zip = new ZipArchive; + + try + { + $zip->open($name, ZipArchive::CREATE); + utils::recursive_zip_map($zip, $path, $path); + } + catch (Exception $e) + { + return ""; + } + finally + { + $zip->close(); + } + + return $name; + } } \ No newline at end of file diff --git a/libraries/utils.php b/libraries/utils.php index 7ade7c2..edcea09 100644 --- a/libraries/utils.php +++ b/libraries/utils.php @@ -17,7 +17,7 @@ class utils { if (is_dir($file)) { - recursive_zip_map($zip, $root, $file); + self::recursive_zip_map($zip, $root, $file); } else { @@ -26,15 +26,4 @@ class utils } } } - // $folder = $my_db[$beatmap_id]; - // $name = basename($folder) . ".osz"; - - // echo "Zipping " . $name; - - // $path = $collection_location . "/" . $name; - // $zip = new ZipArchive; - // $zip->open($path, ZipArchive::CREATE); - // echo "."; - - // recursive_zip_map($zip, $fol } \ No newline at end of file diff --git a/macska.jpg b/macska.jpg new file mode 100644 index 0000000..4be5ef6 Binary files /dev/null and b/macska.jpg differ diff --git a/main.php b/main.php index b314ee4..23600de 100644 --- a/main.php +++ b/main.php @@ -45,6 +45,13 @@ if ($display == "main") redirect("./"); } + if (isset($_GET["repack"]) && !empty($_GET["key"])) + { + $key = $_GET["key"]; + $dl = @optimizer::repack($lib, $key); + redirect("./" . $dl); + } + if (isset($_GET["blacken"])) { @optimizer::blacken_backgrounds($lib); diff --git a/templates/main-browser-script.js b/templates/main-browser-script.js index d5ff95e..52c7c1e 100644 --- a/templates/main-browser-script.js +++ b/templates/main-browser-script.js @@ -1,30 +1,86 @@ var xmlhttp = new XMLHttpRequest(); var page = 1; -var url = "./splitter.php?format=json&page=" + page.toString(); +var url = "./splitter.php?format=json&page="; +updateBrowser(); + xmlhttp.onreadystatechange = function() { // done & success if (this.readyState == 4 && this.status == 200) { var result = JSON.parse(this.responseText); - alert(result); changeBrowser(result); } }; -xmlhttp.open("GET", url, true); -xmlhttp.send(); +function requestPage(uri) { + xmlhttp.open("GET", uri, true); + xmlhttp.send(); +} + +function updateBrowser() { + requestPage(url + page.toString()); +} + + + +function prevPage() { + page -= 1; + if (page < 0) page = 0; + updateBrowser(); +} + +function nextPage() { + page += 1; + updateBrowser(); +} function changeBrowser(mapsets) { var browser = document.getElementById("browser"); - var output = ""; + var output = "
Page " + page.toString() + "
"; - var template = "

{{ MAP_TITLE }}

"; - for (var beatmap of mapsets.entries) + var mapsetTemplate = `{{ MAIN_BROWSER_TEMPLATE_MAPSET }}`; + var template = `{{ MAIN_BROWSER_TEMPLATE_DIFFICULTY }}`; + for (var mapsetKey of Object.keys(mapsets)) { - output += template.replaceAll(/\{\{ MAP_TITLE \}\}/g, beatmap.Metadata.Title); + var mapset = mapsets[mapsetKey]; + var subOutput = ""; + var summary = true; + + for (var beatmapKey of Object.keys(mapset.difficulties)) + { + var beatmap = mapset.difficulties[beatmapKey]; + + if (beatmap.Metadata && beatmap.Metadata.Title) + { + var path = mapset.path.toString() + "/" + beatmap.background.toString(); + path = encodeURI(path); + path = path.replaceAll(/\+/g, "%2b"); + line = template; + line = line.replaceAll(/\{\{ MAP_TITLE \}\}/g, beatmap.Metadata.Title); + line = line.replaceAll(/\{\{ MAP_ARTIST \}\}/g, beatmap.Metadata.Artist); + line = line.replaceAll(/\{\{ MAP_MAPPER \}\}/g, beatmap.Metadata.Creator); + line = line.replaceAll(/\{\{ MAP_DIFFICULTY \}\}/g, beatmap.Metadata.Version); + line = line.replaceAll(/\{\{ MAP_IMAGE \}\}/g, "./proxy.php?path=" + path); + + if (summary) + { + summary = false; + line = "" + line + ""; + } + + subOutput += line; + } + } + + var uriSafeKey = mapset.key; + uriSafeKey = encodeURI(uriSafeKey); + uriSafeKey = uriSafeKey.replaceAll(/\+/g, "%2b"); + subOutput = mapsetTemplate.replaceAll(/\{\{ MAP_DIFFICULTIES \}\}/g, subOutput); + subOutput = subOutput.replaceAll(/\{\{ MAPSET_KEY \}\}/g, uriSafeKey); + output += subOutput; } browser.innerHTML = output; -} +} \ No newline at end of file diff --git a/templates/main-browser-template-difficulty.html b/templates/main-browser-template-difficulty.html new file mode 100644 index 0000000..5e6beda --- /dev/null +++ b/templates/main-browser-template-difficulty.html @@ -0,0 +1,11 @@ +
+
+ +
+
+

\{\{ MAP_TITLE \}\}

+

\{\{ MAP_ARTIST \}\}

+

\{\{ MAP_MAPPER \}\}

+

\{\{ MAP_DIFFICULTY \}\}

+
+
\ No newline at end of file diff --git a/templates/main-browser-template-mapset.html b/templates/main-browser-template-mapset.html new file mode 100644 index 0000000..5c68140 --- /dev/null +++ b/templates/main-browser-template-mapset.html @@ -0,0 +1,6 @@ +
+
+ \{\{ MAP_DIFFICULTIES \}\} +
+ REPACK +
\ No newline at end of file diff --git a/templates/main.html b/templates/main.html index 868ea7b..1f42bcc 100644 --- a/templates/main.html +++ b/templates/main.html @@ -15,7 +15,9 @@
{{ MAIN_OPTIONS }}
-

Browser

+

Browser

+ [ Previous ]   + [ Next ]
diff --git a/templates/style.css b/templates/style.css index 77676e9..82fd53f 100644 --- a/templates/style.css +++ b/templates/style.css @@ -11,9 +11,10 @@ html { margin: 5px 0; padding: 10px; } -a:link, a:hover, a:active, a:visited { +a, a:link, a:hover, a:active, a:visited { color: HotPink; text-decoration: inherit; + cursor:pointer; } .small-background { max-height: 100px; @@ -64,4 +65,49 @@ a:link, a:hover, a:active, a:visited { .main-item>h2, .main-item>h3 { margin: 5px; padding: 5px; +} +.map { + border: 1px solid white; + padding: 10px; + margin: 5px; +} + +.map p { + margin: 0; + padding: 0; +} +.map-title { + font-weight: bold; +} +.map-artist, .map-mapper { + display: inline-block; +} +.map-artist::after { + content: ' /'; +} +.map-mapper::before { + content: '/ '; +} +.map>div { + display: inline-block; +} +.map-image img { + max-height: 64px; + max-width: 64px; +} +.map-details { + display: inline-block; + vertical-align: top; + margin-left: 10px; +} +details.mapset summary::-webkit-details-marker { + display:none; +} + +.mapset[open] .map { + background-color: #333333; +} + +.mapset[open] summary .map { + background-color: #444444; } \ No newline at end of file