Skip to content

Commit

Permalink
enforce style that was used in repo! indent back to 2
Browse files Browse the repository at this point in the history
  • Loading branch information
zardoy committed Sep 27, 2023
1 parent 38e2621 commit f8ae3e1
Show file tree
Hide file tree
Showing 12 changed files with 507 additions and 486 deletions.
21 changes: 21 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,27 @@
{
"extends": "zardoy",
"rules": {
"semi": [
"error",
"never"
],
"indent": [
"error",
2,
{
"SwitchCase": 2,
"ignoredNodes": [
"TemplateLiteral"
]
}
],
"quotes": [
"error",
"single",
{
"allowTemplateLiterals": true
}
],
// perf
"import/no-deprecated": "off",
// ---
Expand Down
94 changes: 47 additions & 47 deletions cypress/integration/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,78 +2,78 @@
import type { AppOptions } from '../../src/optionsStorage'

const cleanVisit = () => {
window.localStorage.clear()
visit()
window.localStorage.clear()
visit()
}

const visit = (url = '/') => {
window.localStorage.cypress = 'true'
cy.visit(url)
window.localStorage.cypress = 'true'
cy.visit(url)
}

// todo use ssl

const compareRenderedFlatWorld = () => {
// wait for render
// cy.wait(6000)
// cy.get('body').toMatchImageSnapshot({
// name: 'superflat-world',
// })
// wait for render
// cy.wait(6000)
// cy.get('body').toMatchImageSnapshot({
// name: 'superflat-world',
// })
}

const testWorldLoad = () => {
cy.document().then({ timeout: 20_000, }, doc => {
return new Cypress.Promise(resolve => {
doc.addEventListener('cypress-world-ready', resolve)
})
}).then(() => {
compareRenderedFlatWorld()
cy.document().then({ timeout: 20_000, }, doc => {
return new Cypress.Promise(resolve => {
doc.addEventListener('cypress-world-ready', resolve)
})
}).then(() => {
compareRenderedFlatWorld()
})
}

const setOptions = (options: Partial<AppOptions>) => {
cy.window().then(win => {
Object.assign(win['options'], options)
})
cy.window().then(win => {
Object.assign(win['options'], options)
})
}

it('Loads & renders singleplayer', () => {
cleanVisit()
setOptions({
localServerOptions: {
generation: {
name: 'superflat',
// eslint-disable-next-line unicorn/numeric-separators-style
options: { seed: 250869072 }
},
},
renderDistance: 2
})
cy.get('#title-screen').find('[data-test-id="singleplayer-button"]', { includeShadowDom: true, }).click()
testWorldLoad()
cleanVisit()
setOptions({
localServerOptions: {
generation: {
name: 'superflat',
// eslint-disable-next-line unicorn/numeric-separators-style
options: { seed: 250869072 }
},
},
renderDistance: 2
})
cy.get('#title-screen').find('[data-test-id="singleplayer-button"]', { includeShadowDom: true, }).click()
testWorldLoad()
})

it('Joins to server', () => {
// visit('/?version=1.16.1')
window.localStorage.version = '1.16.1'
visit()
// todo replace with data-test
cy.get('#title-screen').find('[data-test-id="connect-screen-button"]', { includeShadowDom: true, }).click()
cy.get('input#serverip', { includeShadowDom: true, }).clear().focus().type('localhost')
cy.get('[data-test-id="connect-to-server"]', { includeShadowDom: true, }).click()
testWorldLoad()
// visit('/?version=1.16.1')
window.localStorage.version = '1.16.1'
visit()
// todo replace with data-test
cy.get('#title-screen').find('[data-test-id="connect-screen-button"]', { includeShadowDom: true, }).click()
cy.get('input#serverip', { includeShadowDom: true, }).clear().focus().type('localhost')
cy.get('[data-test-id="connect-to-server"]', { includeShadowDom: true, }).click()
testWorldLoad()
})

it('Loads & renders zip world', () => {
cleanVisit()
cy.get('#title-screen').find('[data-test-id="select-file-folder"]', { includeShadowDom: true, }).click({ shiftKey: true })
cy.get('input[type="file"]').selectFile('cypress/superflat.zip', { force: true })
testWorldLoad()
cleanVisit()
cy.get('#title-screen').find('[data-test-id="select-file-folder"]', { includeShadowDom: true, }).click({ shiftKey: true })
cy.get('input[type="file"]').selectFile('cypress/superflat.zip', { force: true })
testWorldLoad()
})

it.skip('Performance test', () => {
// select that world
// from -2 85 24
// await bot.loadPlugin(pathfinder.pathfinder)
// bot.pathfinder.goto(new pathfinder.goals.GoalXZ(28, -28))
// select that world
// from -2 85 24
// await bot.loadPlugin(pathfinder.pathfinder)
// bot.pathfinder.goto(new pathfinder.goals.GoalXZ(28, -28))
})
16 changes: 8 additions & 8 deletions src/browserfs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { installTexturePack, updateTexturePackInstalledState } from './texturePa
browserfs.install(window)
// todo migrate to StorageManager API for localsave as localstorage has only 5mb limit, when localstorage is fallback test limit warning on 4mb
const deafultMountablePoints = {
"/world": { fs: "LocalStorage" },
'/world': { fs: 'LocalStorage' },
'/userData': { fs: 'IndexedDB' },
}
browserfs.configure({
Expand Down Expand Up @@ -154,8 +154,8 @@ export const openWorldDirectory = async (dragndropHandle?: FileSystemDirectoryHa
// todo
fs: 'MountableFileSystem',
options: {
"/world": {
fs: "FileSystemAccess",
'/world': {
fs: 'FileSystemAccess',
options: {
handle: directoryHandle
}
Expand Down Expand Up @@ -215,8 +215,8 @@ const openWorldZipInner = async (file: File | ArrayBuffer, name = file['name'])
fs: 'MountableFileSystem',
options: {
...deafultMountablePoints,
"/world": {
fs: "ZipFS",
'/world': {
fs: 'ZipFS',
options: {
zipData: Buffer.from(file instanceof File ? (await file.arrayBuffer()) : file),
name
Expand Down Expand Up @@ -276,12 +276,12 @@ export async function generateAndDownloadWorldZip() {
zip.folder('world')

// Generate the ZIP archive content
const zipContent = await zip.generateAsync({ type: "blob" })
const zipContent = await zip.generateAsync({ type: 'blob' })

// Create a download link and trigger the download
const downloadLink = document.createElement("a")
const downloadLink = document.createElement('a')
downloadLink.href = URL.createObjectURL(zipContent)
downloadLink.download = "prismarine-world.zip"
downloadLink.download = 'prismarine-world.zip'
downloadLink.click()

// Clean up the URL object after download
Expand Down
6 changes: 3 additions & 3 deletions src/builtinCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ const exportWorld = async () => {
await addFolderToZip(worldFolder, zip, '')

// Generate the ZIP archive content
const zipContent = await zip.generateAsync({ type: "blob" })
const zipContent = await zip.generateAsync({ type: 'blob' })

// Create a download link and trigger the download
const downloadLink = document.createElement("a")
const downloadLink = document.createElement('a')
downloadLink.href = URL.createObjectURL(zipContent)
downloadLink.download = "world-exported.zip"
downloadLink.download = 'world-exported.zip'
downloadLink.click()

// Clean up the URL object after download
Expand Down
68 changes: 34 additions & 34 deletions src/controls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,22 +139,22 @@ const onTriggerOrReleased = (command: Command, pressed: boolean) => {
// handle general commands
// eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check
switch (command) {
case 'general.jump':
bot.setControlState('jump', pressed)
break
case 'general.sneak':
gameAdditionalState.isSneaking = pressed
bot.setControlState('sneak', pressed)
break
case 'general.sprint':
case 'general.jump':
bot.setControlState('jump', pressed)
break
case 'general.sneak':
gameAdditionalState.isSneaking = pressed
bot.setControlState('sneak', pressed)
break
case 'general.sprint':
// todo add setting to change behavior
if (pressed) {
setSprinting(pressed)
}
break
case 'general.attackDestroy':
document.dispatchEvent(new MouseEvent(pressed ? 'mousedown' : 'mouseup', { button: 0 }))
break
if (pressed) {
setSprinting(pressed)
}
break
case 'general.attackDestroy':
document.dispatchEvent(new MouseEvent(pressed ? 'mousedown' : 'mouseup', { button: 0 }))
break
}
}
}
Expand Down Expand Up @@ -192,26 +192,26 @@ contro.on('trigger', ({ command }) => {
if (stringStartsWith(command, 'general')) {
// eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check
switch (command) {
case 'general.inventory':
document.exitPointerLock?.()
showModal({ reactType: 'inventory' })
break
case 'general.drop':
if (bot.heldItem) bot.tossStack(bot.heldItem)
break
case 'general.chat':
document.getElementById('hud').shadowRoot.getElementById('chat').enableChat()
break
case 'general.command':
document.getElementById('hud').shadowRoot.getElementById('chat').enableChat('/')
break
case 'general.interactPlace':
document.dispatchEvent(new MouseEvent('mousedown', { button: 2 }))
setTimeout(() => {
case 'general.inventory':
document.exitPointerLock?.()
showModal({ reactType: 'inventory' })
break
case 'general.drop':
if (bot.heldItem) bot.tossStack(bot.heldItem)
break
case 'general.chat':
document.getElementById('hud').shadowRoot.getElementById('chat').enableChat()
break
case 'general.command':
document.getElementById('hud').shadowRoot.getElementById('chat').enableChat('/')
break
case 'general.interactPlace':
document.dispatchEvent(new MouseEvent('mousedown', { button: 2 }))
setTimeout(() => {
// todo cleanup
document.dispatchEvent(new MouseEvent('mouseup', { button: 2 }))
})
break
document.dispatchEvent(new MouseEvent('mouseup', { button: 2 }))
})
break
}
}
})
Expand Down
8 changes: 4 additions & 4 deletions src/dragndrop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ import { openWorldDirectory, openWorldZip } from './browserfs'
import { isGameActive } from './globalState'

const parseNbt = promisify(nbt.parse)
window.nbt = nbt;
window.nbt = nbt

// todo display drop zone
for (const event of ["drag", "dragstart", "dragend", "dragover", "dragenter", "dragleave", "drop"]) {
for (const event of ['drag', 'dragstart', 'dragend', 'dragover', 'dragenter', 'dragleave', 'drop']) {
window.addEventListener(event, (e: any) => {
if (e.dataTransfer && !e.dataTransfer.types.includes("Files")) {
if (e.dataTransfer && !e.dataTransfer.types.includes('Files')) {
// e.dataTransfer.effectAllowed = "none"
return
}
e.preventDefault()
})
}
window.addEventListener("drop", async e => {
window.addEventListener('drop', async e => {
if (!e.dataTransfer?.files.length) return
const { items } = e.dataTransfer
const item = items[0]
Expand Down
6 changes: 3 additions & 3 deletions src/inventory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ const getItemSlice = (name) => {

const getImageSrc = (path) => {
switch (path) {
case 'gui/container/inventory': return InventoryGui
case 'blocks': return globalThis.texturePackDataUrl || `textures/${version}.png`
case 'invsprite': return `invsprite.png`
case 'gui/container/inventory': return InventoryGui
case 'blocks': return globalThis.texturePackDataUrl || `textures/${version}.png`
case 'invsprite': return `invsprite.png`
}
return Dirt
}
Expand Down
2 changes: 1 addition & 1 deletion src/loadSave.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export const loadSave = async (root = '/world') => {

if (!fsState.isReadonly) {
// todo allow also to ctrl+s
alert("Note: the world is saved only on /save or disconnect! ENSURE YOU HAVE BACKUP!")
alert('Note: the world is saved only on /save or disconnect! ENSURE YOU HAVE BACKUP!')
}

fsState.saveLoaded = true
Expand Down
Loading

0 comments on commit f8ae3e1

Please sign in to comment.