Move to Renderer V2

This commit is contained in:
duckietm
2024-04-03 09:27:56 +02:00
parent 110c3ad393
commit b3134ce50b
4080 changed files with 115593 additions and 66375 deletions
+3
View File
@@ -0,0 +1,3 @@
{
"extends": [ "@nitrots/eslint-config" ]
}
+51
View File
@@ -0,0 +1,51 @@
# See http://help.github.com/ignore-files/ for more about ignoring files.
# compiled output
/dist
/tmp
/out-tsc
# Only exists if Bazel was run
/bazel-out
# dependencies
/node_modules
# profiling files
chrome-profiler-events*.json
speed-measure-plugin*.json
# IDEs and editors
/.idea
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace
# IDE - VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
.history/*
# misc
/.sass-cache
/connect.lock
/coverage
/libpeerconnection.log
npm-debug.log
yarn-error.log
testem.log
/typings
.git
# System Files
.DS_Store
Thumbs.db
*.zip
*.as
*.bin
+1
View File
@@ -0,0 +1 @@
export * from './src';
+23
View File
@@ -0,0 +1,23 @@
{
"name": "@nitrots/camera",
"description": "Nitro camera module",
"version": "1.0.0",
"type": "module",
"license": "GPL-3.0",
"scripts": {
"compile": "tsc --project ./tsconfig.json --noEmit false",
"eslint": "eslint ./src --fix"
},
"main": "./index",
"dependencies": {
"@nitrots/api": "1.0.0",
"@nitrots/configuration": "1.0.0",
"@nitrots/eslint-config": "1.0.0",
"@nitrots/events": "1.0.0",
"@nitrots/utils": "1.0.0",
"pixi.js": "^8.0.4"
},
"devDependencies": {
"typescript": "~5.4.2"
}
}
@@ -0,0 +1,5 @@
import { RoomCameraWidgetManager } from './RoomCameraWidgetManager';
const roomCameraWidgetManager = new RoomCameraWidgetManager();
export const GetRoomCameraWidgetManager = () => roomCameraWidgetManager;
@@ -0,0 +1,60 @@
import { IRoomCameraWidgetEffect } from '@nitrots/api';
import { BLEND_MODES, ColorMatrix, Texture } from 'pixi.js';
export class RoomCameraWidgetEffect implements IRoomCameraWidgetEffect
{
private _name: string;
private _minLevel: number = -1;
private _texture: Texture = null;
private _colorMatrix: ColorMatrix = null;
private _blendMode: BLEND_MODES = null;
constructor(name: string, minLevel: number = -1, texture: Texture = null, colorMatrix: ColorMatrix = null, blendMode: BLEND_MODES = null)
{
this._name = name;
this._minLevel = minLevel;
this._texture = texture;
this._colorMatrix = colorMatrix;
this._blendMode = blendMode;
}
public get name(): string
{
return this._name;
}
public get texture(): Texture
{
return this._texture;
}
public set texture(texture: Texture)
{
this._texture = texture;
}
public get colorMatrix(): ColorMatrix
{
return this._colorMatrix;
}
public set colorMatrix(colorMatrix: ColorMatrix)
{
this._colorMatrix = colorMatrix;
}
public get blendMode(): BLEND_MODES
{
return this._blendMode;
}
public set blendMode(blendMode: BLEND_MODES)
{
this._blendMode = blendMode;
}
public get minLevel(): number
{
return this._minLevel;
}
}
@@ -0,0 +1,103 @@
import { IRoomCameraWidgetEffect, IRoomCameraWidgetManager, IRoomCameraWidgetSelectedEffect } from '@nitrots/api';
import { GetAssetManager } from '@nitrots/assets';
import { GetConfiguration } from '@nitrots/configuration';
import { GetEventDispatcher, RoomCameraWidgetManagerEvent } from '@nitrots/events';
import { TextureUtils } from '@nitrots/utils';
import { BLEND_MODES, ColorMatrix, ColorMatrixFilter, Container, Sprite, Texture } from 'pixi.js';
import { RoomCameraWidgetEffect } from './RoomCameraWidgetEffect';
export class RoomCameraWidgetManager implements IRoomCameraWidgetManager
{
private _effects: Map<string, IRoomCameraWidgetEffect>;
private _isLoaded: boolean;
constructor()
{
this._effects = new Map();
this._isLoaded = false;
}
public async init(): Promise<void>
{
if(this._isLoaded) return;
this._isLoaded = true;
const imagesUrl = GetConfiguration().getValue<string>('image.library.url') + 'Habbo-Stories/';
const effects = GetConfiguration().getValue<{ name: string, colorMatrix?: ColorMatrix, minLevel: number, blendMode?: BLEND_MODES, enabled: boolean }[]>('camera.available.effects');
for(const effect of effects)
{
if(!effect.enabled) continue;
const cameraEffect = new RoomCameraWidgetEffect(effect.name, effect.minLevel);
if(effect.colorMatrix.length)
{
cameraEffect.colorMatrix = effect.colorMatrix;
}
else
{
const url = `${ imagesUrl }${ effect.name }.png`;
await GetAssetManager().downloadAsset(url);
cameraEffect.texture = GetAssetManager().getTexture(url);
cameraEffect.blendMode = effect.blendMode;
}
this._effects.set(cameraEffect.name, cameraEffect);
}
GetEventDispatcher().dispatchEvent(new RoomCameraWidgetManagerEvent(RoomCameraWidgetManagerEvent.INITIALIZED));
}
public async applyEffects(texture: Texture, selectedEffects: IRoomCameraWidgetSelectedEffect[], isZoomed: boolean): Promise<HTMLImageElement>
{
const container = new Container();
const sprite = new Sprite(texture);
container.addChild(sprite);
if(isZoomed) sprite.scale.set(2);
for(const selectedEffect of selectedEffects)
{
const effect = selectedEffect.effect;
if(!effect) continue;
if(effect.colorMatrix)
{
const filter = new ColorMatrixFilter();
filter.matrix = effect.colorMatrix;
filter.alpha = selectedEffect.alpha;
if(!Array.isArray(sprite.filters)) sprite.filters = [];
sprite.filters.push(filter);
}
else
{
const effectSprite = new Sprite(effect.texture);
effectSprite.alpha = selectedEffect.alpha;
effectSprite.blendMode = effect.blendMode;
container.addChild(effectSprite);
}
}
return await TextureUtils.generateImage(container);
}
public get effects(): Map<string, IRoomCameraWidgetEffect>
{
return this._effects;
}
public get isLoaded(): boolean
{
return this._isLoaded;
}
}
@@ -0,0 +1,23 @@
import { IRoomCameraWidgetEffect } from '@nitrots/api';
export class RoomCameraWidgetSelectedEffect
{
private _effect: IRoomCameraWidgetEffect;
private _alpha: number;
constructor(effect: IRoomCameraWidgetEffect, alpha: number)
{
this._effect = effect;
this._alpha = alpha;
}
public get effect(): IRoomCameraWidgetEffect
{
return this._effect;
}
public get alpha(): number
{
return this._alpha;
}
}
+4
View File
@@ -0,0 +1,4 @@
export * from './GetRoomCameraWidgetManager';
export * from './RoomCameraWidgetEffect';
export * from './RoomCameraWidgetManager';
export * from './RoomCameraWidgetSelectedEffect';
+31
View File
@@ -0,0 +1,31 @@
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./src",
"outDir": "./dist",
"sourceMap": false,
"declaration": true,
"experimentalDecorators": true,
"moduleResolution": "Node",
"esModuleInterop": true,
"importHelpers": true,
"isolatedModules": true,
"resolveJsonModule": true,
"downlevelIteration": true,
"allowSyntheticDefaultImports": true,
"allowJs": true,
"skipLibCheck": true,
"noEmit": true,
"strict": false,
"strictNullChecks": false,
"target": "ES6",
"lib": [
"DOM",
"DOM.Iterable",
"ESNext"
],
"module": "ES6"
},
"include": [
"src" ]
}