galvanic corrosion rewrite

commit this before something goes horribly wrong
This commit is contained in:
2025-08-12 21:04:52 -04:00
parent 941c8400c0
commit f19552929e
40 changed files with 28149 additions and 73212 deletions

View File

@@ -1,8 +1,11 @@
import { RoomInstance } from "../instances/base.ts";
import KV from "../persistence/kv.ts";
import { ProfileRole } from "../platforms/base.ts";
import { PlatformMask, ProfileRole } from "../platforms/types.ts";
import { type ServerBase } from "../server.ts";
import { type SignalRSocketHandler } from "../socket/signalr/socket.ts";
import { ProfileAvatarManager } from "./content/Avatar.ts";
import ProfileContentManager from "./content/base.ts";
import { ProfileMatchmakingManager } from "./content/Matchmaking.ts";
import { ProfileSettingsManager } from "./content/Settings.ts";
import ProfileManagerBase from "./manager.ts";
import { recNetAccountSchema, SelfAccount, type RecNetAccount } from "./types/profile.ts";
@@ -13,12 +16,16 @@ class Profile {
#kv: KV;
#socket: SignalRSocketHandler | null = null;
#server: ServerBase;
#instance: RoomInstance | null = null;
#server: ServerBase;
#selfAcc: SelfAccount;
managers: ProfileContentManager[] = [];
Settings: ProfileSettingsManager;
Avatar: ProfileAvatarManager;
Matchmaking: ProfileMatchmakingManager;
constructor(acc: SelfAccount, kv: KV, server: ServerBase) {
this.#id = acc.accountId;
@@ -28,6 +35,7 @@ class Profile {
this.Settings = new ProfileSettingsManager(this, this.#kv);
this.Avatar = new ProfileAvatarManager(this, this.#kv);
this.Matchmaking = new ProfileMatchmakingManager(this, this.#kv);
}
async #saveSelfAcc() {
@@ -67,11 +75,12 @@ class Profile {
async setBio(bio: string) {
const key = this.constructProfilePropertyKey('bio');
await this.#kv.getKv().set(key, bio);
this.#server.emit('profile.update', { profile: this });
}
async getRole(): Promise<ProfileRole> {
const val = (await this.#kv.getKv().get<ProfileRole>(this.constructProfilePropertyKey('role'))).value;
if (!val) return ProfileRole.User;
if (!val) return ProfileRole.Game;
else return val;
}
@@ -80,6 +89,42 @@ class Profile {
this.#server.emit('profile.roleupdate', { profile: this, newRole: role });
}
async addPlatform(type: PlatformMask) {
const platforms = this.#server.Platforms.getPlatformMask(this.#selfAcc.platforms);
this.#selfAcc.platforms = this.#server.Platforms.buildPlatformMask(...[...platforms, type]);
await this.#saveSelfAcc();
}
async removePlatform(type: PlatformMask) {
const platforms = new Set(this.#server.Platforms.getPlatformMask(this.#selfAcc.platforms));
platforms.delete(type);
this.#selfAcc.platforms = this.#server.Platforms.buildPlatformMask(...platforms.values().toArray());
await this.#saveSelfAcc();
}
async setProfileImg(img: string) {
this.#selfAcc.profileImage = img;
await this.#saveSelfAcc();
}
getProfileImg() {
return this.#selfAcc.profileImage;
}
getCreationDate() {
return this.#selfAcc.createdAt;
}
getPlatforms() {
return this.#selfAcc.platforms;
}
getInstance() {
return this.#instance;
}
setInstance(inst: RoomInstance) {
this.#instance = inst;
}
getId() {
return this.#id;
}
@@ -102,6 +147,10 @@ class Profile {
return this.#selfAcc;
}
same(profile: Profile) {
return profile.getId() == this.getId();
}
}
export default Profile;