Skip to content

Commit

Permalink
Merge pull request #2 from spacestation13/zewaka/query-param-code
Browse files Browse the repository at this point in the history
Add functionality to load code from a query param
  • Loading branch information
alexkar598 authored Oct 26, 2024
2 parents 35bf144 + 11653af commit d996855
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/app/components/editor/editor.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Component, ViewChild } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { EditorView } from 'codemirror';
import {
bracketMatching,
Expand Down Expand Up @@ -63,7 +64,7 @@ export class EditorComponent {
@ViewChild('editor')
private editor!: CodeEditor;

constructor(private executor: ExecutorService) {
constructor(private executor: ExecutorService, private route: ActivatedRoute) {
const noDotted = EditorView.theme({
'&.cm-editor.cm-focused': {
outline: 'none',
Expand All @@ -82,6 +83,23 @@ export class EditorComponent {
flexGrow: 1,
},
});

// Check for URL parameter and decode if present
this.route.queryParams.subscribe(params => {
const encodedContent = params['code'];
if (encodedContent) {
const decodedContent = atob(encodedContent);
this.content = `/world/New()
main()
..()
eval("")
shutdown()
/proc/main()
${decodedContent}`
}
});

const darkMode = EditorView.theme({}, { dark: true });

const runCodeEffect = StateEffect.define<void>();
Expand Down Expand Up @@ -156,5 +174,6 @@ export class EditorComponent {
[controlPanel],
[runCodeField],
];

}
}
4 changes: 4 additions & 0 deletions src/vm/byond.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ export class ByondService {
void this.lock.run(async () => {
for await (const version of (await this.getByondFolder()).keys()) {
this._versions.set(version, VersionStatus.Fetched);
// If this is the first version in the list, load it
if (this._activeVersion == null) {
await this.load(version, true);
}
}
});
void this.lock.run(() =>
Expand Down

0 comments on commit d996855

Please sign in to comment.