Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion client/dev-dist/sw.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ define(['./workbox-20a2f87f'], (function (workbox) { 'use strict';
"revision": "3ca0b8505b4bec776b69afdba2768812"
}, {
"url": "index.html",
"revision": "0.shqbum89m38"
"revision": "0.o26d1okn5o8"
}], {});
workbox.cleanupOutdatedCaches();
workbox.registerRoute(new workbox.NavigationRoute(workbox.createHandlerBoundToURL("index.html"), {
Expand Down
27 changes: 11 additions & 16 deletions client/src/components/FlappyBeasts/flappyBeasts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ const BIRD_COLLIDER_OFFSET_Y = (BIRD_HEIGHT - BIRD_COLLIDER_HEIGHT) / 2;

// Types and Interfaces
import { FlappyBirdRefHandle, FlappyBirdProps } from '../../types/components';
import { Account } from 'starknet';

const FlappyBirdMiniGame = forwardRef<FlappyBirdRefHandle, FlappyBirdProps>(({
className = '',
Expand Down Expand Up @@ -168,20 +169,11 @@ const FlappyBirdMiniGame = forwardRef<FlappyBirdRefHandle, FlappyBirdProps>(({
await handleAction(
"SaveGameResults",
async () => {
await client.player.updatePlayerTotalPoints(
account,
score
)
await client.player.updatePlayerMinigameHighestScore(
account,
score,
2
)
await client.player.addOrUpdateFoodAmount(
account,
foodId,
foodCollected
)
await client.player.updatePlayerTotalPoints(account, score);
const txtest = await client.achieve.achievePlayerNewTotalPoints(account);
console.info('achievePlayerNewTotalPoints fkaooy', txtest);
await client.player.updatePlayerMinigameHighestScore(account, score, 2);
await client.player.addOrUpdateFoodAmount(account, foodId, foodCollected);
});
return true;
} else {
Expand Down Expand Up @@ -217,15 +209,16 @@ const FlappyBirdMiniGame = forwardRef<FlappyBirdRefHandle, FlappyBirdProps>(({
};

// Handle game over
const handleGameEnd = () => {
const handleGameEnd = async () => {

const score = currentScoreRef.current;
setFinalScore(score);
const dojoHighScore = myScoreFlappyBird.length > 0 ? myScoreFlappyBird[0]?.score : 0;
const actualHighScore = Math.max(dojoHighScore, currentHighScore);

if (score > actualHighScore) {
setCurrentHighScore(score);
const tx = await client.achieve.achieveFlappyBeastHighscore(account as Account, score);
console.info('tx flappy highscore', tx);
} else {
setCurrentHighScore(actualHighScore);
}
Expand Down Expand Up @@ -893,6 +886,8 @@ const FlappyBirdMiniGame = forwardRef<FlappyBirdRefHandle, FlappyBirdProps>(({
{currentScreen === 'sharing' && (
<div className="modal-overlay">
<ShareProgress
account={account}
client={client}
isOpen={isShareModalOpen}
onClose={() => {
setIsShareModalOpen(false);
Expand Down
6 changes: 5 additions & 1 deletion client/src/components/Header/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import download from "../../assets/img/icon-download.svg";

// Styles
import './main.css';
import { useDojoSDK } from "@dojoengine/sdk/react";

// Constants
const WEBSITE_URL = 'https://website.bytebeasts.games';
Expand Down Expand Up @@ -56,8 +57,9 @@ const Header: React.FC<HeaderProps> = ({ tamagotchiStats }) => {
// Hooks
const { beastsData: beasts } = useBeasts();
const { player } = usePlayer();
const { client } = useDojoSDK();
const location = useLocation();
const { connector } = useAccount();
const { account, connector } = useAccount();
const [buttonSound] = useSound(buttonClick, { volume: SOUND_VOLUME, preload: true });

// Derived state
Expand Down Expand Up @@ -176,6 +178,8 @@ const Header: React.FC<HeaderProps> = ({ tamagotchiStats }) => {

{tamagotchiStats && (
<ShareProgress
account={account}
client={client}
isOpen={isShareModalOpen}
onClose={() => setIsShareModalOpen(false)}
type="beast"
Expand Down
10 changes: 9 additions & 1 deletion client/src/components/SkyJumpMiniGame/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { InputHandler } from './inputHandler';
import RestartIcon from '../../assets/img/icon-restart.svg';

import './main.css';
import { Account } from 'starknet';

const CanvasSkyJumpGame = forwardRef<SkyJumpGameRefHandle, CanvasSkyJumpGameProps>(({
className = '',
Expand Down Expand Up @@ -84,14 +85,16 @@ const CanvasSkyJumpGame = forwardRef<SkyJumpGameRefHandle, CanvasSkyJumpGameProp
}, [onScoreUpdate]);

// Callback when the game engine signals game over
const handleEngineGameOver = useCallback((engineFinalScore: number) => {
const handleEngineGameOver = useCallback(async (engineFinalScore: number) => {
setFinalScore(engineFinalScore);
setIsGameOverState(true);

const dojoHighScore = myScoreSkyJump.length > 0 ? myScoreSkyJump[0]?.score : 0;

if (engineFinalScore > dojoHighScore) {
setCurrentHighScore(engineFinalScore);
const tx = await client.achieve.achievePlatformHighscore(account as Account, engineFinalScore);
console.info('tx sky jump achievePlatformHighscore', tx);
} else {
setCurrentHighScore(dojoHighScore);
}
Expand Down Expand Up @@ -203,6 +206,9 @@ const CanvasSkyJumpGame = forwardRef<SkyJumpGameRefHandle, CanvasSkyJumpGameProp

const addOrUpdateFoodAmount = await client.player.addOrUpdateFoodAmount(account, foodId, foodCollected);
console.info('addOrUpdateFoodAmount', addOrUpdateFoodAmount);

const achievePlayerNewTotalPoints = await client.achieve.achievePlayerNewTotalPoints(account);
console.info('achievePlayerNewTotalPoints', achievePlayerNewTotalPoints);
}
);
return true;
Expand Down Expand Up @@ -333,6 +339,8 @@ const CanvasSkyJumpGame = forwardRef<SkyJumpGameRefHandle, CanvasSkyJumpGameProp
{currentScreen === 'sharing' && selectedFoodReward && (
<div className="skyjump-modal-overlay">
<ShareProgress
account={account}
client={client}
isOpen={true}
onClose={() => setCurrentScreen('gameover')}
type="minigame"
Expand Down
4 changes: 1 addition & 3 deletions client/src/components/SpawnBeast/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,9 @@ const SpawnBeast: React.FC<SpawnBeastProps> = ({ className = '' }) => {
// Recargar la lista de beasts usando GraphQL
const beastsData = await fetchBeastsData();
const processedBeasts = await processBeastData(beastsData);
console.info('processedBeasts', processedBeasts);


// Encontrar la bestia recién creada
newBeast = processedBeasts.find((beast: Beast) => beast.player === account!.address);
console.info('newBeast', newBeast);
await new Promise(resolve => setTimeout(resolve, 2000));
} while (!newBeast);

Expand Down
3 changes: 1 addition & 2 deletions client/src/components/Tamagotchi/Actions/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@ const Actions = ({
if (action === 'sleep') {
await client.achieve.achieveBeastSleep(account as Account);
} else if (action === 'clean') {
const txss = await client.achieve.achieveBeastClean(account as Account);
console.info('txss', txss);
await client.achieve.achieveBeastClean(account as Account);
}
},
beastsDex[beast.specie - 1][pictureKey]
Expand Down
5 changes: 4 additions & 1 deletion client/src/components/Tamagotchi/Chat/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// React and external libraries
import { useState, useRef } from "react";
import { Account } from "starknet";

// Internal components
import MessageComponent from "../../ui/message";
Expand Down Expand Up @@ -29,7 +30,7 @@ const context = `Remembre this is your context,
`;


const Chat = ({ beast, expanded, botMessage, setBotMessage }: { beast: any, expanded: boolean, botMessage: any, setBotMessage: any }) => {
const Chat = ({ beast, expanded, botMessage, setBotMessage, client, account }: { beast: any, expanded: boolean, botMessage: any, setBotMessage: any, client: any, account: any }) => {
const { isLoading, error, sendMessage } = useBeastChat({ beast, setBotMessage });

const [input, setInput] = useState("");
Expand All @@ -43,6 +44,8 @@ const Chat = ({ beast, expanded, botMessage, setBotMessage }: { beast: any, expa

const handleSendMessage = async () => {
if (input.trim() === "" || isLoading) return;

await client.achieve.achieveBeastChat(account as Account);

const messageWithContext = `${context}\n\nUser: ${input}`;
await sendMessage(messageWithContext);
Expand Down
4 changes: 4 additions & 0 deletions client/src/components/Tamagotchi/Play/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ const Play: React.FC<PlayProps> = ({
}

try {

const tx = await client.achieve.achievePlayMinigame(account);
console.info('tx achievePlayMinigame', tx);

handleAction(
"Play",
async () => {
Expand Down
4 changes: 2 additions & 2 deletions client/src/components/Tamagotchi/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ function Tamagotchi() {
if (foundBeast) setCurrentBeast(foundBeast);
}, [player, beasts]);

console.info('player', player);

const getShareableStats = () => {
if (!currentBeast || !status) return undefined;

Expand Down Expand Up @@ -141,6 +139,8 @@ function Tamagotchi() {
/>
) : currentView === 'chat' ? (
<Chat
account={account}
client={client}
botMessage={botMessage}
setBotMessage={setBotMessage}
beast={currentBeast}
Expand Down
33 changes: 23 additions & 10 deletions client/src/components/Twitter/ShareProgress.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ interface ShareModalProps {
name: string;
score: number;
};
account: any;
client: any;
}

export const ShareProgress: React.FC<ShareModalProps> = ({
Expand All @@ -28,14 +30,16 @@ export const ShareProgress: React.FC<ShareModalProps> = ({
type,
stats,
minigameData,
account,
client,
}) => {
const [tweetMsg, setTweetMsg] = useState("");

useEffect(() => {
if (type === 'beast' && stats) {
setTweetMsg(
`🎮 Playing ByteBeasts Tamagotchi, and here is my Beast's progress:\n\n` +
`🕰️ Age: ${stats.age}` + ` ${stats.age == 1 ? 'day' : 'days' }\n` +
`🕰️ Age: ${stats.age}` + ` ${stats.age == 1 ? 'day' : 'days'}\n` +
`⚡ Energy: ${stats.energy} \n` +
`🍖 Hunger: ${stats.hunger} \n` +
`😊 Happiness: ${stats.happiness} \n` +
Expand Down Expand Up @@ -72,15 +76,15 @@ export const ShareProgress: React.FC<ShareModalProps> = ({
<div className="modal-content">
<div className="modal-header">
<h2>Share on X</h2>
<button
className="close-button"
<button
className="close-button"
onClick={(e) => {
e.stopPropagation();
onClose();
}}
>×</button>
</div>

<div className="modal-body">
<textarea
value={tweetMsg}
Expand All @@ -89,19 +93,28 @@ export const ShareProgress: React.FC<ShareModalProps> = ({
className="tweet-textarea p"
/>
</div>

<div className="modal-footer">
<a
href={tweetText}
target="_blank"
rel="noreferrer"
className="share-button"
onClick={(e) => e.stopPropagation()}
onClick={async (e) => {
e.stopPropagation();
if (minigameData) {
const tx = await client.achieve.achieveScoreShare(account, minigameData.score);
console.info('achieveScoreShare ', tx)
} else {
const tx = await client.achieve.achieveBeastShare(account);
console.info('achieveBeastShare ', tx)
}
}}
>
Share
</a>
</div>
Share
</a>
</div>
</div>
</div >
);
};
};
8 changes: 6 additions & 2 deletions client/src/config/cartridgeConnector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,12 @@ const policies: SessionPolicies = {
entrypoint: "achieve_player_new_total_points"
},
{
name: "achieve_social_share",
entrypoint: "achieve_social_share"
name: "achieve_score_share",
entrypoint: "achieve_score_share"
},
{
name: "achieve_beast_share",
entrypoint: "achieve_beast_share"
},
],
},
Expand Down
35 changes: 29 additions & 6 deletions client/src/dojo/contracts.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,19 +192,40 @@ export function setupWorld(provider: DojoProvider) {
}
};

const build_achieve_achieveSocialShare_calldata = (score: number): DojoCall => {
const build_achieve_achieveScoreShare_calldata = (score: number): DojoCall => {
return {
contractName: "achieve",
entrypoint: "achieve_social_share",
entrypoint: "achieve_score_share",
calldata: [score],
};
};

const achieve_achieveSocialShare = async (snAccount: Account | AccountInterface, score: number) => {
const achieve_achieveScoreShare = async (snAccount: Account | AccountInterface, score: number) => {
try {
return await provider.execute(
snAccount as any,
build_achieve_achieveSocialShare_calldata(score),
build_achieve_achieveScoreShare_calldata(score),
"tamagotchi",
);
} catch (error) {
console.error(error);
throw error;
}
};

const build_achieve_achieveBeastShare_calldata = (): DojoCall => {
return {
contractName: "achieve",
entrypoint: "achieve_beast_share",
calldata: [],
};
};

const achieve_achieveBeastShare = async (snAccount: Account | AccountInterface) => {
try {
return await provider.execute(
snAccount as any,
build_achieve_achieveBeastShare_calldata(),
"tamagotchi",
);
} catch (error) {
Expand Down Expand Up @@ -655,8 +676,10 @@ export function setupWorld(provider: DojoProvider) {
buildAchievePlayMinigameCalldata: build_achieve_achievePlayMinigame_calldata,
achievePlayerNewTotalPoints: achieve_achievePlayerNewTotalPoints,
buildAchievePlayerNewTotalPointsCalldata: build_achieve_achievePlayerNewTotalPoints_calldata,
achieveSocialShare: achieve_achieveSocialShare,
buildAchieveSocialShareCalldata: build_achieve_achieveSocialShare_calldata,
achieveBeastShare: achieve_achieveBeastShare,
buildAchieveBeastShareCalldata: build_achieve_achieveBeastShare_calldata,
achieveScoreShare: achieve_achieveScoreShare,
buildAchieveScoreShareCalldata: build_achieve_achieveScoreShare_calldata,
},
player: {
addOrUpdateFoodAmount: player_addOrUpdateFoodAmount,
Expand Down
Loading