mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2026-04-02 19:08:03 -06:00
54 lines
1.3 KiB
C++
54 lines
1.3 KiB
C++
// SPDX-FileCopyrightText: Copyright 2026 shadPS4 Emulator Project
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
#pragma once
|
|
#include <filesystem>
|
|
#include <string>
|
|
#include <vector>
|
|
#include <nlohmann/json.hpp>
|
|
#include "common/types.h"
|
|
|
|
struct User {
|
|
s32 user_id;
|
|
u32 user_color;
|
|
std::string user_name;
|
|
int controller_port; // 1-4
|
|
};
|
|
|
|
struct Users {
|
|
int default_user_id = 1;
|
|
std::vector<User> user {};
|
|
std::string commit_hash{};
|
|
};
|
|
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(User, user_id, user_color, user_name, controller_port)
|
|
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Users, default_user_id, user, commit_hash)
|
|
|
|
class UserManager {
|
|
public:
|
|
UserManager() = default;
|
|
|
|
bool AddUser(const User& user);
|
|
bool RemoveUser(s32 user_id);
|
|
bool RenameUser(s32 user_id, const std::string& new_name);
|
|
User* GetUserByID(s32 user_id);
|
|
User* GetUserByPlayerIndex(s32 index);
|
|
const std::vector<User>& GetAllUsers() const;
|
|
std::vector<User> CreateDefaultUser();
|
|
bool SetDefaultUser(u32 user_id);
|
|
User GetDefaultUser();
|
|
void SetControllerPort(u32 user_id, int port);
|
|
std::vector<User> GetValidUsers() const;
|
|
|
|
Users& GetUsers() {
|
|
return m_users;
|
|
}
|
|
const Users& GetUsers() const {
|
|
return m_users;
|
|
}
|
|
|
|
bool Save() const;
|
|
|
|
private:
|
|
Users m_users;
|
|
};
|