diff --git a/client/src/config/cartridgeConnector.tsx b/client/src/config/cartridgeConnector.tsx index 2b58c71..de71861 100644 --- a/client/src/config/cartridgeConnector.tsx +++ b/client/src/config/cartridgeConnector.tsx @@ -6,7 +6,7 @@ import { constants } from "starknet"; const { VITE_PUBLIC_DEPLOY_TYPE } = import.meta.env; -const CONTRACT_ADDRESS_GAME = '0x681ea222117a7e68124fdb1dbbdee016a560fd453b846fb54bef34be325882d' +const CONTRACT_ADDRESS_GAME = '0x36a518498c1d7de4106b8904f0878e1e7b78c73614001fba22eba0adca80387' const policies: SessionPolicies = { contracts: { @@ -19,6 +19,9 @@ const policies: SessionPolicies = { { name: "update_golem_name", entrypoint: "update_golem_name" }, { name: "unlock_golem_store", entrypoint: "unlock_golem_store" }, { name: "unlock_world_store", entrypoint: "unlock_world_store" }, + { name: "create_mission", entrypoint: "create_mission" }, + { name: "update_mission", entrypoint: "update_mission" }, + { name: "reward_current_mission", entrypoint: "reward_current_mission" }, ], }, }, @@ -39,7 +42,7 @@ const options: ControllerOptions = { theme, colorMode, namespace: "golem_runner", - slot: "golem5", + slot: "golem6", }; const cartridgeConnector = new ControllerConnector( diff --git a/client/src/config/manifest_sepolia.json b/client/src/config/manifest_sepolia.json index f63e4eb..61a785f 100644 --- a/client/src/config/manifest_sepolia.json +++ b/client/src/config/manifest_sepolia.json @@ -1,8 +1,8 @@ { "world": { "class_hash": "0x7c9469d45a9cdbab775035afb48e1fa73fb35ab059fcb9dfb0a301aa973e783", - "address": "0x1fe4f3da25325886ab8c89826d0af42385e36f2cdb717441532e3220d179da4", - "seed": "golem_runner6", + "address": "0x7c677ef29a276a115468ee7f53094720de5da6d443e6f1a2b7f4a6afb6f86b2", + "seed": "golem_runner7", "name": "Golem Runner", "entrypoints": [ "uuid", @@ -1312,8 +1312,8 @@ }, "contracts": [ { - "address": "0x681ea222117a7e68124fdb1dbbdee016a560fd453b846fb54bef34be325882d", - "class_hash": "0x3341e5d0066d25ab19de417dd772c05593d88063f6084b81b03841d4802d909", + "address": "0x36a518498c1d7de4106b8904f0878e1e7b78c73614001fba22eba0adca80387", + "class_hash": "0x75e15e84fe204faeaa58f91e626f7e4d0a8ca897763f28e0d96ffc1b0a52c2", "abi": [ { "type": "impl", @@ -1405,6 +1405,42 @@ } ] }, + { + "type": "enum", + "name": "golem_runner::types::world::WorldType", + "variants": [ + { + "name": "Forest", + "type": "()" + }, + { + "name": "Volcano", + "type": "()" + }, + { + "name": "Glacier", + "type": "()" + } + ] + }, + { + "type": "enum", + "name": "golem_runner::types::golem::GolemType", + "variants": [ + { + "name": "Fire", + "type": "()" + }, + { + "name": "Ice", + "type": "()" + }, + { + "name": "Stone", + "type": "()" + } + ] + }, { "type": "interface", "name": "golem_runner::systems::game::IGame", @@ -1502,6 +1538,62 @@ } ], "state_mutability": "external" + }, + { + "type": "function", + "name": "create_mission", + "inputs": [ + { + "name": "target_coins", + "type": "core::integer::u64" + }, + { + "name": "required_world", + "type": "golem_runner::types::world::WorldType" + }, + { + "name": "required_golem", + "type": "golem_runner::types::golem::GolemType" + }, + { + "name": "description", + "type": "core::byte_array::ByteArray" + } + ], + "outputs": [], + "state_mutability": "external" + }, + { + "type": "function", + "name": "update_mission", + "inputs": [ + { + "name": "mission_id", + "type": "core::integer::u256" + } + ], + "outputs": [ + { + "type": "core::bool" + } + ], + "state_mutability": "external" + }, + { + "type": "function", + "name": "reward_current_mission", + "inputs": [ + { + "name": "mission_id", + "type": "core::integer::u256" + }, + { + "name": "coins_collected", + "type": "core::integer::u64" + } + ], + "outputs": [], + "state_mutability": "external" } ] }, @@ -1636,6 +1728,9 @@ "update_golem_name", "unlock_golem_store", "unlock_world_store", + "create_mission", + "update_mission", + "reward_current_mission", "upgrade" ] } @@ -1648,6 +1743,12 @@ "tag": "golem_runner-Golem", "selector": "0x5a1af4923c31f36a9a9b5cd3f717dac8c55c1e6a26e92a0e4f28d30754166db" }, + { + "members": [], + "class_hash": "0x2d620c3d3bc76ab5016d9707bcc9ca995ee446492cb26fc41744600d04ecf0f", + "tag": "golem_runner-Mission", + "selector": "0x53894aba2c90ef9aeb7f37e5690c7f994547a79dcce91e9f2f098baa85587a" + }, { "members": [], "class_hash": "0x3f2287ca0736b645e3c9b3b4a09d1b15c1637debf3ccfbfd180aafe43f75d27", diff --git a/client/src/dojo/bindings.ts b/client/src/dojo/bindings.ts index e19958f..af33192 100644 --- a/client/src/dojo/bindings.ts +++ b/client/src/dojo/bindings.ts @@ -16,14 +16,36 @@ export interface Golem { // Type definition for `golem_runner::models::golem::GolemValue` struct export interface GolemValue { - name: number; - description: number; + name: string; + description: string; price: number; rarity: RarityEnum; is_starter: boolean; is_unlocked: boolean; } +// Type definition for `golem_runner::models::mission::Mission` struct +export interface Mission { + id: number; + player_id: string; + target_coins: number; + required_world: WorldTypeEnum; + required_golem: GolemTypeEnum; + description: string; + status: MissionStatusEnum; + created_at: number; +} + +// Type definition for `golem_runner::models::mission::MissionValue` struct +export interface MissionValue { + target_coins: number; + required_world: WorldTypeEnum; + required_golem: GolemTypeEnum; + description: string; + status: MissionStatusEnum; + created_at: number; +} + // Type definition for `golem_runner::models::player::Player` struct export interface Player { address: string; @@ -40,9 +62,9 @@ export interface Player { export interface PlayerValue { coins: number; total_points: number; - level: number; daily_streak: number; last_active_day: number; + level: number; experience: number; creation_day: number; } @@ -72,8 +94,8 @@ export interface World { // Type definition for `golem_runner::models::world::WorldValue` struct export interface WorldValue { - name: number; - description: number; + name: string; + description: string; price: number; is_starter: boolean; is_unlocked: boolean; @@ -131,6 +153,21 @@ export interface Task { description: string; } +// Type definition for `golem_runner::types::golem::GolemType` enum +export type GolemType = { + Fire: string; + Ice: string; + Stone: string; +} +export type GolemTypeEnum = CairoCustomEnum; + +// Type definition for `golem_runner::types::mission_status::MissionStatus` enum +export type MissionStatus = { + Pending: string; + Completed: string; +} +export type MissionStatusEnum = CairoCustomEnum; + // Type definition for `golem_runner::types::rarity::Rarity` enum export type Rarity = { Basic: string; @@ -143,10 +180,20 @@ export type Rarity = { } export type RarityEnum = CairoCustomEnum; +// Type definition for `golem_runner::types::world::WorldType` enum +export type WorldType = { + Forest: string; + Volcano: string; + Glacier: string; +} +export type WorldTypeEnum = CairoCustomEnum; + export interface SchemaType extends ISchemaType { golem_runner: { Golem: Golem, GolemValue: GolemValue, + Mission: Mission, + MissionValue: MissionValue, Player: Player, PlayerValue: PlayerValue, Ranking: Ranking, @@ -171,31 +218,65 @@ export const schema: SchemaType = { description: "", price: 0, rarity: new CairoCustomEnum({ - Basic: "Basic", - Common: "Common", - Uncommon: "Uncommon", - Rare: "Rare", - VeryRare: "VeryRare", - Epic: "Epic", - Unique: "Unique", }), + Basic: "Basic", + Common: "Common", + Uncommon: "Uncommon", + Rare: "Rare", + VeryRare: "VeryRare", + Epic: "Epic", + Unique: "Unique", }), is_starter: false, is_unlocked: false, }, GolemValue: { - name: 0, - description: 0, + name: "", + description: "", price: 0, rarity: new CairoCustomEnum({ - Basic: "Basic", - Common: "Common", - Uncommon: "Uncommon", - Rare: "Rare", - VeryRare: "VeryRare", - Epic: "Epic", - Unique: "Unique", }), + Basic: "Basic", + Common: "Common", + Uncommon: "Uncommon", + Rare: "Rare", + VeryRare: "VeryRare", + Epic: "Epic", + Unique: "Unique", }), is_starter: false, is_unlocked: false, }, + Mission: { + id: 0, + player_id: "", + target_coins: 0, + required_world: new CairoCustomEnum({ + Forest: "Forest", + Volcano: "Volcano", + Glacier: "Glacier", }), + required_golem: new CairoCustomEnum({ + Fire: "Fire", + Ice: "Ice", + Stone: "Stone", }), + description: "", + status: new CairoCustomEnum({ + Pending: "Pending", + Completed: "Completed", }), + created_at: 0, + }, + MissionValue: { + target_coins: 0, + required_world: new CairoCustomEnum({ + Forest: "Forest", + Volcano: "Volcano", + Glacier: "Glacier", }), + required_golem: new CairoCustomEnum({ + Fire: "Fire", + Ice: "Ice", + Stone: "Stone", }), + description: "", + status: new CairoCustomEnum({ + Pending: "Pending", + Completed: "Completed", }), + created_at: 0, + }, Player: { address: "", coins: 0, @@ -233,68 +314,73 @@ export const schema: SchemaType = { is_unlocked: false, }, WorldValue: { - name: 0, - description: 0, + name: "", + description: "", price: 0, is_starter: false, is_unlocked: false, }, }, - achievement: { - TrophyCreation: { - id: 0, - hidden: false, - index: 0, - points: 0, - start: 0, - end: 0, - group: 0, - icon: 0, - title: 0, - description: "", - tasks: [{ id: 0, total: 0, description: "", }], - data: "", - }, - TrophyCreationValue: { - hidden: false, - index: 0, - points: 0, - start: 0, - end: 0, - group: 0, - icon: 0, - title: 0, - description: "", - tasks: [{ id: 0, total: 0, description: "", }], - data: "", - }, - TrophyProgression: { - player_id: 0, - task_id: 0, - count: 0, - time: 0, - }, - TrophyProgressionValue: { - count: 0, - time: 0, - }, - Task: { - id: 0, - total: 0, - description: "", - }, - } + achievement: { + TrophyCreation: { + id: 0, + hidden: false, + index: 0, + points: 0, + start: 0, + end: 0, + group: 0, + icon: 0, + title: 0, + description: "", + tasks: [{ id: 0, total: 0, description: "", }], + data: "", + }, + TrophyCreationValue: { + hidden: false, + index: 0, + points: 0, + start: 0, + end: 0, + group: 0, + icon: 0, + title: 0, + description: "", + tasks: [{ id: 0, total: 0, description: "", }], + data: "", + }, + TrophyProgression: { + player_id: 0, + task_id: 0, + count: 0, + time: 0, + }, + TrophyProgressionValue: { + count: 0, + time: 0, + }, + Task: { + id: 0, + total: 0, + description: "", + }, + } }; export enum ModelsMapping { Golem = 'golem_runner-Golem', GolemValue = 'golem_runner-GolemValue', + Mission = 'golem_runner-Mission', + MissionValue = 'golem_runner-MissionValue', Player = 'golem_runner-Player', PlayerValue = 'golem_runner-PlayerValue', Ranking = 'golem_runner-Ranking', RankingValue = 'golem_runner-RankingValue', World = 'golem_runner-World', WorldValue = 'golem_runner-WorldValue', + GolemType = 'golem_runner-GolemType', + MissionStatus = 'golem_runner-MissionStatus', Rarity = 'golem_runner-Rarity', + WorldType = 'golem_runner-WorldType', TrophyCreation = 'achievement-TrophyCreation', TrophyCreationValue = 'achievement-TrophyCreationValue', TrophyProgression = 'achievement-TrophyProgression', diff --git a/client/src/dojo/contracts.gen.ts b/client/src/dojo/contracts.gen.ts index 50cc685..b43e14f 100644 --- a/client/src/dojo/contracts.gen.ts +++ b/client/src/dojo/contracts.gen.ts @@ -1,8 +1,50 @@ import { DojoProvider, DojoCall } from "@dojoengine/core"; -import { Account, AccountInterface } from "starknet"; +import { Account, AccountInterface, CairoCustomEnum, ByteArray } from "starknet"; export function setupWorld(provider: DojoProvider) { + const build_game_createMission_calldata = (targetCoins: number, requiredWorld: CairoCustomEnum, requiredGolem: CairoCustomEnum, description: ByteArray): DojoCall => { + return { + contractName: "game", + entrypoint: "create_mission", + calldata: [targetCoins, requiredWorld, requiredGolem, description], + }; + }; + + const game_createMission = async (snAccount: Account | AccountInterface, targetCoins: number, requiredWorld: CairoCustomEnum, requiredGolem: CairoCustomEnum, description: ByteArray) => { + try { + return await provider.execute( + snAccount as any, + build_game_createMission_calldata(targetCoins, requiredWorld, requiredGolem, description), + "golem_runner", + ); + } catch (error) { + console.error(error); + throw error; + } + }; + + const build_game_rewardCurrentMission_calldata = (missionId: number, coinsCollected: number): DojoCall => { + return { + contractName: "game", + entrypoint: "reward_current_mission", + calldata: [missionId, coinsCollected], + }; + }; + + const game_rewardCurrentMission = async (snAccount: Account | AccountInterface, missionId: number, coinsCollected: number) => { + try { + return await provider.execute( + snAccount as any, + build_game_rewardCurrentMission_calldata(missionId, coinsCollected), + "golem_runner", + ); + } catch (error) { + console.error(error); + throw error; + } + }; + const build_game_rewardPlayer_calldata = (points: number, coinsCollected: number): DojoCall => { return { contractName: "game", @@ -108,6 +150,27 @@ export function setupWorld(provider: DojoProvider) { } }; + const build_game_updateMission_calldata = (missionId: number): DojoCall => { + return { + contractName: "game", + entrypoint: "update_mission", + calldata: [missionId], + }; + }; + + const game_updateMission = async (snAccount: Account | AccountInterface, missionId: number) => { + try { + return await provider.execute( + snAccount as any, + build_game_updateMission_calldata(missionId), + "golem_runner", + ); + } catch (error) { + console.error(error); + throw error; + } + }; + const build_game_updatePlayerDailyStreak_calldata = (): DojoCall => { return { contractName: "game", @@ -154,6 +217,10 @@ export function setupWorld(provider: DojoProvider) { return { game: { + createMission: game_createMission, + buildCreateMissionCalldata: build_game_createMission_calldata, + rewardCurrentMission: game_rewardCurrentMission, + buildRewardCurrentMissionCalldata: build_game_rewardCurrentMission_calldata, rewardPlayer: game_rewardPlayer, buildRewardPlayerCalldata: build_game_rewardPlayer_calldata, spawnPlayer: game_spawnPlayer, @@ -164,6 +231,8 @@ export function setupWorld(provider: DojoProvider) { buildUnlockWorldStoreCalldata: build_game_unlockWorldStore_calldata, updateGolemName: game_updateGolemName, buildUpdateGolemNameCalldata: build_game_updateGolemName_calldata, + updateMission: game_updateMission, + buildUpdateMissionCalldata: build_game_updateMission_calldata, updatePlayerDailyStreak: game_updatePlayerDailyStreak, buildUpdatePlayerDailyStreakCalldata: build_game_updatePlayerDailyStreak_calldata, updatePlayerRanking: game_updatePlayerRanking, diff --git a/contract/dojo_sepolia.toml b/contract/dojo_sepolia.toml index a80ef98..c4701d9 100644 --- a/contract/dojo_sepolia.toml +++ b/contract/dojo_sepolia.toml @@ -2,7 +2,7 @@ name = "Golem Runner" description = "Golem Runner is a mobile endless runner game where players control elemental golems. Built using Dojo Engine and Cartridge Controller on Starknet." website = "https://github.com/AkatsukiLabs/GolemRunner" -seed = "golem_runner6" +seed = "golem_runner7" [namespace] default = "golem_runner" diff --git a/contract/manifest_sepolia.json b/contract/manifest_sepolia.json index f63e4eb..61a785f 100644 --- a/contract/manifest_sepolia.json +++ b/contract/manifest_sepolia.json @@ -1,8 +1,8 @@ { "world": { "class_hash": "0x7c9469d45a9cdbab775035afb48e1fa73fb35ab059fcb9dfb0a301aa973e783", - "address": "0x1fe4f3da25325886ab8c89826d0af42385e36f2cdb717441532e3220d179da4", - "seed": "golem_runner6", + "address": "0x7c677ef29a276a115468ee7f53094720de5da6d443e6f1a2b7f4a6afb6f86b2", + "seed": "golem_runner7", "name": "Golem Runner", "entrypoints": [ "uuid", @@ -1312,8 +1312,8 @@ }, "contracts": [ { - "address": "0x681ea222117a7e68124fdb1dbbdee016a560fd453b846fb54bef34be325882d", - "class_hash": "0x3341e5d0066d25ab19de417dd772c05593d88063f6084b81b03841d4802d909", + "address": "0x36a518498c1d7de4106b8904f0878e1e7b78c73614001fba22eba0adca80387", + "class_hash": "0x75e15e84fe204faeaa58f91e626f7e4d0a8ca897763f28e0d96ffc1b0a52c2", "abi": [ { "type": "impl", @@ -1405,6 +1405,42 @@ } ] }, + { + "type": "enum", + "name": "golem_runner::types::world::WorldType", + "variants": [ + { + "name": "Forest", + "type": "()" + }, + { + "name": "Volcano", + "type": "()" + }, + { + "name": "Glacier", + "type": "()" + } + ] + }, + { + "type": "enum", + "name": "golem_runner::types::golem::GolemType", + "variants": [ + { + "name": "Fire", + "type": "()" + }, + { + "name": "Ice", + "type": "()" + }, + { + "name": "Stone", + "type": "()" + } + ] + }, { "type": "interface", "name": "golem_runner::systems::game::IGame", @@ -1502,6 +1538,62 @@ } ], "state_mutability": "external" + }, + { + "type": "function", + "name": "create_mission", + "inputs": [ + { + "name": "target_coins", + "type": "core::integer::u64" + }, + { + "name": "required_world", + "type": "golem_runner::types::world::WorldType" + }, + { + "name": "required_golem", + "type": "golem_runner::types::golem::GolemType" + }, + { + "name": "description", + "type": "core::byte_array::ByteArray" + } + ], + "outputs": [], + "state_mutability": "external" + }, + { + "type": "function", + "name": "update_mission", + "inputs": [ + { + "name": "mission_id", + "type": "core::integer::u256" + } + ], + "outputs": [ + { + "type": "core::bool" + } + ], + "state_mutability": "external" + }, + { + "type": "function", + "name": "reward_current_mission", + "inputs": [ + { + "name": "mission_id", + "type": "core::integer::u256" + }, + { + "name": "coins_collected", + "type": "core::integer::u64" + } + ], + "outputs": [], + "state_mutability": "external" } ] }, @@ -1636,6 +1728,9 @@ "update_golem_name", "unlock_golem_store", "unlock_world_store", + "create_mission", + "update_mission", + "reward_current_mission", "upgrade" ] } @@ -1648,6 +1743,12 @@ "tag": "golem_runner-Golem", "selector": "0x5a1af4923c31f36a9a9b5cd3f717dac8c55c1e6a26e92a0e4f28d30754166db" }, + { + "members": [], + "class_hash": "0x2d620c3d3bc76ab5016d9707bcc9ca995ee446492cb26fc41744600d04ecf0f", + "tag": "golem_runner-Mission", + "selector": "0x53894aba2c90ef9aeb7f37e5690c7f994547a79dcce91e9f2f098baa85587a" + }, { "members": [], "class_hash": "0x3f2287ca0736b645e3c9b3b4a09d1b15c1637debf3ccfbfd180aafe43f75d27", diff --git a/contract/torii_config.toml b/contract/torii_config.toml index e3156e9..4af7dcf 100644 --- a/contract/torii_config.toml +++ b/contract/torii_config.toml @@ -1,5 +1,5 @@ # The World address to index. -world_address = "0x01fe4f3da25325886ab8c89826d0af42385e36f2cdb717441532e3220d179da4" +world_address = "0x07c677ef29a276a115468ee7f53094720de5da6d443e6f1a2b7f4a6afb6f86b2" # Default RPC URL configuration rpc = "https://api.cartridge.gg/x/starknet/sepolia"