forked from PrismarineJS/prismarine-web-client
-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
allow to load worlf from ?map= qs url
- Loading branch information
Showing
4 changed files
with
47 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { openWorldZip } from './browserfs' | ||
import { setLoadingScreenStatus } from './utils' | ||
import { filesize } from 'filesize' | ||
|
||
window.addEventListener('load', async (e) => { | ||
const qs = new URLSearchParams(window.location.search) | ||
const mapUrl = qs.get('map') | ||
if (!mapUrl) return | ||
|
||
const menu = document.getElementById('play-screen') | ||
menu.style = 'display: none;' | ||
const name = mapUrl.slice(mapUrl.lastIndexOf('/') + 1).slice(-25) | ||
setLoadingScreenStatus(`Downloading world ${name}...`) | ||
|
||
const response = await fetch(mapUrl) | ||
const contentLength = +response.headers.get('Content-Length') | ||
setLoadingScreenStatus(`Downloading world ${name}: have to download ${filesize(contentLength)}...`) | ||
// const reader = response.body!.getReader() | ||
// let doneValue | ||
// while (true) { | ||
// // done is true for the last chunk | ||
// // value is Uint8Array of the chunk bytes | ||
// const { done, value } = await reader.read() | ||
|
||
// if (done) { | ||
// doneValue = value | ||
// break | ||
// } | ||
|
||
// setLoadingScreenStatus(`Downloading world ${name}: ${filesize(value.length)} / ${filesize(contentLength)}MB...`) | ||
// } | ||
await openWorldZip(await response.arrayBuffer()) | ||
}) | ||
|
||
export default async () => { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters