mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-21 09:20:47 +00:00
send emojis working!
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import {EventBus, GameEvent} from "../core/EventBus"
|
||||
import {AllianceRequest, AllPlayers, Cell, Emoji, Player, PlayerID, PlayerType} from "../core/game/Game"
|
||||
import {AllianceRequest, AllPlayers, Cell, Player, PlayerID, PlayerType} from "../core/game/Game"
|
||||
import {ClientID, ClientIntentMessageSchema, ClientJoinMessageSchema, ClientLeaveMessageSchema, GameID, Intent, ServerMessage, ServerMessageSchema} from "../core/Schemas"
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ export class SendTargetPlayerIntentEvent implements GameEvent {
|
||||
}
|
||||
|
||||
export class SendEmojiIntentEvent implements GameEvent {
|
||||
constructor(public readonly recipient: Player | typeof AllPlayers, public readonly emoji: Emoji) { }
|
||||
constructor(public readonly recipient: Player | typeof AllPlayers, public readonly emoji: string) { }
|
||||
}
|
||||
|
||||
export class Transport {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import {EventBus} from "../../../core/EventBus";
|
||||
import {AllPlayers, Cell, Emoji, Game, Player, PlayerID} from "../../../core/game/Game";
|
||||
import {AllPlayers, Cell, Game, Player} from "../../../core/game/Game";
|
||||
import {ClientID} from "../../../core/Schemas";
|
||||
import {and, bfs, dist, manhattanDist, manhattanDistWrapped, sourceDstOceanShore} from "../../../core/Util";
|
||||
import {ContextMenuEvent, MouseUpEvent} from "../../InputHandler";
|
||||
@@ -89,7 +89,7 @@ export class RadialMenu implements Layer {
|
||||
if (emojiElement.classList.contains('emoji-button')) {
|
||||
const emoji = emojiElement.textContent;
|
||||
this.hideEmojiTable()
|
||||
this.eventBus.emit(new SendEmojiIntentEvent(recipient, Emoji.Heart))
|
||||
this.eventBus.emit(new SendEmojiIntentEvent(recipient, emoji))
|
||||
}
|
||||
});
|
||||
} else {
|
||||
|
||||
+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