Skip to content

Commit

Permalink
Feature Increments
Browse files Browse the repository at this point in the history
Going to start experimenting with some things here, I like to try new things here! Might try Preact next :)

Working on updating NBTify to the latest version, discovered some bugs I want to fix with it first before updating it in Dovetail.
  • Loading branch information
Offroaders123 committed Jun 22, 2023
1 parent fa85c53 commit fe31ed1
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 55 deletions.
52 changes: 26 additions & 26 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@
"private": true,
"type": "module",
"scripts": {
"build": "tsc; vite build --base ./ --target esnext",
"dev": "vite --host --port 5500 --base ./",
"preview": "vite preview --host --port 5500 --base ./"
"build": "tsc; vite build",
"dev": "vite",
"preview": "vite preview"
},
"dependencies": {
"compression-streams-polyfill": "^0.1.3",
"compression-streams-polyfill": "^0.1.4",
"nbtify": "^1.35.2"
},
"devDependencies": {
"better-typescript": "^0.1.2",
"new-javascript": "^0.3.1",
"typescript": "^5.0.4",
"vite": "^4.3.8"
"better-typescript": "^0.1.3",
"new-javascript": "^0.3.4",
"typescript": "^5.1.3",
"vite": "^4.3.9"
}
}
2 changes: 1 addition & 1 deletion public/service-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
var self = /** @type { ServiceWorkerGlobalScope } */ (/** @type { unknown } */ (globalThis));

const NAME = "Dovetail";
const VERSION = "v1.6.1";
const VERSION = "v1.6.2";
const CACHE_NAME = /** @type { const } */ (`${NAME} ${VERSION}`);

self.addEventListener("activate",event => {
Expand Down
39 changes: 19 additions & 20 deletions src/app.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,34 @@
import "./compression-polyfill.js";
import { read, write, parse, stringify, Name, Endian, Compression, BedrockLevel, NBTData, NBTDataOptions, RootTag, Int32, CompressionFormat } from "nbtify";
import { read, write, parse, stringify, NBTData, Int32 } from "nbtify";
import type { Name, Endian, Compression, BedrockLevel, NBTDataOptions, RootTag } from "nbtify";

if (window.isSecureContext){
await navigator.serviceWorker.register("./service-worker.js");
}
const platform = navigator.userAgentData?.platform ?? navigator.platform;
const isiOSDevice = /^(Mac|iPhone|iPad|iPod)/i.test(platform) && typeof navigator.standalone === "boolean";

const saver = document.querySelector<HTMLButtonElement>("#saver")!;
const fileOpener = document.querySelector<HTMLInputElement>("#fileOpener")!;
const formatOpener = document.querySelector<HTMLButtonElement>("#formatOpener")!;
const editor = document.querySelector<HTMLTextAreaElement>("#editor")!;
const formatDialog = document.querySelector<HTMLDialogElement>("#formatDialog")!;
const formatForm = document.querySelector<HTMLFormElement>("#formatForm")!;
const formatForm = document.querySelector<HTMLFormElement & { readonly elements: FormatOptionsCollection; }>("#formatForm")!;

export interface FormatOptionsCollection extends HTMLFormControlsCollection {
name: HTMLInputElement;
disableName: HTMLInputElement;
endian: RadioNodeList;
compression: RadioNodeList;
bedrockLevel: HTMLInputElement;
}

/**
* The name of the currently opened file.
*/
let name: string;

if (window.isSecureContext){
await navigator.serviceWorker.register("./service-worker.js");
}

window.launchQueue?.setConsumer?.(async launchParams => {
const { files: handles } = launchParams;
if (handles.length === 0) return;
Expand Down Expand Up @@ -53,11 +65,6 @@ saver.addEventListener("click",async () => {
const nbtData = new NBTData(nbt,options);
const file = await writeFile(nbtData);

const isiOSDevice = (
/^(Mac|iPhone|iPad|iPod)/i.test(navigator.userAgentData?.platform ?? navigator.platform) &&
typeof navigator.standalone === "boolean"
);

if (isiOSDevice && window.isSecureContext){
await shareFile(file);
} else {
Expand Down Expand Up @@ -100,19 +107,11 @@ export async function openFile(file: File): Promise<void> {
editor.disabled = false;
}

export interface FormatOptionsCollection extends HTMLFormControlsCollection {
name: HTMLInputElement;
disableName: HTMLInputElement;
endian: RadioNodeList;
compression: RadioNodeList;
bedrockLevel: HTMLInputElement;
}

/**
* Updates the Format Options dialog to match the NBT file's metadata.
*/
export function openOptions({ name, endian, compression, bedrockLevel }: NBTData): NBTDataOptions {
const elements = formatForm.elements as FormatOptionsCollection;
const { elements } = formatForm;

if (name !== null){
elements.name.value = name;
Expand Down Expand Up @@ -153,7 +152,7 @@ export async function readFile<T extends RootTag = any>(file: File): Promise<NBT
* Turns the values from the Format Options dialog into the NBT file's metadata.
*/
export function saveOptions(): NBTDataOptions {
const elements = formatForm.elements as FormatOptionsCollection;
const { elements } = formatForm;

const name: Name = (elements.disableName.checked) ? null : elements.name.value;
const endian: Endian = elements.endian.value as Endian;
Expand Down
16 changes: 16 additions & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { defineConfig } from "vite";

export default defineConfig({
base: "./",
build: {
target: "esnext"
},
server: {
port: 5500,
strictPort: true
},
preview: {
port: 5500,
strictPort: true
}
});

0 comments on commit fe31ed1

Please sign in to comment.