Framework icon indicating copy to clipboard operation
Framework copied to clipboard

Strong Node.js / V8 scripting engine

Open Deewarz opened this issue 1 year ago • 2 comments

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:

  • https://github.com/altmp/altv-js-module-v2
  • https://github.com/LeonMrBonnie/altv-example-resources-v2

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 avatar Feb 20 '24 14:02 Deewarz

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)

Deewarz avatar Feb 20 '24 14:02 Deewarz

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

zpl-zak avatar Feb 20 '24 16:02 zpl-zak

Closing this as NodeJS is not supported anymore.

Segfaultd avatar Aug 26 '24 19:08 Segfaultd