Skip to content

Commit

Permalink
Added a way to load the game.
Browse files Browse the repository at this point in the history
- We load a simplified character sheet
- We load monsters

Various refactorings and changes, including adding in a progress loader.

Also created a way where we can simplify some of the imports such as the api handler, the
new game loader context and so on.
  • Loading branch information
AdamKyle committed Dec 31, 2024
1 parent 2b595d4 commit e22c089
Show file tree
Hide file tree
Showing 81 changed files with 4,764 additions and 4,302 deletions.
8,262 changes: 4,131 additions & 4,131 deletions _ide_helper.php

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function transform(Character $character): array
'attack' => $characterStatBuilder->buildTotalAttack(),
'health' => $characterStatBuilder->buildHealth(),
'ac' => $characterStatBuilder->buildDefence(),
'class_bonus_chance' => (new ClassAttackValue($character))->buildAttackData(),
'class_bonus_chance' => (new ClassAttackValue($character))->buildAttackData()['chance'],
'gold' => number_format($character->gold),
'gold_dust' => number_format($character->gold_dust),
'shards' => number_format($character->shards),
Expand Down
14 changes: 6 additions & 8 deletions app/Game/Battle/Controllers/Api/BattleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,12 @@ public function index(Character $character): JsonResponse

$monsters = collect($monsters);

return response()->json([
'monsters' => $monsters->map(function ($monster) {
return [
'id' => $monster['id'],
'name' => $monster['name'],
];
}),
]);
return response()->json($monsters->map(function ($monster) {
return [
'id' => $monster['id'],
'name' => $monster['name'],
];
}));
}

public function setupMonster(AttackTypeRequest $attackTypeRequest, Character $character, Monster $monster): JsonResponse
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ public function sheet(Character $character, CharacterSheetBaseInfoTransformer $c
$character = new Item($character, $characterSheetBaseInfoTransformer);
$sheet = $this->manager->createData($character)->toArray();

return response()->json([
'sheet' => $sheet,
], 200);
return response()->json($sheet);
}

public function baseCharacterInformation(Character $character, CharacterSheetBaseInfoTransformer $characterBaseInfo)
Expand Down
13 changes: 13 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ export default [
'import/resolver': {
alias: {
map: [
['event-system', './resources/js/even-system'],
['axios', './resources/js/api-handler'],
['game-data', './resources/js/game-data'],
['components', './resources/js/components'],
['ui', './resources/js/ui'],
['service-container', './resources/js/service-container'],
Expand Down Expand Up @@ -69,11 +72,21 @@ export default [
group: "internal",
position: "before",
},
{
pattern: "api-handler/**",
group: "internal",
position: "after",
},
{
pattern: "event-system/**",
group: "internal",
position: "after",
},
{
pattern: "game-data/**",
group: "internal",
position: "after",
},
{
pattern: "ui/**",
group: "internal",
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import axios, { AxiosRequestConfig, AxiosResponse } from 'axios';

import AxiosDefinition from './definitions/axios-definition';

export default class Axios implements AxiosDefinition {
export default class ApiHandler implements AxiosDefinition {
async get<T>(url: string, config: AxiosRequestConfig = {}): Promise<T> {
this.setCsrfToken(config);
const modifiedUrl = this.addApiPrefix(url);
Expand Down Expand Up @@ -64,7 +64,9 @@ export default class Axios implements AxiosDefinition {
}
config.headers = {
...config.headers,
Accept: 'application/json',
'X-CSRF-Token': csrfToken,
'X-Requested-With': 'XMLHttpRequest',
};
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { ModularContainerDefinition } from 'configuration/deffinitions/modular-container-definition';

import Axios from './axios';
import ApiHandler from './api-handler';
import AxiosDefinition from './definitions/axios-definition';
import CoreContainerDefinition from '../service-container/deffinitions/core-container-definition';

export const axiosServiceContainer: ModularContainerDefinition = (
container: CoreContainerDefinition
) => {
container.register<AxiosDefinition>('ApiHandler', new Axios());
container.register<AxiosDefinition>('ApiHandler', new ApiHandler());
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export default interface ApiParametersDefinitions {
url: string;
urlParams?: Record<string, number>;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export type AxiosErrorDefinition = {
message: string;
};
File renamed without changes.
File renamed without changes.
26 changes: 0 additions & 26 deletions resources/js/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,6 @@ try {
} catch (e) {
}

/**
* We'll load the axios HTTP library which allows us to easily issue requests
* to our Laravel back-end. This library automatically handles sending the
* CSRF token as a header based on the value of the "XSRF" token cookie.
*/

import axios from 'axios';
window.axios = axios;

window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';

let token = document.head.querySelector('meta[name="csrf-token"]');

axios.interceptors.request.use(function (config) {
config.headers = {
Accept: 'application/json',
'X-CSRF-TOKEN': token.content,
'X-Requested-With': 'XMLHttpRequest'
};

return config;
}, function (error) {
return Promise.reject(error);
});


/**
* Echo exposes an expressive API for subscribing to channels and listening
* for events that are broadcast by Laravel. Echo and event broadcasting
Expand Down
2 changes: 1 addition & 1 deletion resources/js/configuration/modular-container.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { axiosServiceContainer } from 'api-handler/axios-service-container';
import { eventServiceContainer } from 'event-system/event-service-container';

import { ModularContainerDefinition } from './deffinitions/modular-container-definition';
import { axiosServiceContainer } from '../axios/axios-service-container';

/**
* Register service containers here.
Expand Down
2 changes: 0 additions & 2 deletions resources/js/event-system/event-emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ export default class EventEmitter<T extends EventMapDefinition>
}

this.listeners[eventType].push(listener);

console.log(this.listeners);
}

emit<K extends keyof T>(eventType: K, data: T[K]): void {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import InventoryCountDefinition from './inventory-count-definition';

export default interface CharacterSheetDefinition {
id: number;
user_id: number;
name: string;
class: string;
class_id: number;
class_bonus_chance: number;
race: string;
race_id: number;
level: string;
max_level: string;
xp: number;
xp_next: number;
to_hit_stat: string;
ac: number;
attack: number;
health: number;
resurrection_chance: number;
gold: string;
gold_dust: string;
shards: string;
copper_coins: string;
str_modded: number;
dex_modded: number;
int_modded: number;
dur_modded: number;
agi_modded: number;
chr_modded: number;
focus_modded: number;
inventory_count: InventoryCountDefinition;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default interface InventoryCountDefinition {
inventory_max: number;
inventory_count: number;
gem_bag_count: number;
inventory_bag_count: number;
alchemy_item_count: number;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export default interface MonsterDefinition {
name: string;
id: number;
}
17 changes: 17 additions & 0 deletions resources/js/game-data/components/game-data-provider.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React, { useState } from 'react';

import { GameDataContext } from '../game-data-context';
import GameDataProviderProps from './types/game-data-provider-props';
import GameDataDefinition from '../deffinitions/game-data-definition';

const GameDataProvider = (props: GameDataProviderProps): React.ReactNode => {
const [gameData, setGameData] = useState<GameDataDefinition | null>(null);

return (
<GameDataContext.Provider value={{ gameData, setGameData }}>
{props.children}
</GameDataContext.Provider>
);
};

export default GameDataProvider;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { ReactNode } from 'react';

export default interface GameDataProviderProps {
children: ReactNode;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import React from 'react';

import GameDataDefinition from './game-data-definition';

export default interface GameDataContextDefinition {
gameData: GameDataDefinition | null;
setGameData: React.Dispatch<React.SetStateAction<GameDataDefinition | null>>;
}
7 changes: 7 additions & 0 deletions resources/js/game-data/deffinitions/game-data-definition.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import CharacterSheetDefinition from '../api-data-definitions/character/character-sheet-definition';
import MonsterDefinition from '../api-data-definitions/monsters/monster-definition';

export default interface GameDataDefinition {
character: CharacterSheetDefinition | null;
monsters: MonsterDefinition[] | [];
}
7 changes: 7 additions & 0 deletions resources/js/game-data/game-data-context.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { createContext } from 'react';

import GameDataContextDefinition from './deffinitions/game-data-context-definition';

export const GameDataContext = createContext<GameDataContextDefinition | null>(
null
);
14 changes: 14 additions & 0 deletions resources/js/game-data/hooks/use-game-data.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { useContext } from 'react';

import GameDataContextDefinition from '../deffinitions/game-data-context-definition';
import { GameDataContext } from '../game-data-context';

export const useGameData = (): GameDataContextDefinition => {
const context = useContext(GameDataContext);

if (!context) {
throw new Error('useGameData must be used within an GameDataProvider');
}

return context;
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import { useManageMonsterStatSectionVisibility } from './hooks/use-manage-monste
import { Alert } from 'ui/alerts/alert';
import { AlertVariant } from 'ui/alerts/enums/alert-variant';
import Card from 'ui/cards/card';
import Container from 'ui/container/container';
import ContainerWithTitle from 'ui/container/container-with-title';
import Separator from 'ui/seperatror/separator';

export const MonsterStatSection = (): ReactNode => {
const { closeMonsterStats } = useManageMonsterStatSectionVisibility();

return (
<Container
<ContainerWithTitle
manageSectionVisibility={closeMonsterStats}
title={'Monster Name'}
>
Expand Down Expand Up @@ -149,6 +149,6 @@ export const MonsterStatSection = (): ReactNode => {
</div>
</div>
</Card>
</Container>
</ContainerWithTitle>
);
};

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit e22c089

Please sign in to comment.