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 React, { useEffect, useState } from "react";
|
||||||
import { motion, AnimatePresence } from "framer-motion";
|
import { motion, AnimatePresence } from "framer-motion";
|
||||||
import { useNakama } from "./providers/NakamaProvider";
|
import { useNakama } from "./providers/NakamaProvider";
|
||||||
|
import { PlayerProps } from "./interfaces/props";
|
||||||
|
|
||||||
export default function Player({
|
export default function Player({
|
||||||
onMatchDataCallback,
|
onMatchDataCallback,
|
||||||
}: {
|
}: PlayerProps) {
|
||||||
onMatchDataCallback: (msg: any) => void;
|
|
||||||
}) {
|
|
||||||
const {
|
const {
|
||||||
session,
|
session,
|
||||||
matchId,
|
matchId,
|
||||||
|
|||||||
@@ -11,8 +11,8 @@ import {
|
|||||||
} from "@heroiclabs/nakama-js/dist/api.gen"
|
} from "@heroiclabs/nakama-js/dist/api.gen"
|
||||||
|
|
||||||
import {
|
import {
|
||||||
GameMetadata,
|
GameMetadataModel,
|
||||||
MatchDataMessage,
|
MatchDataModel,
|
||||||
} from './models'
|
} from './models'
|
||||||
|
|
||||||
|
|
||||||
@@ -25,13 +25,13 @@ export interface NakamaContextType {
|
|||||||
loginOrRegister(username?: string): Promise<void>;
|
loginOrRegister(username?: string): Promise<void>;
|
||||||
logout(): Promise<void>;
|
logout(): Promise<void>;
|
||||||
|
|
||||||
joinMatchmaker(gameMetadata: GameMetadata): Promise<string>;
|
joinMatchmaker(gameMetadata: GameMetadataModel): Promise<string>;
|
||||||
exitMatchmaker(gameMetadata: GameMetadata): Promise<void>;
|
exitMatchmaker(gameMetadata: GameMetadataModel): Promise<void>;
|
||||||
joinMatch(matchId: string): Promise<void>;
|
joinMatch(matchId: string): Promise<void>;
|
||||||
|
|
||||||
sendMatchData(matchId: string, op: number, data: object): void;
|
sendMatchData(matchId: string, op: number, data: object): void;
|
||||||
|
|
||||||
onMatchData(cb: (msg: MatchDataMessage) => void): void;
|
onMatchData(cb: (msg: MatchDataModel) => void): void;
|
||||||
|
|
||||||
getLeaderboardTop(): Promise<ApiLeaderboardRecordList>;
|
getLeaderboardTop(): Promise<ApiLeaderboardRecordList>;
|
||||||
listOpenMatches(): Promise<ApiMatch[]>;
|
listOpenMatches(): Promise<ApiMatch[]>;
|
||||||
|
|||||||
@@ -11,16 +11,16 @@ export interface MatchDataModel<T = any> {
|
|||||||
userId: string | null;
|
userId: string | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Board {
|
export interface BoardModel {
|
||||||
grid: string[][];
|
grid: string[][];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface GameMetadata {
|
export interface GameMetadataModel {
|
||||||
game: string;
|
game: string;
|
||||||
mode: string;
|
mode: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface MatchDataMessage<T = any> {
|
export interface MatchDataModel<T = any> {
|
||||||
opCode: number;
|
opCode: number;
|
||||||
data: T;
|
data: T;
|
||||||
userId: string | null;
|
userId: string | null;
|
||||||
|
|||||||
@@ -5,11 +5,11 @@ import {
|
|||||||
} from "@heroiclabs/nakama-js";
|
} from "@heroiclabs/nakama-js";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
GameMetadata,
|
GameMetadataModel,
|
||||||
} from './models'
|
} from './models'
|
||||||
|
|
||||||
|
|
||||||
export interface NakamaRefs {
|
export interface NakamaRefs {
|
||||||
socketRef: React.RefObject<Socket | null>;
|
socketRef: React.RefObject<Socket | null>;
|
||||||
gameMetadataRef: React.RefObject<GameMetadata | null>;
|
gameMetadataRef: React.RefObject<GameMetadataModel | null>;
|
||||||
}
|
}
|
||||||
@@ -4,7 +4,7 @@ import {
|
|||||||
} from "@heroiclabs/nakama-js";
|
} from "@heroiclabs/nakama-js";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
Board,
|
BoardModel,
|
||||||
PlayerModel,
|
PlayerModel,
|
||||||
} from "./models"
|
} from "./models"
|
||||||
|
|
||||||
@@ -17,7 +17,7 @@ export interface NakamaProviderState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface GameState {
|
export interface GameState {
|
||||||
boards: Record<string, Board>;
|
boards: Record<string, BoardModel>;
|
||||||
turn: number;
|
turn: number;
|
||||||
winner: string | null;
|
winner: string | null;
|
||||||
gameOver: boolean;
|
gameOver: boolean;
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ import {
|
|||||||
import { NakamaContextType } from "../interfaces/contexts";
|
import { NakamaContextType } from "../interfaces/contexts";
|
||||||
import { NakamaRefs } from "../interfaces/refs";
|
import { NakamaRefs } from "../interfaces/refs";
|
||||||
import { NakamaProviderState } from "../interfaces/states";
|
import { NakamaProviderState } from "../interfaces/states";
|
||||||
import { GameMetadata, MatchDataMessage } from "../interfaces/models";
|
import { GameMetadataModel, MatchDataModel } from "../interfaces/models";
|
||||||
|
|
||||||
function getOrCreateDeviceId(): string {
|
function getOrCreateDeviceId(): string {
|
||||||
const key = "nakama.deviceId";
|
const key = "nakama.deviceId";
|
||||||
@@ -68,7 +68,7 @@ export function NakamaProvider({ children }: { children: React.ReactNode }) {
|
|||||||
// --------------------------------------
|
// --------------------------------------
|
||||||
const refs: NakamaRefs = {
|
const refs: NakamaRefs = {
|
||||||
socketRef: useRef<Socket | null>(null),
|
socketRef: useRef<Socket | null>(null),
|
||||||
gameMetadataRef: useRef<GameMetadata | null>(null),
|
gameMetadataRef: useRef<GameMetadataModel | null>(null),
|
||||||
};
|
};
|
||||||
|
|
||||||
// Helpers to update internal state cleanly
|
// Helpers to update internal state cleanly
|
||||||
@@ -202,7 +202,7 @@ export function NakamaProvider({ children }: { children: React.ReactNode }) {
|
|||||||
// ----------------------------------------------------
|
// ----------------------------------------------------
|
||||||
// MATCHMAKING
|
// MATCHMAKING
|
||||||
// ----------------------------------------------------
|
// ----------------------------------------------------
|
||||||
async function joinMatchmaker(gameMetadata: GameMetadata) {
|
async function joinMatchmaker(gameMetadata: GameMetadataModel) {
|
||||||
const socket = refs.socketRef.current;
|
const socket = refs.socketRef.current;
|
||||||
if (!socket) throw new Error("Socket missing");
|
if (!socket) throw new Error("Socket missing");
|
||||||
|
|
||||||
@@ -267,7 +267,7 @@ export function NakamaProvider({ children }: { children: React.ReactNode }) {
|
|||||||
// ----------------------------------------------------
|
// ----------------------------------------------------
|
||||||
// MATCH DATA LISTENER
|
// MATCH DATA LISTENER
|
||||||
// ----------------------------------------------------
|
// ----------------------------------------------------
|
||||||
function onMatchData(cb: (msg: MatchDataMessage) => void) {
|
function onMatchData(cb: (msg: MatchDataModel) => void) {
|
||||||
if (!internal.socket) return;
|
if (!internal.socket) return;
|
||||||
|
|
||||||
internal.socket.onmatchdata = (m: MatchData) => {
|
internal.socket.onmatchdata = (m: MatchData) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user