refactor(types): rename interfaces with *Model suffix and update references across codebase
- Renamed GameMetadata → GameMetadataModel for naming consistency - Renamed Board → BoardModel - Renamed MatchDataMessage → MatchDataModel (duplicate name removed) - Updated all imports and references in: - NakamaProvider - contexts.ts - refs.ts - states.ts - Player.tsx - props and models files - Updated GameState to use BoardModel instead of Board - Updated NakamaContextType to use GameMetadataModel and MatchDataModel - Updated NakamaRefs to store gameMetadataRef: RefObject<GameMetadataModel> - Updated joinMatchmaker() and exitMatchmaker() signatures - Updated onMatchData() to emit MatchDataModel - Updated Player component to use PlayerProps type instead of inline typing This commit standardizes naming conventions by ensuring all schema/interface definitions follow the *Model naming pattern, improving clarity and type consistency across the project.
This commit is contained in:
@@ -1,12 +1,11 @@
|
||||
import React, { useEffect, useState } from "react";
|
||||
import { motion, AnimatePresence } from "framer-motion";
|
||||
import { useNakama } from "./providers/NakamaProvider";
|
||||
import { PlayerProps } from "./interfaces/props";
|
||||
|
||||
export default function Player({
|
||||
onMatchDataCallback,
|
||||
}: {
|
||||
onMatchDataCallback: (msg: any) => void;
|
||||
}) {
|
||||
}: PlayerProps) {
|
||||
const {
|
||||
session,
|
||||
matchId,
|
||||
|
||||
@@ -11,8 +11,8 @@ import {
|
||||
} from "@heroiclabs/nakama-js/dist/api.gen"
|
||||
|
||||
import {
|
||||
GameMetadata,
|
||||
MatchDataMessage,
|
||||
GameMetadataModel,
|
||||
MatchDataModel,
|
||||
} from './models'
|
||||
|
||||
|
||||
@@ -25,13 +25,13 @@ export interface NakamaContextType {
|
||||
loginOrRegister(username?: string): Promise<void>;
|
||||
logout(): Promise<void>;
|
||||
|
||||
joinMatchmaker(gameMetadata: GameMetadata): Promise<string>;
|
||||
exitMatchmaker(gameMetadata: GameMetadata): Promise<void>;
|
||||
joinMatchmaker(gameMetadata: GameMetadataModel): Promise<string>;
|
||||
exitMatchmaker(gameMetadata: GameMetadataModel): Promise<void>;
|
||||
joinMatch(matchId: string): Promise<void>;
|
||||
|
||||
sendMatchData(matchId: string, op: number, data: object): void;
|
||||
|
||||
onMatchData(cb: (msg: MatchDataMessage) => void): void;
|
||||
onMatchData(cb: (msg: MatchDataModel) => void): void;
|
||||
|
||||
getLeaderboardTop(): Promise<ApiLeaderboardRecordList>;
|
||||
listOpenMatches(): Promise<ApiMatch[]>;
|
||||
|
||||
@@ -11,16 +11,16 @@ export interface MatchDataModel<T = any> {
|
||||
userId: string | null;
|
||||
}
|
||||
|
||||
export interface Board {
|
||||
export interface BoardModel {
|
||||
grid: string[][];
|
||||
}
|
||||
|
||||
export interface GameMetadata {
|
||||
export interface GameMetadataModel {
|
||||
game: string;
|
||||
mode: string;
|
||||
}
|
||||
|
||||
export interface MatchDataMessage<T = any> {
|
||||
export interface MatchDataModel<T = any> {
|
||||
opCode: number;
|
||||
data: T;
|
||||
userId: string | null;
|
||||
|
||||
@@ -5,11 +5,11 @@ import {
|
||||
} from "@heroiclabs/nakama-js";
|
||||
|
||||
import {
|
||||
GameMetadata,
|
||||
GameMetadataModel,
|
||||
} from './models'
|
||||
|
||||
|
||||
export interface NakamaRefs {
|
||||
socketRef: React.RefObject<Socket | null>;
|
||||
gameMetadataRef: React.RefObject<GameMetadata | null>;
|
||||
gameMetadataRef: React.RefObject<GameMetadataModel | null>;
|
||||
}
|
||||
@@ -4,7 +4,7 @@ import {
|
||||
} from "@heroiclabs/nakama-js";
|
||||
|
||||
import {
|
||||
Board,
|
||||
BoardModel,
|
||||
PlayerModel,
|
||||
} from "./models"
|
||||
|
||||
@@ -17,7 +17,7 @@ export interface NakamaProviderState {
|
||||
}
|
||||
|
||||
export interface GameState {
|
||||
boards: Record<string, Board>;
|
||||
boards: Record<string, BoardModel>;
|
||||
turn: number;
|
||||
winner: string | null;
|
||||
gameOver: boolean;
|
||||
|
||||
@@ -22,7 +22,7 @@ import {
|
||||
import { NakamaContextType } from "../interfaces/contexts";
|
||||
import { NakamaRefs } from "../interfaces/refs";
|
||||
import { NakamaProviderState } from "../interfaces/states";
|
||||
import { GameMetadata, MatchDataMessage } from "../interfaces/models";
|
||||
import { GameMetadataModel, MatchDataModel } from "../interfaces/models";
|
||||
|
||||
function getOrCreateDeviceId(): string {
|
||||
const key = "nakama.deviceId";
|
||||
@@ -68,7 +68,7 @@ export function NakamaProvider({ children }: { children: React.ReactNode }) {
|
||||
// --------------------------------------
|
||||
const refs: NakamaRefs = {
|
||||
socketRef: useRef<Socket | null>(null),
|
||||
gameMetadataRef: useRef<GameMetadata | null>(null),
|
||||
gameMetadataRef: useRef<GameMetadataModel | null>(null),
|
||||
};
|
||||
|
||||
// Helpers to update internal state cleanly
|
||||
@@ -202,7 +202,7 @@ export function NakamaProvider({ children }: { children: React.ReactNode }) {
|
||||
// ----------------------------------------------------
|
||||
// MATCHMAKING
|
||||
// ----------------------------------------------------
|
||||
async function joinMatchmaker(gameMetadata: GameMetadata) {
|
||||
async function joinMatchmaker(gameMetadata: GameMetadataModel) {
|
||||
const socket = refs.socketRef.current;
|
||||
if (!socket) throw new Error("Socket missing");
|
||||
|
||||
@@ -267,7 +267,7 @@ export function NakamaProvider({ children }: { children: React.ReactNode }) {
|
||||
// ----------------------------------------------------
|
||||
// MATCH DATA LISTENER
|
||||
// ----------------------------------------------------
|
||||
function onMatchData(cb: (msg: MatchDataMessage) => void) {
|
||||
function onMatchData(cb: (msg: MatchDataModel) => void) {
|
||||
if (!internal.socket) return;
|
||||
|
||||
internal.socket.onmatchdata = (m: MatchData) => {
|
||||
|
||||
Reference in New Issue
Block a user