Skip to content

Commit

Permalink
This will surely work first try (I have not built yet, but will in a …
Browse files Browse the repository at this point in the history
…bit)
  • Loading branch information
lyxal committed Jan 13, 2025
1 parent dfa7314 commit c4d84ea
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/latest/data/releaseDates.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
38 changes: 37 additions & 1 deletion src/latest/scripts/interpreter/permalink.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import compatRaw from "../../data/compat.json?raw";
import datesRaw from "../../data/releaseDates.json?raw";
import { gunzipString, gzipString } from "gzip-utils";

const compat = JSON.parse(compatRaw);
const releaseDates = JSON.parse(datesRaw);
const LATEST_VYXAL_VERSION_CONSTANT_RETURNED_FROM_DETERMINE_VERSION = "hacky ahh solution"

type OldPermalinks = {
format: 2,
Expand All @@ -13,7 +16,7 @@ type OldPermalinks = {
version: string,
};

const latestPermalink = 3;
const latestPermalink = 4;
export type Permalink = {
format: typeof latestPermalink,
flags: string[],
Expand All @@ -24,7 +27,39 @@ export type Permalink = {
version: string,
};

function decodeVersion(version: string): string {
// This is what happens when you let lyxal write a hack
// solution to something that probably required a bigger
// refactoring. (Comment written by, surprisingly, lyxal)

// Version will either be `x.y.z` or `dd/mm/yyyy`. So
// determine which one it is. If `x.y.z`, simply return
// it.

if (version.includes(".")) {
return version;
}

// It's a date, which means fun because that's the whole
// point of this function. The version can be determined
// by finding the first release on a date after the given
// date.

// But first, convert the string to a date object.
const date = new Date(version);

// Now, iterate through the release dates and find the
// first release after the given date.

const candidates = Object.entries(releaseDates).filter(([_, d]) => new Date(d.toString()) > date);
if (candidates.length === 0) {
return LATEST_VYXAL_VERSION_CONSTANT_RETURNED_FROM_DETERMINE_VERSION;
}
return candidates[0][1].toString();
}

function incompatible(permalinkVersion: string) {
if (permalinkVersion === LATEST_VYXAL_VERSION_CONSTANT_RETURNED_FROM_DETERMINE_VERSION) { return true; }
return compat[permalinkVersion] ?? false;
}

Expand Down Expand Up @@ -84,6 +119,7 @@ export async function decodeHash(hash: string): Promise<DecodeResult | null> {
}
}
try {
let realVersion = decodeVersion(permalink.version);
if (incompatible(permalink.version)) {
return { compatible: false, version: permalink.version };
}
Expand Down
11 changes: 6 additions & 5 deletions src/latest/scripts/ui/Theseus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ export function Theseus({ permalink }: TheseusProps) {

const [state, setState] = useState<RunState>({ name: autorun ? "starting" : "idle" });
const [lastFocusedEditor, setLastFocusedEditor] = useState<ReactCodeMirrorRef | null>(null);

const runnerRef = useRef<VyTerminalRef | null>(null);
const snowflakesRef = useRef<Snowflakes | null>(null);

useEffect(() => {
switch (settingsState.theme) {
case Theme.Dark:
Expand Down Expand Up @@ -109,13 +109,14 @@ export function Theseus({ permalink }: TheseusProps) {
}, [settingsState]);

useEffect(() => {
const date = new Date();
encodeHash({
header,
code,
footer,
flags: [...serializeFlags(elementData.flagDefs, flags)],
inputs: inputs.map(({ name, inputs }) => [name, inputs.map(({ input }) => input)]),
version: elementData.version,
version: `${date.getDate()}/${date.getMonth() + 1}/${date.getFullYear()}`,
}).then((hash) => history.replaceState(undefined, "", "#" + hash));
}, [header, code, footer, flags, inputs, elementData]);

Expand All @@ -134,7 +135,7 @@ export function Theseus({ permalink }: TheseusProps) {
utilWorker.formatBytecount(code, literate).then(setBytecount);
}, [code, flags, utilWorker, literate]);

const literateToSbcs = useCallback(async() => {
const literateToSbcs = useCallback(async () => {
runnerRef.current?.showMessage(`\x1b[1mSBCS translation:\x1b[0m\n${await utilWorker.sbcsify(code)}`);
}, [code, runnerRef, utilWorker]);

Expand Down Expand Up @@ -174,7 +175,7 @@ export function Theseus({ permalink }: TheseusProps) {
if (view != null) {
view.dispatch(view.state.replaceSelection(char));
}
}}
}}
/>
<div className="w-100 h-100 vstack">
<Header
Expand Down

0 comments on commit c4d84ea

Please sign in to comment.