Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring/cleanup #8

Merged
merged 4 commits into from
Feb 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions public/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import {FloorFurniture} from "../src/objects/furnitures/FloorFurniture";
import {WallFurniture} from "../src/objects/furnitures/WallFurniture";
import {random} from "gsap/gsap-core";
import {Avatar} from "../src/objects/avatars/Avatar";
import {FloorPosition} from "../src/interfaces/Furniture.interface";
import {Direction} from "../src/types/Direction";
import {IFloorPosition} from "../src/interfaces/Furniture.interface";
import {Direction} from "../src/enums/Direction";
import {AvatarAction} from "../src/objects/avatars/actions/AvatarAction";

(async ()=>{
Expand Down Expand Up @@ -171,7 +171,7 @@ import {AvatarAction} from "../src/objects/avatars/actions/AvatarAction";
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";

const room = new Room(renderer, {
tileMap: tileMap2,
tileMap: tileMap4,
/*floorMaterial: new FloorMaterial(renderer, 110),
wallMaterial: new WallMaterial(renderer, 1501)*/
//floorMaterial: new FloorMaterial(renderer, 307),
Expand Down
76 changes: 60 additions & 16 deletions src/Scuti.ts
Original file line number Diff line number Diff line change
@@ -1,56 +1,92 @@
import {Application, Assets, BaseTexture, Container, MIPMAP_MODES, SCALE_MODES, settings} from "pixi.js";
import {RendererConfiguration} from "./interfaces/Configuration.interface";
import {Logger} from "./utilities/Logger";
import {PixiPlugin} from "gsap/PixiPlugin";
import {gsap} from "gsap";
import { Application, Assets, BaseTexture, Container, SCALE_MODES, settings } from "pixi.js";
import { IRendererConfiguration } from "./interfaces/Configuration.interface";
import { Logger } from "./utilities/Logger";
import { PixiPlugin } from "gsap/PixiPlugin";
import { gsap } from "gsap";

/**
* Convenience class to create a new Scuti renderer.
*
* This class automatically load all the needed resources and initialise the PixiJS application.
* @example
* import { Scuti } from 'scuti-renderer';
*
* // Create the renderer
* const renderer = new Scuti({
* canvas: document.getElementById("app"),
* width: window.innerWidth,
* height: window.innerHeight,
* resources: './resources'
* });
* await renderer.loadResources();
*
* @class
* @memberof Scuti
*/
export class Scuti {

/**
* The canvas that the game engine will use.
* The canvas that will be used to render the PixiJS canvas.
*
* @member {HTMLElement}
* @private
*/
private _canvas: HTMLElement;

/**
* PIXI.js application.
* The PixiJS application instance that will be used to render everything.
*
* @member {Application}
* @private
*/
private _application: Application;

/**
* The renderer logger
* The renderer logger instance.
*
* @member {Logger}
* @private
*/
private _logger: Logger = new Logger("Scuti");

/**
* Game engine main class.
* @param configuration - The game engine configuration.
*/
* @param {IRendererConfiguration} [configuration] - The renderer configuration.
* @param {HTMLElement} [configuration.canvas] - The canvas that will be used to render everything.
* @param {number} [configuration.width] - The width of the render part.
* @param {number} [configuration.height] - The height of the render part.
* @param {string} [configuration.resources] - The URL of the resource server.
**/
constructor(
private configuration: RendererConfiguration
private configuration: IRendererConfiguration
) {
this._logger.info("⚡ Scuti Renderer - v1.0.0");
/** Change the PixiJS settings and default settings */
settings.RESOLUTION = 1;
Container.defaultSortableChildren = true;
BaseTexture.defaultOptions.scaleMode = SCALE_MODES.NEAREST;
/** Register the plugins */
gsap.registerPlugin(PixiPlugin);
/** Create the PixiJS application */
this._application = new Application({
width: configuration.width,
height: configuration.height,
resolution: 1,
antialias: false,
});
this._canvas = configuration.canvas;
// @ts-ignore
/** Append it to the canvas */
this._canvas.append(this._application.view);
}

/**
* Load all the needed ressources
* It loads all the resources that are essentials for rendering rooms and objects.
* It's necessary to call this method just after the instanciation of this class.
*
* @member {Promise<void>}
* @public
*/
public async loadResources(): Promise<void> {
/** Add all the resources */
Assets.add("room/materials", "http://127.0.0.1:8081/generic/room/room_data.json");
Assets.add("room/room", "http://127.0.0.1:8081/generic/room/room.json");
Assets.add("room/cursors", "http://127.0.0.1:8081/generic/tile_cursor/tile_cursor.json");
Expand All @@ -62,6 +98,7 @@ export class Scuti {
Assets.add("figures/actions", "http://127.0.0.1:8081/generic/HabboAvatarActions.json");
Assets.add("figures/partsets", "http://127.0.0.1:8081/generic/HabboAvatarPartSets.json");
Assets.add("figures/animations", "http://127.0.0.1:8081/generic/HabboAvatarAnimations.json");
/** And now load them */
await Assets.load("room/materials");
await Assets.load("room/room");
await Assets.load("room/cursors");
Expand All @@ -76,15 +113,22 @@ export class Scuti {
}

/**
* Return the PIXI.js application
* Reference to the PixiJS application instance.
*
* @member {Application}
* @readonly
* @public
*/
public get application(): Application {
return this._application;
}

/**
* Return the renderer logger
* Reference to the renderer logger instance.
*
* @member {Logger}
* @readonly
* @public
*/
public get logger(): Logger {
return this._logger;
Expand Down
16 changes: 16 additions & 0 deletions src/enums/Direction.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* Direction enum regroup the 8 directions that an avatar can handle on Habbo.
*
* @enum
* @memberof Scuti
*/
export enum Direction {
NORTH, /** Direction 0 */
NORTH_EAST, /** Direction 1 */
EAST, /** Direction 2 */
SOUTH_EAST, /** Direction 3 */
SOUTH, /** Direction 4 */
SOUTH_WEST, /** Direction 5 */
WEST, /** Direction 6 */
NORTH_WEST /** Direction 7 */
}
11 changes: 11 additions & 0 deletions src/enums/StairType.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* StairType enum regroup the 3 differents type of stairs available on Habbo.
*
* @enum
* @memberof Scuti
*/
export enum StairType {
INNER_CORNER_STAIR,
OUTER_CORNER_STAIR,
STAIR
}
12 changes: 12 additions & 0 deletions src/enums/WallType.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* WallType enum regroup the 3 differents type of walls available on Habbo.
*
* @enum
* @memberof Scuti
*/
export enum WallType {
CORNER_WALL,
LEFT_WALL,
RIGHT_WALL,
DOOR_WALL
}
14 changes: 7 additions & 7 deletions src/interfaces/Avatar.interface.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import {Direction} from "../types/Direction";
import {FloorPosition} from "./Furniture.interface";
import {AvatarAction} from "../objects/avatars/actions/AvatarAction";
import { Direction } from "../enums/Direction";
import { IFloorPosition } from "./Furniture.interface";
import { AvatarAction } from "../objects/avatars/actions/AvatarAction";

export type AvatarFigure = Map<string, { setId: number, colors: number[] }>;

export interface IAvatarConfiguration {
figure: string,
position: FloorPosition,
position: IFloorPosition,
bodyDirection: Direction,
headDirection: Direction,
actions: AvatarAction[]
}

export type AvatarFigure = Map<string, { setId: number, colors: number[] }>;

export interface IAvatarPart {
colorable: number,
colorindex: number
Expand Down Expand Up @@ -75,7 +75,7 @@ export interface IAvatarPartSets {
}
}

export interface AvatarLayerConfiguration {
export interface IAvatarLayerConfiguration {
type: string,
part: IAvatarPart,
gesture: string,
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/Configuration.interface.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export interface RendererConfiguration {
export interface IRendererConfiguration {
canvas: HTMLElement,
width: number,
height: number,
Expand Down
20 changes: 10 additions & 10 deletions src/interfaces/Furniture.interface.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
import { Direction } from "../types/Direction";
import { Direction } from "../enums/Direction";
import { BLEND_MODES } from "pixi.js";

export interface FloorPosition {
export interface IFloorPosition {
x: number,
y: number,
z: number
}

export interface FloorFurnitureConfiguration {
export interface IFloorFurnitureConfiguration {
id: number,
position: FloorPosition,
position: IFloorPosition,
direction: Direction,
state?: number
}

export interface WallPosition {
export interface IWallPosition {
x: number,
y: number,
offsetX: number,
offsetY: number
}

export interface WallFurnitureConfiguration {
export interface IWallFurnitureConfiguration {
id: number,
position: WallPosition,
position: IWallPosition,
direction: Direction,
state?: number
}
Expand All @@ -32,7 +32,7 @@ export type FurnitureFrameId = number;

export type FurnitureLayerId = number;

export interface FurnitureData {
export interface IFurnitureData {
id: number,
className: string,
name: string,
Expand All @@ -53,7 +53,7 @@ export interface FurnitureData {
canLayOn: boolean
}

export interface FurnitureVisualization {
export interface IFurnitureVisualization {
layerCount: number,
directions: number[],
colors: number[],
Expand All @@ -69,7 +69,7 @@ export interface FurnitureVisualization {
}[][]
}

export interface FurnitureLayerConfiguration {
export interface IFurnitureLayerConfiguration {
layer: FurnitureLayerId | string,
alpha: number,
tint: number,
Expand Down
35 changes: 18 additions & 17 deletions src/interfaces/Room.interface.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import {StairType} from "../types/StairType";
import {Direction} from "../types/Direction";
import {WallType} from "../types/WallType";
import {Material} from "../objects/rooms/materials/Material";
import { StairType } from "../enums/StairType";
import { Direction } from "../enums/Direction";
import { WallType } from "../enums/WallType";
import { Material } from "../objects/rooms/materials/Material";

export interface RoomConfiguration {
export type TileMap = string[][];

export interface IRoomConfiguration {
tileMap: string,
floorMaterial?: Material,
floorThickness?: number,
Expand All @@ -12,46 +14,45 @@ export interface RoomConfiguration {
wallThickness?: number
}

export interface TileConfiguration {
export interface ITileConfiguration {
material?: Material,
thickness?: number,
position: Position
position: IPosition3D
}

// TODO: Replace with FloorConfiguration?
export interface StairConfiguration {
export interface IStairConfiguration {
material?: Material,
thickness?: number,
type: StairType,
position: Position
position: IPosition3D
}

export interface WallConfiguration {
export interface IWallConfiguration {
material?: Material,
thickness?: number,
height?: number,
position: Position,
position: IPosition3D,
type: WallType,
door?: boolean,
}

export interface CursorConfiguration {
position: Position
export interface ICursorConfiguration {
position: IPosition3D
}

export interface Position {
export interface IPosition3D {
x: number,
y: number,
z: number,
direction?: number
}

export interface Position2D {
export interface IPosition2D {
x: number,
y: number
}

export interface TileInfo {
export interface ITileInfo {
tile: boolean,
door: boolean,
height: number,
Expand Down
Loading