-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
new onboarding flow #2672
Merged
Merged
new onboarding flow #2672
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
bc2104b
start new onboarding
aymericdelab 9a06513
show random realm hex view if not connected
aymericdelab 95e6b26
fix issues
aymericdelab 0f9e239
add new no account modal
aymericdelab f57f342
add no account modal and not logged in message
aymericdelab 322c62c
need input to be > 0
aymericdelab fc133a2
enable all modules
aymericdelab 80e2fbe
add account required on confirm popup
aymericdelab 5c670cf
refactor for system call callback
aymericdelab e13a34b
refactor + remove console.log
aymericdelab 373320a
remove console.log
aymericdelab b1e1b29
rabbit comments
aymericdelab 0ad45fc
address comment
aymericdelab b9e800f
knip
aymericdelab File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,3 +26,4 @@ yarn.lock | |
dev-dist | ||
.env | ||
.env.local | ||
*.ts.timestamp-*.mjs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
client/apps/game/src/hooks/helpers/use-navigate-to-realm-view-by-account.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { Position } from "@/types/position"; | ||
import { getPlayerFirstRealm, getRandomRealmEntity } from "@/utils/realms"; | ||
import { ClientComponents, ContractAddress } from "@bibliothecadao/eternum"; | ||
import { getComponentValue } from "@dojoengine/recs"; | ||
import { useAccount } from "@starknet-react/core"; | ||
import { useEffect } from "react"; | ||
import { NULL_ACCOUNT } from "../context/dojo-context"; | ||
import { useNavigateToHexView } from "./use-navigate"; | ||
|
||
export const useNavigateToRealmViewByAccount = (components: ClientComponents) => { | ||
const navigateToHexView = useNavigateToHexView(); | ||
const { account } = useAccount(); | ||
|
||
// navigate to random hex view if not connected or to player's first realm if connected | ||
useEffect(() => { | ||
if (!account) { | ||
const randomRealmEntity = getRandomRealmEntity(components); | ||
const position = randomRealmEntity ? getComponentValue(components.Position, randomRealmEntity) : undefined; | ||
navigateToHexView(new Position(position || { x: 0, y: 0 })); | ||
} else { | ||
const playerRealm = getPlayerFirstRealm(components, ContractAddress(account?.address || NULL_ACCOUNT.address)); | ||
const position = playerRealm ? getComponentValue(components.Position, playerRealm) : undefined; | ||
position && navigateToHexView(new Position(position)); | ||
} | ||
}, [account?.address]); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { Position } from "@/types/position"; | ||
import { useQuery } from "@bibliothecadao/react"; | ||
import { useUIStore } from "../store/use-ui-store"; | ||
|
||
export const useNavigateToHexView = () => { | ||
const showBlankOverlay = useUIStore((state) => state.setShowBlankOverlay); | ||
const setIsLoadingScreenEnabled = useUIStore((state) => state.setIsLoadingScreenEnabled); | ||
const setPreviewBuilding = useUIStore((state) => state.setPreviewBuilding); | ||
const { handleUrlChange } = useQuery(); | ||
|
||
return (position: Position) => { | ||
const url = position.toHexLocationUrl(); | ||
|
||
setIsLoadingScreenEnabled(true); | ||
showBlankOverlay(false); | ||
setPreviewBuilding(null); | ||
handleUrlChange(url); | ||
}; | ||
}; | ||
|
||
export const useNavigateToMapView = () => { | ||
const showBlankOverlay = useUIStore((state) => state.setShowBlankOverlay); | ||
const setPreviewBuilding = useUIStore((state) => state.setPreviewBuilding); | ||
const { handleUrlChange, isMapView } = useQuery(); | ||
const setIsLoadingScreenEnabled = useUIStore((state) => state.setIsLoadingScreenEnabled); | ||
|
||
return (position: Position) => { | ||
if (!isMapView) { | ||
setIsLoadingScreenEnabled(true); | ||
} | ||
showBlankOverlay(false); | ||
setPreviewBuilding(null); | ||
handleUrlChange(position.toMapLocationUrl()); | ||
}; | ||
}; |
38 changes: 9 additions & 29 deletions
38
client/apps/game/src/hooks/helpers/use-structure-entity-id.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,33 @@ | ||
import { useUIStore } from "@/hooks/store/use-ui-store"; | ||
import { Position as PositionInterface } from "@/types/position"; | ||
import { UNDEFINED_STRUCTURE_ENTITY_ID } from "@/ui/constants"; | ||
import { ContractAddress } from "@bibliothecadao/eternum"; | ||
import { useDojo, usePlayerStructures, useQuery } from "@bibliothecadao/react"; | ||
import { useDojo, useQuery } from "@bibliothecadao/react"; | ||
import { Entity, Has, HasValue, getComponentValue, runQuery } from "@dojoengine/recs"; | ||
import { useEffect, useMemo } from "react"; | ||
import { useEffect } from "react"; | ||
|
||
export const useStructureEntityId = () => { | ||
const { | ||
setup: { | ||
components: { Structure, Position, Owner }, | ||
components: { Structure, Position }, | ||
}, | ||
account: { account }, | ||
} = useDojo(); | ||
|
||
const { hexPosition, isMapView } = useQuery(); | ||
const { hexPosition } = useQuery(); | ||
const setStructureEntityId = useUIStore((state) => state.setStructureEntityId); | ||
const isSpectatorMode = useUIStore((state) => state.isSpectatorMode); | ||
const structureEntityId = useUIStore((state) => state.structureEntityId); | ||
|
||
const address = isSpectatorMode ? ContractAddress("0x0") : ContractAddress(account.address); | ||
|
||
const structures = usePlayerStructures(ContractAddress(account.address)); | ||
|
||
const defaultPlayerStructure = useMemo(() => { | ||
return structures[0]; | ||
}, [structureEntityId, structures]); | ||
|
||
useEffect(() => { | ||
const { x, y } = new PositionInterface({ | ||
const position = new PositionInterface({ | ||
x: hexPosition.col, | ||
y: hexPosition.row, | ||
}).getContract(); | ||
|
||
const structureEntity = runQuery([Has(Structure), HasValue(Position, { x, y })]) | ||
const structureEntity = runQuery([Has(Structure), HasValue(Position, { x: position.x, y: position.y })]) | ||
.values() | ||
.next().value; | ||
|
||
const structure = getComponentValue(Structure, structureEntity ?? ("0" as Entity)); | ||
aymericdelab marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const structureOwner = getComponentValue(Owner, structureEntity ?? ("0" as Entity)); | ||
|
||
const isOwner = structureOwner?.address === BigInt(address); | ||
const newStructureId = structure?.entity_id; | ||
|
||
if (isMapView) { | ||
setStructureEntityId( | ||
isOwner ? structureOwner.entity_id : defaultPlayerStructure?.entity_id || UNDEFINED_STRUCTURE_ENTITY_ID, | ||
); | ||
} else { | ||
setStructureEntityId(structure?.entity_id || UNDEFINED_STRUCTURE_ENTITY_ID); | ||
} | ||
}, [defaultPlayerStructure, isMapView, hexPosition, address]); | ||
setStructureEntityId(newStructureId || UNDEFINED_STRUCTURE_ENTITY_ID); | ||
}, [hexPosition]); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implement the navigateToHexView function.
The spectator mode click handler relies on an unimplemented navigation function, which will throw an error when used.
Consider implementing the navigation function or using an existing navigation utility from your codebase. The function should handle the Position type and navigate to the appropriate hex view.
Also applies to: 252-254