diff --git a/client/src/app/helpers/data-grabber.interceptor.ts b/client/src/app/helpers/data-grabber.interceptor.ts index 7eb9773..ba29415 100644 --- a/client/src/app/helpers/data-grabber.interceptor.ts +++ b/client/src/app/helpers/data-grabber.interceptor.ts @@ -105,6 +105,10 @@ export class DataGrabberInterceptor implements HttpInterceptor { if (body.notifications) { this.store.dispatch(new SetNotifications(body.notifications)); } + + if (body.actions) { + this.store.dispatch(body.actions); + } }), ); } diff --git a/client/src/app/helpers/store-context.ts b/client/src/app/helpers/store-context.ts index f52777f..b4b6745 100644 --- a/client/src/app/helpers/store-context.ts +++ b/client/src/app/helpers/store-context.ts @@ -1,9 +1,11 @@ import { inject } from '@angular/core'; import { IAttachmentHelpers } from '@interfaces'; +import { NotifyService } from '@services/notify.service'; import { VisualService } from '@services/visual.service'; export function getStateHelpers(): IAttachmentHelpers { return { visual: inject(VisualService), + notify: inject(NotifyService), }; } diff --git a/client/src/app/services/notify.service.ts b/client/src/app/services/notify.service.ts index 552c5d5..fc65ddc 100644 --- a/client/src/app/services/notify.service.ts +++ b/client/src/app/services/notify.service.ts @@ -2,13 +2,12 @@ import { Injectable } from '@angular/core'; import { ToastController } from '@ionic/angular'; @Injectable({ - providedIn: 'root' + providedIn: 'root', }) export class NotifyService { - constructor(private toastController: ToastController) {} - private async showToast(message: string, color: string) { + public async showToast(message: string, color: string) { const toast = await this.toastController.create({ message, duration: 1500, @@ -17,9 +16,9 @@ export class NotifyService { buttons: [ { text: 'Close', - role: 'cancel' - } - ] + role: 'cancel', + }, + ], }); await toast.present(); diff --git a/client/src/interfaces/ngxs.ts b/client/src/interfaces/ngxs.ts index 2f7bdb3..07e4029 100644 --- a/client/src/interfaces/ngxs.ts +++ b/client/src/interfaces/ngxs.ts @@ -1,8 +1,10 @@ import { StateContext } from '@ngxs/store'; +import { type NotifyService } from '@services/notify.service'; import { type VisualService } from '@services/visual.service'; export interface IAttachmentHelpers { visual: VisualService; + notify: NotifyService; } export interface IAttachment { @@ -10,6 +12,6 @@ export interface IAttachment { handler: ( ctx: StateContext, action?: any, - helpers?: IAttachmentHelpers + helpers?: IAttachmentHelpers, ) => void; } diff --git a/client/src/stores/inventory/inventory.actions.ts b/client/src/stores/inventory/inventory.actions.ts index 45e85ac..5d81170 100644 --- a/client/src/stores/inventory/inventory.actions.ts +++ b/client/src/stores/inventory/inventory.actions.ts @@ -10,3 +10,8 @@ export class ApplyInventoryPatches { static type = '[Inventory] Apply Patches'; constructor(public patches: jsonpatch.Operation[]) {} } + +export class RemoveItemFromInventory { + static type = '[Inventory] Remove Item'; + constructor(public instanceId: string) {} +} diff --git a/client/src/stores/notifications/notifications.actions.ts b/client/src/stores/notifications/notifications.actions.ts index 344644f..448161f 100644 --- a/client/src/stores/notifications/notifications.actions.ts +++ b/client/src/stores/notifications/notifications.actions.ts @@ -20,3 +20,8 @@ export class ClearNotificationActions { static type = '[Notifications] Clear Actions'; constructor(public id: string) {} } + +export class Notify { + static type = 'Notify'; + constructor(public messageType: string, public message: string) {} +} diff --git a/client/src/stores/notifications/notifications.attachments.ts b/client/src/stores/notifications/notifications.attachments.ts index 031c395..38854a0 100644 --- a/client/src/stores/notifications/notifications.attachments.ts +++ b/client/src/stores/notifications/notifications.attachments.ts @@ -3,12 +3,14 @@ import { ApplyNotificationsPatches, ClearNotificationActions, MarkNotificationRead, + Notify, SetNotifications, } from './notifications.actions'; import { applyNotificationsPatches, clearActions, markRead, + notify, setNotifications, } from './notifications.functions'; @@ -17,4 +19,5 @@ export const attachments: IAttachment[] = [ { action: ApplyNotificationsPatches, handler: applyNotificationsPatches }, { action: MarkNotificationRead, handler: markRead }, { action: ClearNotificationActions, handler: clearActions }, + { action: Notify, handler: notify }, ]; diff --git a/client/src/stores/notifications/notifications.functions.ts b/client/src/stores/notifications/notifications.functions.ts index 5e80651..bea7eea 100644 --- a/client/src/stores/notifications/notifications.functions.ts +++ b/client/src/stores/notifications/notifications.functions.ts @@ -1,4 +1,8 @@ -import { INotification, INotificationsStore } from '@interfaces'; +import { + IAttachmentHelpers, + INotification, + INotificationsStore, +} from '@interfaces'; import { StateContext } from '@ngxs/store'; import { patch, updateItem } from '@ngxs/store/operators'; import { applyPatch } from 'fast-json-patch'; @@ -7,6 +11,7 @@ import { ApplyNotificationsPatches, ClearNotificationActions, MarkNotificationRead, + Notify, SetNotifications, } from './notifications.actions'; @@ -65,3 +70,11 @@ export function clearActions( }), ); } + +export function notify( + ctx: StateContext, + { message, messageType }: Notify, + helpers: IAttachmentHelpers | undefined, +) { + helpers?.notify.showToast(message, messageType); +} diff --git a/client/src/styles/theme/ateoat.theme.scss b/client/src/styles/theme/ateoat.theme.scss index 212cd06..6b9e29e 100644 --- a/client/src/styles/theme/ateoat.theme.scss +++ b/client/src/styles/theme/ateoat.theme.scss @@ -20,12 +20,12 @@ --ion-color-tertiary-shade: #3d7173; --ion-color-tertiary-tint: #588d8f; - --ion-color-success: #2dd36f; - --ion-color-success-rgb: 45,211,111; - --ion-color-success-contrast: #000000; - --ion-color-success-contrast-rgb: 0,0,0; - --ion-color-success-shade: #28ba62; - --ion-color-success-tint: #42d77d; + --ion-color-success: #27b05d; + --ion-color-success-rgb: 39,176,93; + --ion-color-success-contrast: #ffffff; + --ion-color-success-contrast-rgb: 255,255,255; + --ion-color-success-shade: #229b52; + --ion-color-success-tint: #3db86d; --ion-color-warning: #ffc409; --ion-color-warning-rgb: 255,196,9; diff --git a/server/src/interfaces/api.ts b/server/src/interfaces/api.ts index 61264c8..10dd760 100644 --- a/server/src/interfaces/api.ts +++ b/server/src/interfaces/api.ts @@ -20,6 +20,8 @@ export interface IFullUser { achievements: Achievements; inventory: Inventory; items: InventoryItem[]; + + actions: Array<{ type: string } & any>; } export interface IPatchUser { diff --git a/server/src/modules/discoveries/discoveries.service.ts b/server/src/modules/discoveries/discoveries.service.ts index 89ed4b4..1b7c0b8 100644 --- a/server/src/modules/discoveries/discoveries.service.ts +++ b/server/src/modules/discoveries/discoveries.service.ts @@ -92,7 +92,16 @@ export class DiscoveriesService { }, ); - return { discoveries: discoveryPatches }; + return { + discoveries: discoveryPatches, + actions: [ + { + type: 'Notify', + messageType: 'success', + message: `You collected ${itemDefinition.name}!`, + }, + ], + }; } async discoverEquipment( @@ -127,6 +136,15 @@ export class DiscoveriesService { }, ); - return { discoveries: discoveryPatches }; + return { + discoveries: discoveryPatches, + actions: [ + { + type: 'Notify', + messageType: 'success', + message: `You collected ${itemDefinition.name}!`, + }, + ], + }; } } diff --git a/server/src/modules/player/gameplay.service.ts b/server/src/modules/player/gameplay.service.ts index cb8ae7f..5276ae7 100644 --- a/server/src/modules/player/gameplay.service.ts +++ b/server/src/modules/player/gameplay.service.ts @@ -477,6 +477,17 @@ export class GameplayService { }, ); - return { player: playerPatches }; + return { + player: playerPatches, + actions: [ + { + type: 'Notify', + messageType: 'success', + message: `You sold ${ + item.name + } for ${coinsGained.toLocaleString()} coins!`, + }, + ], + }; } }