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
{
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 SHOES: string = 'sh';
public static LEGS: string = 'lg';

View File

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

View File

@ -1,25 +1,25 @@
export class FigureDataContainer
{
private static MALE: string = 'M';
private static FEMALE: string = 'F';
private static UNISEX: string = 'U';
private static SCALE: string = 'h';
private static STD: string = 'std';
private static DEFAULT_FRAME: string = '0';
private static HD: string = 'hd';
private static HAIR: string = 'hr';
private static HAT: string = 'ha';
private static HEAD_ACCESSORIES: string = 'he';
private static EYE_ACCESSORIES: string = 'ea';
private static FACE_ACCESSORIES: string = 'fa';
private static JACKET: string = 'cc';
private static SHIRT: string = 'ch';
private static CHEST_ACCESSORIES: string = 'ca';
private static CHEST_PRINTS: string = 'cp';
private static TROUSERS: string = 'lg';
private static SHOES: string = 'sh';
private 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 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: string = '0';
public static HD: string = 'hd';
public static HAIR: string = 'hr';
public static HAT: string = 'ha';
public static HEAD_ACCESSORIES: string = 'he';
public static EYE_ACCESSORIES: string = 'ea';
public static FACE_ACCESSORIES: string = 'fa';
public static JACKET: string = 'cc';
public static SHIRT: string = 'ch';
public static CHEST_ACCESSORIES: string = 'ca';
public static CHEST_PRINTS: string = 'cp';
public static TROUSERS: string = 'lg';
public static SHOES: string = 'sh';
public static TROUSER_ACCESSORIES: string = 'wa';
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 _colors: Map<string, number[]>;

View File

@ -11,6 +11,7 @@
"main": "./index",
"dependencies": {
"@nitrots/api": "1.0.0",
"@nitrots/assets": "1.0.0",
"@nitrots/configuration": "1.0.0",
"@nitrots/eslint-config": "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>;
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()

View File

@ -4,9 +4,9 @@ export class RoomUnitChatShoutComposer implements IMessageComposer<ConstructorPa
{
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()

View File

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

View File

@ -25,13 +25,14 @@ export class RoomSessionChatEvent extends RoomSessionEvent
private _extraParam: 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);
this._objectId = objectId;
this._message = message;
this._chatType = chatType;
this._chatColours = chatColours;
this._links = links;
this._extraParam = extraParam;
this._style = style;
@ -66,4 +67,9 @@ export class RoomSessionChatEvent extends RoomSessionEvent
{
return this._style;
}
public get chatColours(): string[]
{
return this._chatColours;
}
}

View File

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

View File

@ -69,14 +69,14 @@ export class RoomSession implements IRoomSession
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
@ -127,6 +127,11 @@ export class RoomSession implements IRoomSession
GetCommunication().connection.send(new RoomAmbassadorAlertComposer(userId));
}
public sendWhisperGroupMessage(userId: number): void
{
GetCommunication().connection.send(new ChatWhisperGroupComposer(userId));
}
public sendKickMessage(userId: number): void
{
GetCommunication().connection.send(new RoomKickUserComposer(userId));

View File

@ -37,7 +37,7 @@ export class RoomChatHandler extends BaseHandler
if(event instanceof RoomUnitChatShoutEvent) chatType = RoomSessionChatEvent.CHAT_TYPE_SHOUT;
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);
}