Skip to content

Commit

Permalink
turn status
Browse files Browse the repository at this point in the history
  • Loading branch information
Cheelax committed Sep 27, 2023
1 parent 4feec48 commit d93a2f5
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 34 deletions.
32 changes: 16 additions & 16 deletions client/src/dojo/createSystemCalls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export function createSystemCalls(
try {
const tx = await execute(signer, 'Create', [ip, seed, pseudo]);

console.log(tx);
// console.log(tx);
const receipt = (await signer.waitForTransaction(tx.transaction_hash, {
retryInterval: 100,
})) as InvokeTransactionReceiptResponse;
Expand Down Expand Up @@ -61,7 +61,7 @@ export function createSystemCalls(
try {
const tx = await execute(signer, 'Play', [ip, x, y]);

console.log(tx);
// console.log(tx);
const receipt = (await signer.waitForTransaction(tx.transaction_hash, {
retryInterval: 100,
})) as InvokeTransactionReceiptResponse;
Expand Down Expand Up @@ -91,14 +91,14 @@ export function createSystemCalls(
try {
const tx = await execute(signer, 'Spawn', [ip]);

console.log(tx);
// console.log(tx);
const receipt = (await signer.waitForTransaction(tx.transaction_hash, {
retryInterval: 100,
})) as InvokeTransactionReceiptResponse;

const events = receipt.events;

console.log(events);
// console.log(events);
if (events) {
const eventsTransformed = await setComponentsFromEvents(contractComponents, events);
await executeEvents(eventsTransformed, add_hole, set_size, reset_holes, set_hit_mob, set_turn);
Expand Down Expand Up @@ -154,7 +154,7 @@ export async function executeEvents(
}

const characterEvents = events.filter((e): e is CharacterEvent & ComponentData => e.type === 'Character');
console.log('characterEvents', characterEvents);
// console.log('characterEvents', characterEvents);
for (const e of characterEvents) {
if (e.hitter !== 0) {
set_turn(e.hitter);
Expand All @@ -163,7 +163,7 @@ export async function executeEvents(
if (e._type === TileType.Barbarian) hit_mob = 'barbarian';
else if (e._type === TileType.Bowman) hit_mob = 'bowman';
else if (e._type === TileType.Wizard) hit_mob = 'wizard';
console.log('set_hit_mob', hit_mob);
// console.log('set_hit_mob', hit_mob);
set_hit_mob(hit_mob);
} else {
set_turn(e._type);
Expand Down Expand Up @@ -279,11 +279,11 @@ function handleCharacterEvent(
): Omit<CharacterEvent, 'component' | 'componentValues' | 'entityIndex'> {
const [game_id, _type] = keys.map((k) => Number(k));
const [health, index, hitter, hit] = values.map((v) => Number(v));
console.log(
`[Character: KEYS: (game_id: ${game_id}, _type: ${_type}) - VALUES: (health: ${Number(health)}, index: ${Number(
index
)}, hitter: ${Number(hitter)}, hit: ${Number(hit)})]`
);
// console.log(
// `[Character: KEYS: (game_id: ${game_id}, _type: ${_type}) - VALUES: (health: ${Number(health)}, index: ${Number(
// index
// )}, hitter: ${Number(hitter)}, hit: ${Number(hit)})]`
// );
return {
type: 'Character',
game_id,
Expand Down Expand Up @@ -311,11 +311,11 @@ function handleTileEvent(
): Omit<TileEvent, 'component' | 'componentValues' | 'entityIndex'> {
const [game_id, map_id, index] = keys.map((k) => Number(k));
const [_type, x, y] = values.map((v) => Number(v));
console.log(
`[Tile: KEYS: (game_id: ${game_id}, map_id: ${map_id}, index: ${index}) - VALUES: (_type: ${Number(
_type
)}, (x: ${Number(x)}, y: ${Number(y)}))]`
);
// console.log(
// `[Tile: KEYS: (game_id: ${game_id}, map_id: ${map_id}, index: ${index}) - VALUES: (_type: ${Number(
// _type
// )}, (x: ${Number(x)}, y: ${Number(y)}))]`
// );
return {
type: 'Tile',
game_id,
Expand Down
11 changes: 8 additions & 3 deletions client/src/ui/Canvas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import NewGame from './NewGame';
import PassTurnButton from './PassTurnButton';
import ResetButton from './ResetButton';
import Sword from './Sword';
import TurnStatus from './TurnStatus';

interface CanvasProps {
setMusicPlaying: (bool: boolean) => void;
Expand Down Expand Up @@ -339,9 +340,13 @@ const Canvas: React.FC<CanvasProps> = ({ setMusicPlaying }) => {
{map.size !== 0 && <Sword targetY={getYFromMob(turn)} />}
</Container>
</Stage>

{map.size !== 0 && <ResetButton onClick={generateNewGame}></ResetButton>}
{map.size !== 0 && <PassTurnButton onClick={passTurn}></PassTurnButton>}
{map.size !== 0 && (
<div className="flex justify-between items-center -mt-20">
<ResetButton onClick={generateNewGame}></ResetButton>
<TurnStatus isProcessing={hasPlayed} />
<PassTurnButton onClick={passTurn}></PassTurnButton>
</div>
)}
{map.size === 0 && <NewGame onClick={generateNewGame} onPseudoChange={setPseudo} />}

<GameOverModal score={score} isOpen={isGameOver} onClose={() => setIsGameOver(false)} />
Expand Down
4 changes: 2 additions & 2 deletions client/src/ui/PassTurnButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ interface NewGameButtonProps {
const PassTurnButton: React.FC<NewGameButtonProps> = ({ onClick }) => {
return (
<button
className="bg-blue-500 hover:bg-blue-700 mx-10 my-10 text-white font-bold py-2 px-4 rounded"
style={{ width: '160px', position: 'absolute', bottom: '0', right: '2rem' }}
className="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded"
style={{ width: '160px', margin: '10px' }}
onClick={onClick}
>
Pass turn
Expand Down
9 changes: 9 additions & 0 deletions client/src/ui/TurnStatus.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
type Props = {
isProcessing: boolean;
};

const TurnStatus = ({ isProcessing }: Props) => {
return <div className="w-50">{isProcessing ? <p>Processing turn...</p> : <p>Your turn!</p>}</div>;
};

export default TurnStatus;
26 changes: 13 additions & 13 deletions client/src/utils/animation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,39 +33,39 @@ export const getFramesFromType = (
const frames = Object.keys(resource.data.frames);
let filtered = [];
if (type === Animation.Idle) {
console.log('[', mob_name, ']', 'Idle Frame');
// console.log('[', mob_name, ']', 'Idle Frame');
filtered = frames.filter((e) => e.includes('idle'));
} else if (type === Animation.Walk) {
console.log('[', mob_name, ']', 'Walk Frame');
// console.log('[', mob_name, ']', 'Walk Frame');
filtered = frames.filter((e) => e.includes('walk'));
} else if (type === Animation.Carry) {
console.log('[', mob_name, ']', 'Carry Frame');
// console.log('[', mob_name, ']', 'Carry Frame');
filtered = frames.filter((e) => e.includes('carry'));
} else if (type === Animation.Jump) {
console.log('[', mob_name, ']', 'Jump Frame');
// console.log('[', mob_name, ']', 'Jump Frame');
filtered = frames.filter((e) => e.includes('jump'));
} else if (type === Animation.SwordAttack) {
console.log('[', mob_name, ']', 'SwordAttack Frame');
// console.log('[', mob_name, ']', 'SwordAttack Frame');
filtered = frames.filter((e) => e.includes('sword'));
} else if (type === Animation.BowAttack) {
console.log('[', mob_name, ']', 'BowAttack Frame');
// console.log('[', mob_name, ']', 'BowAttack Frame');
filtered = frames.filter((e) => e.includes('-bow'));
} else if (type === Animation.StaffAttack) {
console.log('[', mob_name, ']', 'StaffAttack Frame');
// console.log('[', mob_name, ']', 'StaffAttack Frame');
filtered = frames.filter((e) => e.includes('staff'));
} else if (type === Animation.Throw) {
console.log('[', mob_name, ']', 'Throw Frame');
// console.log('[', mob_name, ']', 'Throw Frame');
filtered = frames.filter((e) => e.includes('throw'));
} else if (type === Animation.Hurt) {
console.log('[', mob_name, ']', 'Hurt Frame');
// console.log('[', mob_name, ']', 'Hurt Frame');
filtered = frames.filter((e) => e.includes('hurt'));
} else if (type === Animation.Death) {
console.log('[', mob_name, ']', 'Death Frame');
// console.log('[', mob_name, ']', 'Death Frame');
filtered = frames.filter((e) => e.includes('death'));
} else {
throw new Error('Invalid AnimationType');
}
console.log('FILTERED', filtered);
// console.log('FILTERED', filtered);
if (direction === Direction.SE) {
filtered = filtered.filter((e) => /-SE-/.test(e));
} else if (direction === Direction.SW) {
Expand All @@ -84,11 +84,11 @@ export const getFramesFromType = (
filtered = filtered.filter((e) => /-W-/.test(e) && !/-SW-/.test(e) && !/-NW-/.test(e));
}

console.log(filtered);
// console.log(filtered);

return filtered.map((frame: any) => {
const texture = Texture.from(frame);
console.log(texture);
// console.log(texture);
texture.baseTexture.scaleMode = SCALE_MODES.NEAREST;
return texture;
}) as Texture[];
Expand Down

0 comments on commit d93a2f5

Please sign in to comment.