Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strong Node.js / V8 scripting engine #108

Open
Deewarz opened this issue Feb 20, 2024 · 2 comments
Open

Strong Node.js / V8 scripting engine #108

Deewarz opened this issue Feb 20, 2024 · 2 comments
Labels
help wanted Extra attention is needed priority:high

Comments

@Deewarz
Copy link
Contributor

Deewarz commented Feb 20, 2024

Summary

This issue is based on the current implementation made in the Framework and MafiaMP.

Currently, scripting DX is quite unpleasant:

  • Missing some error stack trace (probably Node.js related) (eg. unable to load a file (MODULE_NOT_FOUND), code error...)
  • Missing timer features (setTimeout, setInterval...)
  • Missing modern ES features (ES Module, Promise...)
  • Missing sourceMaps support
  • If package.json "main" file is in subdirectory, the execution context is still "/gamemode". (Imports will fail)
  • SDK is global instead of imported (eg. import * as sdk from "@mafiamp/server") (see: [RFC] Scripting API)
  • Events use multiple arguments instead of a context object (see: [RFC] Scripting API)
  • Missing managers (eg. get all players, get player by id, get all vehicles, get vehicle by id...)
  • Missing "tick" event (eg. sdk.on('tick', () => {})
  • Missing client-side SDK
  • Missing webview support
  • Missing metadata attachment to entity (low priority)

Inspiration

A very good implementation is done here:

This implementation follows [RFC] Scripting API and covers most of the points above.
It is perhaps a little too advanced for our current needs but can serve as a good basis for our implementation.

Todo (by priority order)

  • Reorganize code (shared, server, client) (classes, namespaces, events...)
  • Use package.json "main" path as execution context
  • Support for ES module instead of CommonJS (import foo from "bar" instead of const foo = require("bar"))
  • Consider SDKs as modules (eg. for MafiaMP: @mafiamp/shared, @mafiamp/server, @mafiamp/client)
  • Events : pass context object instead of multiple arguments
  • Support for SetTimeout
  • Support for SetInterval
  • Support for "tick" event (eg. sdk.on('tick', () => {})
  • Support for sourceMaps
  • Support for Promise / async operations (non blocking) (eg. uses for MafiaMP: createVehicle, exit/enter vehicle, animations...)
  • Player manager (eg. get all players, get player by id...)
  • Vehicle manager (eg. get all vehicles, get vehicle by id...)
  • Use enums for events names in C++ (for MafiaMP)
  • Client side scripting SDK
  • Webview support
  • Types definitions package on NPM (for MafiaMP)
  • Gamemode boilerplate in JavaScript (for MafiaMP)
  • Gamemode boilerplate in TypeScript (for MafiaMP)
@Deewarz Deewarz added help wanted Extra attention is needed priority:high labels Feb 20, 2024
@Deewarz
Copy link
Contributor Author

Deewarz commented Feb 20, 2024

I can help with JavaScript / TypeScript and simple C++.

But the main thing requires advanced skills in C++, V8 and Node.js.


I have already made the basis for type definitions but it requires:

  • Support for ES module instead of CommonJS (import foo from "bar" instead of const foo = require("bar"))
  • Consider SDKs as modules (eg. for MafiaMP: @mafiamp/shared, @mafiamp/server, @mafiamp/client)

@zpl-zak
Copy link
Member

zpl-zak commented Feb 20, 2024

Track all related issues in https://github.com/orgs/MafiaHub/projects/5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed priority:high
Projects
Status: No status
Status: No status
Development

No branches or pull requests

2 participants