Skip to content

Commit

Permalink
Feat/improvements (#287)
Browse files Browse the repository at this point in the history
- add graphql schema fix
- remove travel log
- hide play pages if no adventurer selected
- add cartridge as client reward
- handle optimistic updates from equipping and purchasing
- hide expired games by default
  • Loading branch information
starknetdev authored Jan 13, 2025
1 parent e5b80c5 commit 9f6cb40
Show file tree
Hide file tree
Showing 19 changed files with 1,009 additions and 710 deletions.
43 changes: 25 additions & 18 deletions indexer/graphql/src/indexer/graphql.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import asyncio
from typing import List, NewType, Optional, Dict, Union, Any
import ssl
import hashlib
import json
import logging
import hashlib
import ssl
from typing import Any, Dict, List, NewType, Optional, Union

import strawberry
import aiohttp_cors
from aiohttp import web
import aioredis
import strawberry
from aiohttp import web
from indexer.config import Config
from indexer.utils import get_key_by_value
from pymongo import MongoClient
from strawberry.aiohttp.views import GraphQLView
from indexer.utils import get_key_by_value
from indexer.config import Config
from strawberry.types import Info

config = Config()
Expand Down Expand Up @@ -1074,14 +1074,14 @@ class AdventurersFilter:
ring: Optional[FeltValueFilter] = None
beastHealth: Optional[FeltValueFilter] = None
statUpgrades: Optional[FeltValueFilter] = None
birthDate: Optional[OrderByInput] = None
deathDate: Optional[OrderByInput] = None
goldenTokenId: Optional[OrderByInput] = None
launchTournamentWinnerTokenId: Optional[OrderByInput] = None
customRenderer: Optional[OrderByInput] = None
battleActionCount: Optional[OrderByInput] = None
birthDate: Optional[FeltValueFilter] = None
deathDate: Optional[FeltValueFilter] = None
goldenTokenId: Optional[FeltValueFilter] = None
launchTournamentWinnerTokenId: Optional[FeltValueFilter] = None
customRenderer: Optional[HexValueFilter] = None
battleActionCount: Optional[FeltValueFilter] = None
gold: Optional[FeltValueFilter] = None
createdTime: Optional[OrderByInput] = None
createdTime: Optional[DateTimeFilter] = None
lastUpdatedTime: Optional[DateTimeFilter] = None
timestamp: Optional[DateTimeFilter] = None

Expand Down Expand Up @@ -1908,8 +1908,8 @@ class Adventurer:
ring: Optional[ItemValue]
beastHealth: Optional[FeltValue]
statUpgrades: Optional[FeltValue]
birthDate: Optional[str]
deathDate: Optional[str]
birthDate: Optional[FeltValue]
deathDate: Optional[FeltValue]
goldenTokenId: Optional[FeltValue]
launchTournamentWinnerTokenId: Optional[FeltValue]
customRenderer: Optional[FeltValue]
Expand Down Expand Up @@ -3333,7 +3333,7 @@ async def count_adventurers_with_zero_health(info) -> int:


async def count_adventurers_with_positive_health(
info, owner: Optional[HexValue] = None
info, owner: Optional[HexValue] = None, birthDate: Optional[FeltValue] = None
) -> int:
redis = info.context["redis"]

Expand All @@ -3343,6 +3343,13 @@ async def count_adventurers_with_positive_health(
if owner:
filter["owner"] = {"$eq": owner}

# Add birthDate to the filter if provided
if birthDate:
filter["birthDate"] = {"$gt": birthDate}

# Add health filter
filter["health"] = {"$gt": 0}

cache_key = f"count_adventurers_with_positive_health:{json.dumps(filter)}"

# Check if the result is in the cache
Expand All @@ -3352,7 +3359,7 @@ async def count_adventurers_with_positive_health(

# If not in cache, query the database
db = info.context["db"]
count = db["adventurers"].count_documents({**filter, "health": {"$gt": 0}})
count = db["adventurers"].count_documents(filter)

# Store the result in the cache
await redis.set(cache_key, count, ex=60) # Set an expiration time of 60 seconds
Expand Down
29 changes: 26 additions & 3 deletions ui/src/app/components/encounters/EncounterTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ import { listAllEncounters } from "@/app/lib/utils/processFutures";
import { Item } from "@/app/types";
import React, { useMemo, useState } from "react";
import Paths from "./Paths";
import { getPurchaseItemsObjects, getUpdatedAdventurer } from "./utils";
import {
getEquippedItemsObjects,
getPurchaseItemsObjects,
getUpdatedAdventurer,
} from "./utils";

const EncounterTable = () => {
const adventurer = useAdventurerStore((state) => state.adventurer);
Expand All @@ -38,21 +42,40 @@ const EncounterTable = () => {
const upgrades = useUIStore((state) => state.upgrades);
const potionAmount = useUIStore((state) => state.potionAmount);
const purchaseItems = useUIStore((state) => state.purchaseItems);
const equipItems = useUIStore((state) => state.equipItems);

const purchaseItemsObjects = useMemo(
() => getPurchaseItemsObjects(purchaseItems, gameData),
[purchaseItems]
);

const equippedItemsObjects = useMemo(
() =>
getEquippedItemsObjects(
equipItems,
gameData,
data.itemsByAdventurerQuery?.items!
),
[equipItems, data.itemsByAdventurerQuery?.items]
);

const updatedAdventurer = useMemo(
() =>
getUpdatedAdventurer(
adventurer,
upgrades,
potionAmount,
purchaseItemsObjects
purchaseItemsObjects,
equippedItemsObjects,
data.itemsByAdventurerQuery?.items!
),
[adventurer, upgrades, potionAmount, purchaseItemsObjects]
[
adventurer,
upgrades,
potionAmount,
purchaseItemsObjects,
equippedItemsObjects,
]
);

let armoritems: Item[] =
Expand Down
25 changes: 22 additions & 3 deletions ui/src/app/components/encounters/Paths.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { Step } from "@/app/lib/utils/processFutures";
import { Item } from "@/app/types";
import React, { useEffect, useMemo, useState } from "react";
import {
getEquippedItemsObjects,
getItems,
getPaths,
getPurchaseItemsObjects,
Expand All @@ -32,6 +33,7 @@ const Paths = () => {
const upgrades = useUIStore((state) => state.upgrades);
const potionAmount = useUIStore((state) => state.potionAmount);
const purchaseItems = useUIStore((state) => state.purchaseItems);
const equipItems = useUIStore((state) => state.equipItems);

const [selectedBeastEncounter, setSelectedBeastEncounter] =
useState<Step | null>(null);
Expand All @@ -54,6 +56,16 @@ const Paths = () => {
return item.slot! === "Weapon";
}) || [];

const equippedItemsObjects = useMemo(
() =>
getEquippedItemsObjects(
equipItems,
gameData,
data.itemsByAdventurerQuery?.items!
),
[equipItems]
);

const purchaseItemsObjects = useMemo(
() => getPurchaseItemsObjects(purchaseItems, gameData),
[purchaseItems]
Expand All @@ -65,7 +77,9 @@ const Paths = () => {
adventurer,
upgrades,
potionAmount,
purchaseItemsObjects
purchaseItemsObjects,
equippedItemsObjects,
data.itemsByAdventurerQuery?.items!
),
[
adventurer,
Expand All @@ -77,12 +91,17 @@ const Paths = () => {
upgrades.Vitality,
potionAmount,
purchaseItemsObjects,
equippedItemsObjects,
]
);

const items = useMemo(
() => getItems(purchaseItems, data, gameData),
[data.itemsByAdventurerQuery?.items, purchaseItemsObjects]
() => getItems(equipItems, purchaseItems, data, gameData),
[
data.itemsByAdventurerQuery?.items,
purchaseItemsObjects,
equippedItemsObjects,
]
);

const outcomesWithPath = useMemo(
Expand Down
Loading

0 comments on commit 9f6cb40

Please sign in to comment.