ProductPromotion
Logo

Angular.JS

made by https://0x3d.site

GitHub - FRACTAL-GAME-STUDIOS/fractal_boilerplate_lua_angular: Basic Angular & Lua - FiveM Boilerplate: A streamlined starter kit for web and in-game development with hot builds and utility scripts
Basic Angular & Lua - FiveM Boilerplate: A streamlined starter kit for web and in-game development with hot builds and utility scripts - FRACTAL-GAME-STUDIOS/fractal_boilerplate_lua_angular
Visit Site

GitHub - FRACTAL-GAME-STUDIOS/fractal_boilerplate_lua_angular: Basic Angular & Lua - FiveM Boilerplate: A streamlined starter kit for web and in-game development with hot builds and utility scripts

GitHub - FRACTAL-GAME-STUDIOS/fractal_boilerplate_lua_angular: Basic Angular & Lua - FiveM Boilerplate: A streamlined starter kit for web and in-game development with hot builds and utility scripts

Fractal Game Studios - Angular Lua Boilerplate

This repository is a basic boilerplate for getting started with Angular in NUI. It contains several helpful utilities and was generated with the Angular CLI. The project is set up with SCSS as stylesheet format. It is for both browser and in-game based development workflows.

For in-game workflows, run npm run watch which will watch the files and build the application upon changes.

This version of the boilerplate is meant for the CfxLua runtime, but should work with other languages if you copy over the web folder and the required fxmanifest.lua entries.

This boilerplate was inspired by the React boilerplate made by Project Error.

Requirements

A basic understanding of the modern web development workflow. If you don't know this yet, Angular will not be for you. To get started with Angular go to https://angular.io/start.

Getting Started

First clone the repository or use the template option and place it within your resources folder

Installation

Install dependencies by navigating to the web folder within a terminal of your choice and type npm i.

Features

This boilerplate comes with some utilities and examples to work off of.

Lua Utils

SendAngularMessage

This is a small wrapper for dispatching NUI messages. This is designed to be used with the fromMessageAction function of the NuiService in Angular.

Signature

---@param action string The action you wish to target
---@param data any The data you wish to send along with this action
SendAngularMessage(action, data)

Usage

SendAngularMessage("setVisible", true)

debugPrint

A debug printing utility that is dependent on a convar, if the convar is set this will print out to the console.

The convar is dependent on the name given to the resource. It follows this format YOUR_RESOURCE_NAME-debugMode

To turn on debugMode add setr YOUR_RESOURCE_NAME-debugMode 1 to your server.cfg or use the setr console command instead.

Signature (Replicates print)

---@param ... any[] The arguments you wish to send
debugPrint(...)

Usage

debugPrint("Is Angular better than React?", true, someOtherVar)

Angular Utils

Signatures are not included for these utilities as the type definitions are sufficient enough.

fromMessageAction

This function returns a subject which can be subscribed to to receive updates for a certain action. This is the primary way of creating passive listeners.

Note: You can register as many observers for the same action as you want.

Usage

export class MyComponent implements OnInit {
	count: number = 0;

	constructor(private nui: NuiService) {}

	ngOnInit(): void {
		// This listens for the "setVisible" message
		this.nui.fromMessageAction<number>("setCount").subscribe({
			next: (value) => {
				// Do whatever logic you want here
				this.counter = value;
			}
		});
	}
}

getLastMessageData

This function returns the last data received for a certain action. Useful when a component is rendered after the event has been dispatched but still needs that data (i.e. an application on a phone which gets updated by a loop).

Usage

export class MyComponent {
    constructor(private data: DataService) {
        let lastData = this.data.getLastMessageData<Player>("updatePlayer");
        if (lastData) {
            this.player = lastData;
        }
    }
}

fetchNui

This is a simple NUI focused wrapper around the standard fetch API. This is the main way to accomplish active NUI data fetching or to trigger NUI callbacks in the game scripts.

When using this, you should always at least callback using {} in the gamescripts.

This can be heavily customized to your use case

Usage

// First argument is the callback event name.
this.nui.fetchNui<ReturnData>("getClientData")
	.then((retData) => {
		console.log("Got return data from client scripts:");
		console.dir(retData);
		setClientData(retData);
	})
	.catch((e) => {
		console.error("Setting mock data due to error", e);
		setClientData({ x: 500, y: 300, z: 200 });
	});

dispatchBackEvents

This is a function allowing for mocking dispatched game script actions in a browser environment. It will trigger fromMessageAction handlers as if they were dispatched by the game scripts. It will only fire if the current environment is a regular browser and not CEF

Usage

// This will target the fromMessageAction observers registered with `setVisible`
// and pass them the data of `true`
this.nui.dispatchBackEvents([
	{
		action: "setVisible",
		data: true
	}
]);

Misc Utils

These are small but useful included utilities.

  • this.nui.isEnvBrowser() - Will return a boolean indicating if the current environment is a regular browser. (Useful for logic in development)

Development Workflow

This boilerplate was designed with development workflow in mind. It includes some helpful scripts to accomplish that.

Hot Builds In-Game

When developing in-game, it's best to use npm run watch. This is similar to ng serve, but it builds the application. Meaning all that is required is a resource restart to update the game script.

Usage

npm run watch

Production Builds

When you are done with development phase for your resource. You must create a production build that is optimized and minimized.f You can do this by running the following:

npm run build

More Resources
to explore the angular.

mail [email protected] to add your project or resources here 🔥.

Related Articles
to learn about angular.

FAQ's
to learn more about Angular JS.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory