Added Color to the Renderer and Avatar update

This commit is contained in:
duckietm 2024-04-04 09:26:05 +02:00
parent 187622429f
commit 95bc0045ec
11 changed files with 92 additions and 51 deletions

View File

@ -1,5 +1,11 @@
export class AvatarFigurePartType export class AvatarFigurePartType
{ {
public static MALE: string = 'M';
public static FEMALE: string = 'F';
public static UNISEX: string = 'U';
public static SCALE: string = 'h';
public static STD: string = 'std';
public static DEFAULT_FRAME: number = 0;
public static BODY: string = 'bd'; public static BODY: string = 'bd';
public static SHOES: string = 'sh'; public static SHOES: string = 'sh';
public static LEGS: string = 'lg'; public static LEGS: string = 'lg';

View File

@ -9,8 +9,8 @@ export interface IRoomSession
setRoomOwner(): void; setRoomOwner(): void;
start(): boolean; start(): boolean;
reset(roomId: number): void; reset(roomId: number): void;
sendChatMessage(text: string, styleId: number): void; sendChatMessage(text: string, styleId: number, chatColour: string): void;
sendShoutMessage(text: string, styleId: number): void; sendShoutMessage(text: string, styleId: number, chatColour: string): void;
sendWhisperMessage(recipientName: string, text: string, styleId: number): void; sendWhisperMessage(recipientName: string, text: string, styleId: number): void;
sendChatTypingMessage(isTyping: boolean): void; sendChatTypingMessage(isTyping: boolean): void;
sendMottoMessage(motto: string): void; sendMottoMessage(motto: string): void;
@ -20,6 +20,7 @@ export interface IRoomSession
sendPostureMessage(posture: number): void; sendPostureMessage(posture: number): void;
sendDoorbellApprovalMessage(userName: string, flag: boolean): void; sendDoorbellApprovalMessage(userName: string, flag: boolean): void;
sendAmbassadorAlertMessage(userId: number): void; sendAmbassadorAlertMessage(userId: number): void;
sendWhisperGroupMessage(userId: number): void;
sendKickMessage(userId: number): void; sendKickMessage(userId: number): void;
sendMuteMessage(userId: number, minutes: number): void; sendMuteMessage(userId: number, minutes: number): void;
sendBanMessage(userId: number, type: string): void; sendBanMessage(userId: number, type: string): void;

View File

@ -1,25 +1,25 @@
export class FigureDataContainer export class FigureDataContainer
{ {
private static MALE: string = 'M'; public static MALE: string = 'M';
private static FEMALE: string = 'F'; public static FEMALE: string = 'F';
private static UNISEX: string = 'U'; public static UNISEX: string = 'U';
private static SCALE: string = 'h'; public static SCALE: string = 'h';
private static STD: string = 'std'; public static STD: string = 'std';
private static DEFAULT_FRAME: string = '0'; public static DEFAULT_FRAME: string = '0';
private static HD: string = 'hd'; public static HD: string = 'hd';
private static HAIR: string = 'hr'; public static HAIR: string = 'hr';
private static HAT: string = 'ha'; public static HAT: string = 'ha';
private static HEAD_ACCESSORIES: string = 'he'; public static HEAD_ACCESSORIES: string = 'he';
private static EYE_ACCESSORIES: string = 'ea'; public static EYE_ACCESSORIES: string = 'ea';
private static FACE_ACCESSORIES: string = 'fa'; public static FACE_ACCESSORIES: string = 'fa';
private static JACKET: string = 'cc'; public static JACKET: string = 'cc';
private static SHIRT: string = 'ch'; public static SHIRT: string = 'ch';
private static CHEST_ACCESSORIES: string = 'ca'; public static CHEST_ACCESSORIES: string = 'ca';
private static CHEST_PRINTS: string = 'cp'; public static CHEST_PRINTS: string = 'cp';
private static TROUSERS: string = 'lg'; public static TROUSERS: string = 'lg';
private static SHOES: string = 'sh'; public static SHOES: string = 'sh';
private static TROUSER_ACCESSORIES: string = 'wa'; public static TROUSER_ACCESSORIES: string = 'wa';
private static BLOCKED_FX_TYPES: number[] = [28, 29, 30, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 68]; public static BLOCKED_FX_TYPES: number[] = [28, 29, 30, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 68];
private _data: Map<string, number>; private _data: Map<string, number>;
private _colors: Map<string, number[]>; private _colors: Map<string, number[]>;

View File

@ -11,6 +11,7 @@
"main": "./index", "main": "./index",
"dependencies": { "dependencies": {
"@nitrots/api": "1.0.0", "@nitrots/api": "1.0.0",
"@nitrots/assets": "1.0.0",
"@nitrots/configuration": "1.0.0", "@nitrots/configuration": "1.0.0",
"@nitrots/eslint-config": "1.0.0", "@nitrots/eslint-config": "1.0.0",
"@nitrots/events": "1.0.0", "@nitrots/events": "1.0.0",

View File

@ -4,9 +4,9 @@ export class RoomUnitChatComposer implements IMessageComposer<ConstructorParamet
{ {
private _data: ConstructorParameters<typeof RoomUnitChatComposer>; private _data: ConstructorParameters<typeof RoomUnitChatComposer>;
constructor(message: string, styleId: number = 0) constructor(message: string, styleId: number = 0, chatColour: string = '')
{ {
this._data = [message, styleId]; this._data = [message, styleId, chatColour];
} }
public getMessageArray() public getMessageArray()

View File

@ -4,9 +4,9 @@ export class RoomUnitChatShoutComposer implements IMessageComposer<ConstructorPa
{ {
private _data: ConstructorParameters<typeof RoomUnitChatShoutComposer>; private _data: ConstructorParameters<typeof RoomUnitChatShoutComposer>;
constructor(message: string, styleId: number) constructor(message: string, styleId: number, chatColour: string)
{ {
this._data = [message, styleId]; this._data = [message, styleId, chatColour];
} }
public getMessageArray() public getMessageArray()

View File

@ -7,6 +7,7 @@ export class RoomUnitChatParser implements IMessageParser
private _gesture: number; private _gesture: number;
private _bubble: number; private _bubble: number;
private _urls: string[]; private _urls: string[];
private _chatColours: string;
private _messageLength: number; private _messageLength: number;
public flush(): boolean public flush(): boolean
@ -16,6 +17,7 @@ export class RoomUnitChatParser implements IMessageParser
this._gesture = 0; this._gesture = 0;
this._bubble = 0; this._bubble = 0;
this._urls = []; this._urls = [];
this._chatColours = null;
this._messageLength = 0; this._messageLength = 0;
return true; return true;
@ -31,7 +33,8 @@ export class RoomUnitChatParser implements IMessageParser
this._bubble = wrapper.readInt(); this._bubble = wrapper.readInt();
this.parseUrls(wrapper); this.parseUrls(wrapper);
this._chatColours = wrapper.readString();
this._messageLength = wrapper.readInt(); this._messageLength = wrapper.readInt();
return true; return true;
@ -79,6 +82,11 @@ export class RoomUnitChatParser implements IMessageParser
{ {
return this._urls; return this._urls;
} }
public get chatColours(): string
{
return this._chatColours;
}
public get messageLength(): number public get messageLength(): number
{ {

View File

@ -25,13 +25,14 @@ export class RoomSessionChatEvent extends RoomSessionEvent
private _extraParam: number; private _extraParam: number;
private _style: number; private _style: number;
constructor(type: string, session: IRoomSession, objectId: number, message: string, chatType: number, style: number = 0, links: string[] = null, extraParam: number = -1) constructor(type: string, session: IRoomSession, objectId: number, message: string, chatType: number, style: number = 0, chatColours: string[], links: string[] = null, extraParam: number = -1)
{ {
super(type, session); super(type, session);
this._objectId = objectId; this._objectId = objectId;
this._message = message; this._message = message;
this._chatType = chatType; this._chatType = chatType;
this._chatColours = chatColours;
this._links = links; this._links = links;
this._extraParam = extraParam; this._extraParam = extraParam;
this._style = style; this._style = style;
@ -66,4 +67,9 @@ export class RoomSessionChatEvent extends RoomSessionEvent
{ {
return this._style; return this._style;
} }
public get chatColours(): string[]
{
return this._chatColours;
}
} }

View File

@ -1,6 +1,6 @@
import { AlphaTolerance } from '@nitrots/api'; import { AlphaTolerance } from '@nitrots/api';
import { GetRenderer } from '@nitrots/utils'; import { GetRenderer, TextureUtils } from '@nitrots/utils';
import { GlRenderTarget, Point, Sprite, Texture, TextureSource, WebGLRenderer } from 'pixi.js'; import { GlRenderTarget, Point, RendererType, Sprite, Texture, TextureSource, WebGPURenderer } from 'pixi.js';
const BYTES_PER_PIXEL = 4; const BYTES_PER_PIXEL = 4;
@ -56,7 +56,9 @@ export class ExtendedSprite extends Sprite
if((!textureSource || !textureSource.hitMap) && !ExtendedSprite.generateHitMapForTextureSource(textureSource)) return false; if((!textureSource || !textureSource.hitMap) && !ExtendedSprite.generateHitMapForTextureSource(textureSource)) return false;
//@ts-ignore //@ts-ignore
const hitMap = (textureSource.hitMap as U8intclampedArray); const hitMap = (textureSource.hitMap as Uint8Array);
if(!hitMap) return false;
let dx = (point.x + texture.frame.x); let dx = (point.x + texture.frame.x);
let dy = (point.y + texture.frame.y); let dy = (point.y + texture.frame.y);
@ -79,28 +81,40 @@ export class ExtendedSprite extends Sprite
{ {
if(!textureSource) return false; if(!textureSource) return false;
const renderer = GetRenderer();
const width = Math.max(Math.round(textureSource.width * textureSource.resolution), 1); const width = Math.max(Math.round(textureSource.width * textureSource.resolution), 1);
const height = Math.max(Math.round(textureSource.height * textureSource.resolution), 1); const height = Math.max(Math.round(textureSource.height * textureSource.resolution), 1);
const pixels = new Uint8Array(BYTES_PER_PIXEL * width * height);
const renderer = GetRenderer() as WebGLRenderer; let pixels: Uint8ClampedArray = null;
const renderTarget = renderer.renderTarget.getRenderTarget(textureSource); if(renderer instanceof WebGPURenderer)
const glRenterTarget = renderer.renderTarget.getGpuRenderTarget(renderTarget) as GlRenderTarget; {
pixels = TextureUtils.getPixels(new Texture(textureSource))?.pixels ?? null;
}
const gl = renderer.gl; else if(renderer.type === RendererType.WEBGL)
{
pixels = new Uint8ClampedArray(BYTES_PER_PIXEL * width * height);
gl.bindFramebuffer(gl.FRAMEBUFFER, glRenterTarget.resolveTargetFramebuffer); const renderTarget = renderer.renderTarget.getRenderTarget(textureSource);
const glRenderTarget = renderer.renderTarget.getGpuRenderTarget(renderTarget) as GlRenderTarget;
gl.readPixels( const gl = renderer.gl;
0,
0, gl.bindFramebuffer(gl.FRAMEBUFFER, glRenderTarget.resolveTargetFramebuffer);
width,
height, gl.readPixels(
gl.RGBA, 0,
gl.UNSIGNED_BYTE, 0,
pixels width,
); height,
gl.RGBA,
gl.UNSIGNED_BYTE,
pixels
);
}
if(!pixels) return false;
//@ts-ignore //@ts-ignore
textureSource.hitMap = pixels; textureSource.hitMap = pixels;

View File

@ -69,14 +69,14 @@ export class RoomSession implements IRoomSession
this._roomId = roomId; this._roomId = roomId;
} }
public sendChatMessage(text: string, styleId: number): void public sendChatMessage(text: string, styleId: number, chatColour: string): void
{ {
GetCommunication().connection.send(new RoomUnitChatComposer(text, styleId)); GetCommunication().connection.send(new RoomUnitChatComposer(text, styleId, chatColour));
} }
public sendShoutMessage(text: string, styleId: number): void public sendShoutMessage(text: string, styleId: number, chatColour: string): void
{ {
GetCommunication().connection.send(new RoomUnitChatShoutComposer(text, styleId)); GetCommunication().connection.send(new RoomUnitChatShoutComposer(text, styleId, chatColour));
} }
public sendWhisperMessage(recipientName: string, text: string, styleId: number): void public sendWhisperMessage(recipientName: string, text: string, styleId: number): void
@ -126,6 +126,11 @@ export class RoomSession implements IRoomSession
{ {
GetCommunication().connection.send(new RoomAmbassadorAlertComposer(userId)); GetCommunication().connection.send(new RoomAmbassadorAlertComposer(userId));
} }
public sendWhisperGroupMessage(userId: number): void
{
GetCommunication().connection.send(new ChatWhisperGroupComposer(userId));
}
public sendKickMessage(userId: number): void public sendKickMessage(userId: number): void
{ {

View File

@ -37,7 +37,7 @@ export class RoomChatHandler extends BaseHandler
if(event instanceof RoomUnitChatShoutEvent) chatType = RoomSessionChatEvent.CHAT_TYPE_SHOUT; if(event instanceof RoomUnitChatShoutEvent) chatType = RoomSessionChatEvent.CHAT_TYPE_SHOUT;
else if(event instanceof RoomUnitChatWhisperEvent) chatType = RoomSessionChatEvent.CHAT_TYPE_WHISPER; else if(event instanceof RoomUnitChatWhisperEvent) chatType = RoomSessionChatEvent.CHAT_TYPE_WHISPER;
const chatEvent = new RoomSessionChatEvent(RoomSessionChatEvent.CHAT_EVENT, session, parser.roomIndex, parser.message, chatType, parser.bubble); const chatEvent = new RoomSessionChatEvent(RoomSessionChatEvent.CHAT_EVENT, session, parser.roomIndex, parser.message, chatType, parser.bubble, parser.chatColours);
GetEventDispatcher().dispatchEvent(chatEvent); GetEventDispatcher().dispatchEvent(chatEvent);
} }