mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-30 10:02:17 +00:00
send emojis working!
This commit is contained in:
+7
-4
@@ -1,5 +1,5 @@
|
||||
import {z} from 'zod';
|
||||
import {Emoji, PlayerType} from './game/Game';
|
||||
import {PlayerType} from './game/Game';
|
||||
|
||||
export type GameID = string
|
||||
export type ClientID = string
|
||||
@@ -38,8 +38,6 @@ export type ClientJoinMessage = z.infer<typeof ClientJoinMessageSchema>
|
||||
export type ClientLeaveMessage = z.infer<typeof ClientLeaveMessageSchema>
|
||||
|
||||
const PlayerTypeSchema = z.nativeEnum(PlayerType);
|
||||
const EmojiSchema = z.nativeEnum(Emoji);
|
||||
|
||||
|
||||
// TODO: create Cell schema
|
||||
|
||||
@@ -121,7 +119,12 @@ export const EmojiIntentSchema = BaseIntentSchema.extend({
|
||||
type: z.literal('emoji'),
|
||||
sender: z.string(),
|
||||
recipient: z.string(),
|
||||
emoji: EmojiSchema,
|
||||
emoji: z.string().refine(
|
||||
(val) => /^\p{Emoji}$/u.test(val),
|
||||
{
|
||||
message: "Must be a single emoji"
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
const IntentSchema = z.union([
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {AllPlayers, Emoji, Execution, MutableGame, MutablePlayer, PlayerID} from "../game/Game";
|
||||
import {AllPlayers, Execution, MutableGame, MutablePlayer, PlayerID} from "../game/Game";
|
||||
|
||||
export class EmojiExecution implements Execution {
|
||||
|
||||
@@ -10,7 +10,7 @@ export class EmojiExecution implements Execution {
|
||||
constructor(
|
||||
private senderID: PlayerID,
|
||||
private recipientID: PlayerID | typeof AllPlayers,
|
||||
private emoji: Emoji
|
||||
private emoji: string
|
||||
) { }
|
||||
|
||||
|
||||
|
||||
+2
-11
@@ -8,22 +8,13 @@ import {BreakAllianceExecution} from "../execution/alliance/BreakAllianceExecuti
|
||||
export type PlayerID = string
|
||||
export type Tick = number
|
||||
|
||||
export enum Emoji {
|
||||
ThumbsUp = "👍",
|
||||
ThumbsDown = "👎",
|
||||
Smile = "😊",
|
||||
Sad = "😢",
|
||||
Heart = "❤️",
|
||||
Fire = "🔥",
|
||||
}
|
||||
|
||||
export const AllPlayers = "AllPlayers" as const;
|
||||
|
||||
export class EmojiMessage {
|
||||
constructor(
|
||||
public readonly sender: Player,
|
||||
public readonly recipient: Player | typeof AllPlayers,
|
||||
public readonly emoji: Emoji,
|
||||
public readonly emoji: string,
|
||||
public readonly createdAt: Tick
|
||||
) { }
|
||||
}
|
||||
@@ -201,7 +192,7 @@ export interface MutablePlayer extends Player {
|
||||
targets(): MutablePlayer[]
|
||||
transitiveTargets(): MutablePlayer[]
|
||||
// Null means send to all Players
|
||||
sendEmoji(recipient: Player | typeof AllPlayers, emoji: Emoji): void
|
||||
sendEmoji(recipient: Player | typeof AllPlayers, emoji: string): void
|
||||
}
|
||||
|
||||
export interface Game {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {MutablePlayer, Tile, PlayerInfo, PlayerID, PlayerType, Player, TerraNullius, Cell, MutableGame, Execution, AllianceRequest, MutableAllianceRequest, MutableAlliance, Alliance, Tick, TargetPlayerEvent, Emoji, EmojiMessage, EmojiMessageEvent, AllPlayers} from "./Game";
|
||||
import {MutablePlayer, Tile, PlayerInfo, PlayerID, PlayerType, Player, TerraNullius, Cell, Execution, AllianceRequest, MutableAllianceRequest, MutableAlliance, Alliance, Tick, TargetPlayerEvent, EmojiMessage, EmojiMessageEvent, AllPlayers} from "./Game";
|
||||
import {ClientID} from "../Schemas";
|
||||
import {simpleHash} from "../Util";
|
||||
import {CellString, GameImpl} from "./GameImpl";
|
||||
@@ -209,7 +209,7 @@ export class PlayerImpl implements MutablePlayer {
|
||||
return [...new Set(ts)]
|
||||
}
|
||||
|
||||
sendEmoji(recipient: Player | typeof AllPlayers, emoji: Emoji): void {
|
||||
sendEmoji(recipient: Player | typeof AllPlayers, emoji: string): void {
|
||||
if (recipient == this) {
|
||||
throw Error(`Cannot send emoji to oneself: ${this}`)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user