mirror of
https://github.com/billsonnn/nitro-react.git
synced 2024-11-30 08:50:51 +01:00
Add avatar-info widget utilites
This commit is contained in:
parent
535c9560df
commit
606b3ad965
@ -0,0 +1,31 @@
|
||||
import { IObjectData } from 'nitro-renderer';
|
||||
|
||||
export class FurnitureInfoData
|
||||
{
|
||||
constructor(
|
||||
public id: number = 0,
|
||||
public category: number = 0,
|
||||
public name: string = '',
|
||||
public description: string = '',
|
||||
public image: HTMLImageElement = null,
|
||||
public isWallItem: boolean = false,
|
||||
public isStickie: boolean = false,
|
||||
public isRoomOwner: boolean = false,
|
||||
public roomControllerLevel: number = 0,
|
||||
public isAnyRoomController: boolean = false,
|
||||
public expiration: number = -1,
|
||||
public purchaseCatalogPageId: number = -1,
|
||||
public purchaseOfferId: number = -1,
|
||||
public extraParam: string = '',
|
||||
public isOwner: boolean = false,
|
||||
public stuffData: IObjectData = null,
|
||||
public groupId: number = 0,
|
||||
public ownerId: number = 0,
|
||||
public ownerName: string = '',
|
||||
public usagePolicy: number = 0,
|
||||
public rentCatalogPageId: number = -1,
|
||||
public rentOfferId: number = -1,
|
||||
public purchaseCouldBeUsedForBuyout: boolean = false,
|
||||
public rentCouldBeUsedForBuyout: boolean = false,
|
||||
public availableForBuildersClub: boolean = false) {}
|
||||
}
|
113
src/views/room/widgets/avatar-info/utils/GetFurnitureInfoData.ts
Normal file
113
src/views/room/widgets/avatar-info/utils/GetFurnitureInfoData.ts
Normal file
@ -0,0 +1,113 @@
|
||||
import { IFurnitureData, Nitro, ObjectDataFactory, RoomObjectCategory, RoomObjectVariable, RoomWidgetEnumItemExtradataParameter, Vector3d } from 'nitro-renderer';
|
||||
import { GetRoomEngine, GetRoomSession, GetSessionDataManager } from '../../../../../api';
|
||||
import { IsOwnerOfFurniture } from '../../../../room-host/utils/IsOwnerOfFurniture';
|
||||
import { FurnitureInfoData } from './FurnitureInfoData';
|
||||
|
||||
export function GetFurnitureInfoData(roomId: number, objectId: number, category: number): FurnitureInfoData
|
||||
{
|
||||
const furnitureInfoData = new FurnitureInfoData();
|
||||
|
||||
furnitureInfoData.id = objectId;
|
||||
furnitureInfoData.category = category;
|
||||
|
||||
const roomObject = GetRoomEngine().getRoomObject(roomId, objectId, category);
|
||||
|
||||
if(!roomObject) return null;
|
||||
|
||||
const model = roomObject.model;
|
||||
|
||||
if(model.getValue<string>(RoomWidgetEnumItemExtradataParameter.INFOSTAND_EXTRA_PARAM))
|
||||
{
|
||||
furnitureInfoData.extraParam = model.getValue<string>(RoomWidgetEnumItemExtradataParameter.INFOSTAND_EXTRA_PARAM);
|
||||
}
|
||||
|
||||
const dataFormat = model.getValue<number>(RoomObjectVariable.FURNITURE_DATA_FORMAT);
|
||||
const objectData = ObjectDataFactory.getData(dataFormat);
|
||||
|
||||
objectData.initializeFromRoomObjectModel(model);
|
||||
|
||||
furnitureInfoData.stuffData = objectData;
|
||||
|
||||
const objectType = roomObject.type;
|
||||
|
||||
if(objectType.indexOf('poster') === 0)
|
||||
{
|
||||
const posterId = parseInt(objectType.replace('poster', ''));
|
||||
|
||||
furnitureInfoData.name = (('${poster_' + posterId) + '_name}');
|
||||
furnitureInfoData.description = (('${poster_' + posterId) + '_desc}');
|
||||
}
|
||||
else
|
||||
{
|
||||
const typeId = model.getValue<number>(RoomObjectVariable.FURNITURE_TYPE_ID);
|
||||
|
||||
let furnitureData: IFurnitureData = null;
|
||||
|
||||
if(category === RoomObjectCategory.FLOOR)
|
||||
{
|
||||
furnitureData = this._container.sessionDataManager.getFloorItemData(typeId);
|
||||
}
|
||||
|
||||
else if(category === RoomObjectCategory.WALL)
|
||||
{
|
||||
furnitureData = this._container.sessionDataManager.getWallItemData(typeId);
|
||||
}
|
||||
|
||||
if(furnitureData)
|
||||
{
|
||||
furnitureInfoData.name = furnitureData.name;
|
||||
furnitureInfoData.description = furnitureData.description;
|
||||
furnitureInfoData.purchaseOfferId = furnitureData.purchaseOfferId;
|
||||
furnitureInfoData.purchaseCouldBeUsedForBuyout = furnitureData.purchaseCouldBeUsedForBuyout;
|
||||
furnitureInfoData.rentOfferId = furnitureData.rentOfferId;
|
||||
furnitureInfoData.rentCouldBeUsedForBuyout = furnitureData.rentCouldBeUsedForBuyout;
|
||||
furnitureInfoData.availableForBuildersClub = furnitureData.availableForBuildersClub;
|
||||
|
||||
// if(this._container.wiredService && (k.category === RoomObjectCategory.FLOOR))
|
||||
// {
|
||||
// this._container.wiredService.selectFurniture(roomObject.id, furnitureData.name);
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
if(objectType.indexOf('post_it') > -1) furnitureInfoData.isStickie = true;
|
||||
|
||||
const expiryTime = model.getValue<number>(RoomObjectVariable.FURNITURE_EXPIRY_TIME);
|
||||
const expiryTimestamp = model.getValue<number>(RoomObjectVariable.FURNITURE_EXPIRTY_TIMESTAMP);
|
||||
|
||||
furnitureInfoData.expiration = ((expiryTime < 0) ? expiryTime : Math.max(0, (expiryTime - ((Nitro.instance.time - expiryTimestamp) / 1000))));
|
||||
|
||||
let roomObjectImage = GetRoomEngine().getRoomObjectImage(roomId, objectId, category, new Vector3d(180), 64, null);
|
||||
|
||||
if(!roomObjectImage.data || (roomObjectImage.data.width > 140) || (roomObjectImage.data.height > 200))
|
||||
{
|
||||
roomObjectImage = GetRoomEngine().getRoomObjectImage(roomId, objectId, category, new Vector3d(180), 1, null);
|
||||
}
|
||||
|
||||
if(roomObjectImage && roomObjectImage.data)
|
||||
{
|
||||
const image = Nitro.instance.renderer.extract.image(roomObjectImage.data);
|
||||
|
||||
if(image) furnitureInfoData.image = image;
|
||||
}
|
||||
|
||||
furnitureInfoData.isWallItem = (category === RoomObjectCategory.WALL);
|
||||
furnitureInfoData.isRoomOwner = GetRoomSession().isRoomOwner;
|
||||
furnitureInfoData.roomControllerLevel = GetRoomSession().controllerLevel;
|
||||
furnitureInfoData.isAnyRoomController = GetSessionDataManager().isModerator;
|
||||
furnitureInfoData.ownerId = model.getValue<number>(RoomObjectVariable.FURNITURE_OWNER_ID);
|
||||
furnitureInfoData.ownerName = model.getValue<string>(RoomObjectVariable.FURNITURE_OWNER_NAME);
|
||||
furnitureInfoData.usagePolicy = model.getValue<number>(RoomObjectVariable.FURNITURE_USAGE_POLICY);
|
||||
|
||||
const guildId = model.getValue<number>(RoomObjectVariable.FURNITURE_GUILD_CUSTOMIZED_GUILD_ID);
|
||||
|
||||
if(guildId !== 0)
|
||||
{
|
||||
furnitureInfoData.groupId = guildId;
|
||||
//this.container.connection.send(new _Str_2863(guildId, false));
|
||||
}
|
||||
|
||||
if(IsOwnerOfFurniture(roomObject)) furnitureInfoData.isOwner = true;
|
||||
|
||||
return furnitureInfoData;
|
||||
}
|
@ -0,0 +1,59 @@
|
||||
import { IFurnitureData, RoomObjectCategory, RoomObjectVariable } from 'nitro-renderer';
|
||||
import { GetRoomEngine, GetRoomSession, GetSessionDataManager } from '../../../../../api';
|
||||
import { RoomObjectNameData } from './RoomObjectNameData';
|
||||
|
||||
export function GetRoomObjectNameData(roomId: number, objectId: number, category: number): RoomObjectNameData
|
||||
{
|
||||
let id = -1;
|
||||
let name: string = null;
|
||||
let type = 0;
|
||||
|
||||
switch(category)
|
||||
{
|
||||
case RoomObjectCategory.FLOOR:
|
||||
case RoomObjectCategory.WALL:
|
||||
const roomObject = GetRoomEngine().getRoomObject(roomId, objectId, category);
|
||||
|
||||
if(!roomObject) return;
|
||||
|
||||
if(roomObject.type.indexOf('poster') === 0)
|
||||
{
|
||||
name = ('${poster_' + parseInt(roomObject.type.replace('poster', '')) + '_name}');
|
||||
}
|
||||
else
|
||||
{
|
||||
let furniData: IFurnitureData = null;
|
||||
|
||||
const typeId = roomObject.model.getValue<number>(RoomObjectVariable.FURNITURE_TYPE_ID);
|
||||
|
||||
if(category === RoomObjectCategory.FLOOR)
|
||||
{
|
||||
furniData = GetSessionDataManager().getFloorItemData(typeId);
|
||||
}
|
||||
|
||||
else if(category === RoomObjectCategory.WALL)
|
||||
{
|
||||
furniData = GetSessionDataManager().getWallItemData(typeId);
|
||||
}
|
||||
|
||||
if(!furniData) return;
|
||||
|
||||
id = furniData.id;
|
||||
name = furniData.name;
|
||||
}
|
||||
break;
|
||||
case RoomObjectCategory.UNIT:
|
||||
const userData = GetRoomSession().userDataManager.getUserDataByIndex(objectId);
|
||||
|
||||
if(!userData) return;
|
||||
|
||||
id = userData.webID;
|
||||
name = userData.name;
|
||||
type = userData.type;
|
||||
break;
|
||||
}
|
||||
|
||||
if(!name) return null;
|
||||
|
||||
return new RoomObjectNameData(objectId, category, id, name, type);
|
||||
}
|
184
src/views/room/widgets/avatar-info/utils/GetUserInfoData.ts
Normal file
184
src/views/room/widgets/avatar-info/utils/GetUserInfoData.ts
Normal file
@ -0,0 +1,184 @@
|
||||
import { RoomControllerLevel, RoomModerationParser, RoomObjectType, RoomObjectVariable, RoomTradingLevelEnum, RoomUserData } from 'nitro-renderer';
|
||||
import { GetRoomEngine, GetRoomSession, GetSessionDataManager } from '../../../../../api';
|
||||
import { UserInfoData } from './UserInfoData';
|
||||
|
||||
export const _Str_18400: number = 0;
|
||||
export const _Str_14161: number = 2;
|
||||
export const _Str_13798: number = 3;
|
||||
|
||||
export function GetUserInfoData(roomId: number, objectId: number, category: number, userData: RoomUserData): UserInfoData
|
||||
{
|
||||
const isOwnUser = false;
|
||||
|
||||
const userInfoData = new UserInfoData();
|
||||
|
||||
userInfoData.isSpectatorMode = GetRoomSession().isSpectator;
|
||||
userInfoData.name = userData.name;
|
||||
userInfoData.motto = userData.custom;
|
||||
userInfoData.achievementScore = userData.activityPoints;
|
||||
userInfoData.webID = userData.webID;
|
||||
userInfoData.userRoomId = objectId;
|
||||
userInfoData.userType = RoomObjectType.USER;
|
||||
|
||||
const roomObject = GetRoomEngine().getRoomObject(roomId, objectId, category);
|
||||
|
||||
if(roomObject) userInfoData.carryItem = roomObject.model.getValue<number>(RoomObjectVariable.FIGURE_CARRY_OBJECT);
|
||||
|
||||
if(isOwnUser)
|
||||
{
|
||||
userInfoData.realName = GetSessionDataManager().realName;
|
||||
userInfoData.allowNameChange = GetSessionDataManager().canChangeName;
|
||||
}
|
||||
|
||||
userInfoData.amIOwner = GetRoomSession().isRoomOwner;
|
||||
userInfoData.isGuildRoom = GetRoomSession().isGuildRoom;
|
||||
userInfoData.roomControllerLevel = GetRoomSession().controllerLevel;
|
||||
userInfoData.amIAnyRoomController = GetSessionDataManager().isModerator;
|
||||
userInfoData.isAmbassador = GetSessionDataManager().isAmbassador;
|
||||
|
||||
if(!isOwnUser)
|
||||
{
|
||||
// userInfoData.canBeAskedAsFriend = this._container.friendService.canBeAskedForAFriend(userData.webID);
|
||||
|
||||
// const friend = this._container.friendService.getFriend(userData.webID);
|
||||
|
||||
// if(friend)
|
||||
// {
|
||||
// userInfoData.realName = friend.realName;
|
||||
// userInfoData.isFriend = true;
|
||||
// }
|
||||
|
||||
if(roomObject)
|
||||
{
|
||||
const flatControl = roomObject.model.getValue<number>(RoomObjectVariable.FIGURE_FLAT_CONTROL);
|
||||
|
||||
if(flatControl !== null) userInfoData.targetRoomControllerLevel = flatControl;
|
||||
|
||||
userInfoData.canBeMuted = canBeMuted(userInfoData);
|
||||
userInfoData.canBeKicked = canBeKicked(userInfoData);
|
||||
userInfoData.canBeBanned = canBeBanned(userInfoData);
|
||||
}
|
||||
|
||||
userInfoData.isIgnored = GetSessionDataManager().isUserIgnored(userData.name);
|
||||
userInfoData.respectLeft = GetSessionDataManager().respectsLeft;
|
||||
|
||||
const isShuttingDown = GetSessionDataManager().isSystemShutdown;
|
||||
const tradeMode = GetRoomSession().tradeMode;
|
||||
|
||||
if(isShuttingDown)
|
||||
{
|
||||
userInfoData.canTrade = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
switch(tradeMode)
|
||||
{
|
||||
case RoomTradingLevelEnum._Str_14475: {
|
||||
const roomController = ((userInfoData.roomControllerLevel !== RoomControllerLevel.NONE) && (userInfoData.roomControllerLevel !== RoomControllerLevel.GUILD_MEMBER));
|
||||
const targetController = ((userInfoData.targetRoomControllerLevel !== RoomControllerLevel.NONE) && (userInfoData.targetRoomControllerLevel !== RoomControllerLevel.GUILD_MEMBER));
|
||||
|
||||
userInfoData.canTrade = (roomController || targetController);
|
||||
break;
|
||||
}
|
||||
case RoomTradingLevelEnum._Str_9173:
|
||||
userInfoData.canTrade = true;
|
||||
break;
|
||||
default:
|
||||
userInfoData.canTrade = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
userInfoData.canTradeReason = _Str_18400;
|
||||
|
||||
if(isShuttingDown) userInfoData.canTradeReason = _Str_14161;
|
||||
|
||||
if(tradeMode !== RoomTradingLevelEnum._Str_9173) userInfoData.canTradeReason = _Str_13798;
|
||||
|
||||
// const _local_12 = GetSessionDataManager().userId;
|
||||
// _local_13 = GetSessionDataManager()._Str_18437(_local_12);
|
||||
// this._Str_16287(_local_12, _local_13);
|
||||
}
|
||||
|
||||
userInfoData.groupId = parseInt(userData.guildId);
|
||||
//event._Str_5235 = GetSessionDataManager()._Str_17173(int(userData._Str_4592));
|
||||
userInfoData.groupName = userData.groupName;
|
||||
userInfoData.badges = GetRoomSession().userDataManager.getUserBadges(userData.webID);
|
||||
userInfoData.figure = userData.figure;
|
||||
//var _local_8:Array = GetSessionDataManager()._Str_18437(userData.webID);
|
||||
//this._Str_16287(userData._Str_2394, _local_8);
|
||||
//this._container._Str_8097._Str_14387(userData.webID);
|
||||
//this._container.connection.send(new _Str_8049(userData._Str_2394));
|
||||
|
||||
return userInfoData;
|
||||
}
|
||||
|
||||
function checkGuildSetting(userInfoData: UserInfoData): boolean
|
||||
{
|
||||
if(userInfoData.isGuildRoom) return (userInfoData.roomControllerLevel >= RoomControllerLevel.GUILD_ADMIN);
|
||||
|
||||
return (userInfoData.roomControllerLevel >= RoomControllerLevel.GUEST);
|
||||
}
|
||||
|
||||
function canBeMuted(userInfoData: UserInfoData): boolean
|
||||
{
|
||||
const checkSetting = function(userInfoData: UserInfoData, moderation: RoomModerationParser)
|
||||
{
|
||||
switch(moderation.allowMute)
|
||||
{
|
||||
case RoomModerationParser._Str_5047:
|
||||
return checkGuildSetting(userInfoData);
|
||||
default:
|
||||
return (userInfoData.roomControllerLevel >= RoomControllerLevel.ROOM_OWNER);
|
||||
}
|
||||
}
|
||||
|
||||
return isValidSetting(userInfoData, checkSetting);
|
||||
}
|
||||
|
||||
function canBeKicked(userInfoData: UserInfoData): boolean
|
||||
{
|
||||
const checkSetting = function(userInfoData: UserInfoData, moderation: RoomModerationParser)
|
||||
{
|
||||
switch(moderation.allowKick)
|
||||
{
|
||||
case RoomModerationParser._Str_11537:
|
||||
return true;
|
||||
case RoomModerationParser._Str_5047:
|
||||
return checkGuildSetting(userInfoData);
|
||||
default:
|
||||
return (userInfoData.roomControllerLevel >= RoomControllerLevel.ROOM_OWNER);
|
||||
}
|
||||
}
|
||||
|
||||
return isValidSetting(userInfoData, checkSetting);
|
||||
}
|
||||
|
||||
function canBeBanned(userInfoData: UserInfoData): boolean
|
||||
{
|
||||
const checkSetting = function(userInfoData: UserInfoData, moderation: RoomModerationParser)
|
||||
{
|
||||
switch(moderation.allowBan)
|
||||
{
|
||||
case RoomModerationParser._Str_5047:
|
||||
return checkGuildSetting(userInfoData);
|
||||
default:
|
||||
return (userInfoData.roomControllerLevel >= RoomControllerLevel.ROOM_OWNER);
|
||||
}
|
||||
}
|
||||
|
||||
return isValidSetting(userInfoData, checkSetting);
|
||||
}
|
||||
|
||||
function isValidSetting(userInfoData: UserInfoData, checkSetting: (userInfoData: UserInfoData, moderation: RoomModerationParser) => boolean): boolean
|
||||
{
|
||||
if(!GetRoomSession()._Str_7411) return false;
|
||||
|
||||
const moderation = GetRoomSession().moderationSettings;
|
||||
|
||||
let flag = false;
|
||||
|
||||
if(moderation) flag = checkSetting(userInfoData, moderation);
|
||||
|
||||
return (flag && (userInfoData.roomControllerLevel < RoomControllerLevel.ROOM_OWNER));
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
export class RoomObjectNameData
|
||||
{
|
||||
constructor(
|
||||
public objectId: number,
|
||||
public category: number,
|
||||
public id: number,
|
||||
public name: string,
|
||||
public type: number) {}
|
||||
}
|
35
src/views/room/widgets/avatar-info/utils/UserInfoData.ts
Normal file
35
src/views/room/widgets/avatar-info/utils/UserInfoData.ts
Normal file
@ -0,0 +1,35 @@
|
||||
export class UserInfoData
|
||||
{
|
||||
constructor(
|
||||
public name: string = '',
|
||||
public motto: string = '',
|
||||
public achievementScore: number = 0,
|
||||
public webID: number = 0,
|
||||
public xp: number = 0,
|
||||
public userType: number = -1,
|
||||
public figure: string = '',
|
||||
public badges: string[] = [],
|
||||
public groupId: number = 0,
|
||||
public groupName: string = '',
|
||||
public groupBadgeId: string = '',
|
||||
public carryItem: number = 0,
|
||||
public userRoomId: number = 0,
|
||||
public isSpectatorMode: boolean = false,
|
||||
public realName: string = '',
|
||||
public allowNameChange: boolean = false,
|
||||
public amIOwner: boolean = false,
|
||||
public amIAnyRoomController: boolean = false,
|
||||
public roomControllerLevel: number = 0,
|
||||
public canBeAskedAsFriend: boolean = false,
|
||||
public canBeKicked: boolean = false,
|
||||
public canBeBanned: boolean = false,
|
||||
public canBeMuted: boolean = false,
|
||||
public respectLeft: number = 0,
|
||||
public isIgnored: boolean = false,
|
||||
public isGuildRoom: boolean = false,
|
||||
public canTrade: boolean = false,
|
||||
public canTradeReason: number = 0,
|
||||
public targetRoomControllerLevel: number = 0,
|
||||
public isFriend: boolean = false,
|
||||
public isAmbassador: boolean = false) {}
|
||||
}
|
Loading…
Reference in New Issue
Block a user