Skip to content
This repository has been archived by the owner on Jun 5, 2024. It is now read-only.

Commit

Permalink
add editor
Browse files Browse the repository at this point in the history
  • Loading branch information
Stuyk committed Apr 2, 2023
1 parent 71db7b8 commit adc7394
Show file tree
Hide file tree
Showing 26 changed files with 8,410 additions and 111 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,6 @@ yarn.lock

# Resources
resources/core/**
resources/webviews/**
resources/webviews/**

typedefs.d.ts
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@
## 5.0.0

```
- Fixed Character Select Event Bug
- Added in-game editor for debug mode / admins
--- Command is /editor
- Fixed restrict function
--------------------------------------
--- Everything Below is Before April 2
--------------------------------------
Major Breaking Changes
---> These changes reflect a larger set of changes that will be occuring to the framework during the 5.0.0 release window.
---> These changes are necessary to scale the framework more and lower the complexity of the framework further.
Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"cdn": "node ./scripts/runtime/index.js --start --cdn",
"[-] Updating, Installing, Cleanup": "",
"update": "npx altv-pkg d release",
"check": "tsc --noEmit -p ./tsconfig.json | node ./scripts/fileChecker/index.js",
"check": "tsc -p ./tsconfig.json | node ./scripts/fileChecker/index.js",
"fix": "node ./scripts/doctor/index.js",
"[-] Vue WebView Deployment": "",
"vue-dev": "node ./scripts/plugins/webview && node ./scripts/plugins/files && npx vite ./src-webviews --clearScreen=false --host=localhost --port=3000",
Expand Down Expand Up @@ -51,6 +51,7 @@
"typedoc-plugin-missing-exports": "^1.0.0",
"typescript": "4.6.3",
"vite": "^4.2.0",
"vite-plugin-monaco-editor": "^1.1.0",
"vue": "^3.2.47"
},
"dependencies": {
Expand All @@ -72,6 +73,6 @@
"trailingComma": "all"
},
"engines": {
"node": ">=17.0.0"
"node": ">=18.0.0"
}
}
}
1 change: 1 addition & 0 deletions src-webviews/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import { CORE_IMPORTS } from './pages/components';
import { PLUGIN_IMPORTS } from './plugins/imports';
import { WebViewEventNames } from '../../src/core/shared/enums/webViewEvents';
import VueDevMenu from './components/VueDevMenu.vue';
import './utility/state';
// Interfaces
import IPageData from './interfaces/IPageData';
Expand Down
26 changes: 26 additions & 0 deletions src-webviews/src/utility/state.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const state: { [key: string]: any } = {};

/**
* Set state that can be transferred between page instances.
*
* @export
* @param {string} key
* @param {*} value
*/
export function set(key: string, value: any) {
state[key] = value;
}

/**
* Get state by key value.
*
* Specify a generic type to automatically transform to that type.
*
* @export
* @template T
* @param {string} key
* @return {T}
*/
export function get<T>(key: string): T | undefined {
return state[key];
}
3 changes: 2 additions & 1 deletion src-webviews/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { defineConfig } from 'vite';
import * as path from 'path';
import vue from '@vitejs/plugin-vue';
import monacoEditorPlugin from 'vite-plugin-monaco-editor';

// https://vitejs.dev/config/
export default defineConfig({
plugins: [vue()],
plugins: [vue(), monacoEditorPlugin['default']({ languageWorkers: ['typescript'] })],
base: './',
build: {
outDir: '../resources/webviews',
Expand Down
182 changes: 91 additions & 91 deletions src/core/client/views/input.ts
Original file line number Diff line number Diff line change
@@ -1,96 +1,96 @@
import * as alt from 'alt-client';
import * as AthenaClient from '@AthenaClient/api';

import { InputMenu, InputResult } from '@AthenaShared/interfaces/inputMenus';
import { View_Events_Input_Menu } from '@AthenaShared/enums/views';
import ViewModel from '@AthenaClient/models/viewModel';

const PAGE_NAME = 'InputBox';
let inputMenu: InputMenu;

/**
* Do Not Export Internal Only
*/
class InternalFunctions implements ViewModel {
static async show(_inputMenu: InputMenu): Promise<void> {
inputMenu = _inputMenu;

if (AthenaClient.webview.isAnyMenuOpen()) {
return;
}

// Need to add a sleep here because wheel menu inputs can be be too quick.
await alt.Utils.wait(150);

const view = await AthenaClient.webview.get();
view.on(`${PAGE_NAME}:Ready`, InternalFunctions.ready);
view.on(`${PAGE_NAME}:Submit`, InternalFunctions.submit);

AthenaClient.webview.openPages(PAGE_NAME, true, InternalFunctions.close);
AthenaClient.webview.focus();
AthenaClient.webview.showCursor(true);

alt.toggleGameControls(false);
alt.Player.local.isMenuOpen = true;
}

static async close(isNotCancel = false, shouldClosePage = false) {
alt.toggleGameControls(true);

const view = await AthenaClient.webview.get();
view.off(`${PAGE_NAME}:Ready`, InternalFunctions.ready);
view.off(`${PAGE_NAME}:Submit`, InternalFunctions.submit);

AthenaClient.webview.unfocus();
AthenaClient.webview.showCursor(false);

alt.Player.local.isMenuOpen = false;

if (shouldClosePage) {
AthenaClient.webview.closePages([PAGE_NAME], true);
}

if (isNotCancel) {
return;
}

if (inputMenu.callback) {
inputMenu.callback(null);
}

if (inputMenu.serverEvent) {
alt.emitServer(inputMenu.serverEvent, null);
}
}

static submit(results: InputResult[]) {
if (inputMenu.callback) {
inputMenu.callback(results);
}

if (inputMenu.serverEvent) {
alt.emitServer(inputMenu.serverEvent, results);
}

InternalFunctions.close(true, true);
}

static async ready() {
const view = await AthenaClient.webview.get();
view.emit(`${PAGE_NAME}:SetMenu`, inputMenu.title, inputMenu.options, inputMenu.generalOptions);
}
}

export class InputView {
/**
* Show an input menu from client-side.
* @static
* @param {InputMenu} _inputMenu
*
*/
static setMenu(_inputMenu: InputMenu) {
InternalFunctions.show(_inputMenu);
}
}
// import { InputMenu, InputResult } from '@AthenaShared/interfaces/inputMenus';
// import { View_Events_Input_Menu } from '@AthenaShared/enums/views';
// import ViewModel from '@AthenaClient/models/viewModel';

// const PAGE_NAME = 'InputBox';
// let inputMenu: InputMenu;

// /**
// * Do Not Export Internal Only
// */
// class InternalFunctions implements ViewModel {
// static async show(_inputMenu: InputMenu): Promise<void> {
// inputMenu = _inputMenu;

// if (AthenaClient.webview.isAnyMenuOpen()) {
// return;
// }

// // Need to add a sleep here because wheel menu inputs can be be too quick.
// await alt.Utils.wait(150);

// const view = await AthenaClient.webview.get();
// view.on(`${PAGE_NAME}:Ready`, InternalFunctions.ready);
// view.on(`${PAGE_NAME}:Submit`, InternalFunctions.submit);

// AthenaClient.webview.openPages(PAGE_NAME, true, InternalFunctions.close);
// AthenaClient.webview.focus();
// AthenaClient.webview.showCursor(true);

// alt.toggleGameControls(false);
// alt.Player.local.isMenuOpen = true;
// }

// static async close(isNotCancel = false, shouldClosePage = false) {
// alt.toggleGameControls(true);

// const view = await AthenaClient.webview.get();
// view.off(`${PAGE_NAME}:Ready`, InternalFunctions.ready);
// view.off(`${PAGE_NAME}:Submit`, InternalFunctions.submit);

// AthenaClient.webview.unfocus();
// AthenaClient.webview.showCursor(false);

// alt.Player.local.isMenuOpen = false;

// if (shouldClosePage) {
// AthenaClient.webview.closePages([PAGE_NAME], true);
// }

// if (isNotCancel) {
// return;
// }

// if (inputMenu.callback) {
// inputMenu.callback(null);
// }

// if (inputMenu.serverEvent) {
// alt.emitServer(inputMenu.serverEvent, null);
// }
// }

// static submit(results: InputResult[]) {
// if (inputMenu.callback) {
// inputMenu.callback(results);
// }

// if (inputMenu.serverEvent) {
// alt.emitServer(inputMenu.serverEvent, results);
// }

// InternalFunctions.close(true, true);
// }

// static async ready() {
// const view = await AthenaClient.webview.get();
// view.emit(`${PAGE_NAME}:SetMenu`, inputMenu.title, inputMenu.options, inputMenu.generalOptions);
// }
// }

// export class InputView {
// /**
// * Show an input menu from client-side.
// * @static
// * @param {InputMenu} _inputMenu
// *
// */
// static setMenu(_inputMenu: InputMenu) {
// InternalFunctions.show(_inputMenu);
// }
// }

alt.onServer(View_Events_Input_Menu.SetMenu, InternalFunctions.show);
2 changes: 2 additions & 0 deletions src/core/client/webview/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ export class Page {
*
*/
async open(): Promise<boolean> {
console.log(this);

if (this.info.keybind && this.info.keybind.useSameKeyToClose) {
if (AthenaClient.webview.isPageOpen(this.info.name)) {
this.close(true);
Expand Down
47 changes: 47 additions & 0 deletions src/core/plugins/athena-debug/client/index.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,65 @@
import * as alt from 'alt-client';
import * as native from 'natives';
import * as AthenaClient from '@AthenaClient/api';

import { ATHENA_DEBUG_EVENTS } from '../shared/events';
import { onTicksStart } from '@AthenaClient/events/onTicksStart';

const F1_KEY = 112;
let page: AthenaClient.webview.Page;

function init() {
if (!alt.debug) {
return;
}

page = new AthenaClient.webview.Page({
name: 'Editor',
callbacks: { onReady() {}, onClose() {} },
options: {
disableEscapeKey: true,
onOpen: {
blurBackground: true,
disableControls: 'all',
disablePauseMenu: true,
focus: true,
hideHud: true,
hideOverlays: true,
setIsMenuOpenToTrue: true,
showCursor: true,
},
onClose: {
enableControls: true,
enablePauseMenu: true,
hideCursor: true,
setIsMenuOpenToFalse: true,
showHud: true,
showOverlays: true,
unblurBackground: true,
unfocus: true,
},
},
});

alt.on('keyup', (key: number) => {
if (key !== F1_KEY) {
return;
}

alt.emitServer(ATHENA_DEBUG_EVENTS.ClientToServer.FORWARD);
});

alt.onServer(ATHENA_DEBUG_EVENTS.toClient.exec, (code: string) => {
eval(code);
});

AthenaClient.webview.on(ATHENA_DEBUG_EVENTS.toClient.closePage, () => {
page.close(true);
});

alt.onServer(ATHENA_DEBUG_EVENTS.toClient.openExec, () => {
page.open();
});
}

onTicksStart.add(init);
Loading

0 comments on commit adc7394

Please sign in to comment.