Skip to content
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

Next into season 1 #2647

Merged
merged 29 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
5fca84b
contracts & client: increase resource precision from 3 to 9 (#2625)
credence0x Jan 7, 2025
06c9e22
Merge branch 'season-1' of https://github.com/BibliothecaDAO/eternum …
credence0x Jan 7, 2025
1a48f2f
update contracts folder structure (#2626)
credence0x Jan 7, 2025
2e99610
Merge branch 'next' of https://github.com/BibliothecaDAO/eternum into…
credence0x Jan 9, 2025
5803a40
Merge branch 'next' of https://github.com/BibliothecaDAO/eternum into…
credence0x Jan 10, 2025
a9bffe8
new production (#2629)
credence0x Jan 16, 2025
c610451
Merge branch 'next' into next-into-season-1
aymericdelab Jan 18, 2025
e4e8f8b
fix build
aymericdelab Jan 18, 2025
ddb62bf
fix build
aymericdelab Jan 19, 2025
8a24dda
fix build
aymericdelab Jan 19, 2025
84c0a45
fix
aymericdelab Jan 19, 2025
e2c694b
fix build
aymericdelab Jan 19, 2025
0d4e6f8
Merge branch 'next' into next-into-season-1
aymericdelab Jan 19, 2025
4718c4c
fix build
aymericdelab Jan 19, 2025
4fd331c
fix
aymericdelab Jan 19, 2025
94a376b
knip clean
aymericdelab Jan 20, 2025
9b9c4de
Move config folder to root
bob0005 Jan 20, 2025
5abea52
- Move game/assets to public folder
bob0005 Jan 20, 2025
1742288
Merge branch 'next-into-season-1' of https://github.com/BibliothecaDA…
bob0005 Jan 20, 2025
cbeff22
fix env and deploy
aymericdelab Jan 20, 2025
6b05341
clean env
aymericdelab Jan 20, 2025
8af9607
remove burner
aymericdelab Jan 20, 2025
ad2f9f4
update contracts
aymericdelab Jan 20, 2025
8f43edc
prepare landing
aymericdelab Jan 20, 2025
282a116
Merge branch 'deploy' into next-into-season-1
aymericdelab Jan 20, 2025
57521f3
pnpm lock
aymericdelab Jan 20, 2025
f9d9055
contracts:scripts:fix torii pid
credence0x Jan 21, 2025
95cf687
update erc721 and erc20 in torii toml in between deploys
credence0x Jan 21, 2025
f47aaad
formatting
bob0005 Jan 21, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
8 changes: 4 additions & 4 deletions .github/workflows/discord-bot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- name: Checkout code
uses: actions/checkout@v4
with:
sparse-checkout: discord-bot
sparse-checkout: bot/discord

- name: Install Rust
uses: actions-rs/toolchain@v1
Expand All @@ -32,7 +32,7 @@ jobs:
components: rustfmt

- name: Run rustfmt
run: cd discord-bot && cargo fmt -- --check
run: cd bot/discord && cargo fmt -- --check

clippy:
runs-on: ubuntu-latest
Expand All @@ -41,7 +41,7 @@ jobs:
- name: Checkout code
uses: actions/checkout@v4
with:
sparse-checkout: discord-bot
sparse-checkout: bot/discord

- name: Install Rust
uses: actions-rs/toolchain@v1
Expand All @@ -54,4 +54,4 @@ jobs:
run: sudo apt-get install protobuf-compiler

- name: Run clippy
run: cd discord-bot && cargo clippy -- -D warnings
run: cd bot/discord && cargo clippy -- -D warnings
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl<'a> TickSender<'a> {
Some(Felt::from_hex(TICK_ARMIES_ID).unwrap()),
],
pattern_matching: PatternMatching::FixedLen,
models: vec!["s0_eternum-TickConfig".to_string()],
models: vec!["s1_eternum-TickConfig".to_string()],
})),
limit: 1,
offset: 0,
Expand All @@ -61,7 +61,7 @@ impl<'a> TickSender<'a> {
let tick_interval_in_seconds = entity
.models
.iter()
.find(|model| model.name == "s0_eternum-TickConfig")
.find(|model| model.name == "s1_eternum-TickConfig")
.expect("Tick interval in seconds not found")
.children
.iter()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ use crate::{
};

const TORII_SUBSCRIPTION_MODELS: [&str; 9] = [
"s0_eternum-BattleClaimData",
"s0_eternum-BattleJoinData",
"s0_eternum-BattleLeaveData",
"s0_eternum-BattlePillageData",
"s0_eternum-BattleStartData",
"s0_eternum-SettleRealmData",
"s0_eternum-GameEnded",
"s0_eternum-HyperstructureFinished",
"s0_eternum-HyperstructureStarted",
"s1_eternum-BattleClaimData",
"s1_eternum-BattleJoinData",
"s1_eternum-BattleLeaveData",
"s1_eternum-BattlePillageData",
"s1_eternum-BattleStartData",
"s1_eternum-SettleRealmData",
"s1_eternum-GameEnded",
"s1_eternum-HyperstructureFinished",
"s1_eternum-HyperstructureStarted",
];

pub struct ToriiClientSubscriber {
Expand Down Expand Up @@ -125,64 +125,64 @@ impl ToriiClientSubscriber {
let felts = ty.serialize().unwrap();

let event = match model.name.as_str() {
"s0_eternum-BattleStartData" => {
"s1_eternum-BattleStartData" => {
let event = BattleStart::cairo_deserialize(&felts, 0).unwrap();
Event {
event: Box::new(event),
identifier: event.defender,
}
}
"s0_eternum-BattleJoinData" => {
"s1_eternum-BattleJoinData" => {
let event = BattleJoin::cairo_deserialize(&felts, 0).unwrap();
Event {
event: Box::new(event),
identifier: event.joiner,
}
}
"s0_eternum-BattleLeaveData" => {
"s1_eternum-BattleLeaveData" => {
let event = BattleLeave::cairo_deserialize(&felts, 0).unwrap();
Event {
event: Box::new(event),
identifier: event.leaver,
}
}
"s0_eternum-BattleClaimData" => {
"s1_eternum-BattleClaimData" => {
let event = BattleClaim::cairo_deserialize(&felts, 0).unwrap();
Event {
event: Box::new(event),
identifier: event.claimee_address,
}
}
"s0_eternum-BattlePillageData" => {
"s1_eternum-BattlePillageData" => {
let event = BattlePillage::cairo_deserialize(&felts, 0).unwrap();
let event_clone = event.clone();
Event {
event: Box::new(event_clone),
identifier: event.pillaged_structure_owner,
}
}
"s0_eternum-SettleRealmData" => {
"s1_eternum-SettleRealmData" => {
let event = SettleRealm::cairo_deserialize(&felts, 0).unwrap();
Event {
event: Box::new(event),
identifier: event.owner_address,
}
}
"s0_eternum-GameEnded" => {
"s1_eternum-GameEnded" => {
let event = GameEnded::cairo_deserialize(&felts, 0).unwrap();
Event {
event: Box::new(event),
identifier: event.winner_address,
}
}
"s0_eternum-HyperstructureFinished" => {
"s1_eternum-HyperstructureFinished" => {
let event = HyperstructureFinished::cairo_deserialize(&felts, 0).unwrap();
Event {
event: Box::new(event),
identifier: event.hyperstructure_owner_name,
}
}
"s0_eternum-HyperstructureStarted" => {
"s1_eternum-HyperstructureStarted" => {
let event = HyperstructureStarted::cairo_deserialize(&felts, 0).unwrap();
Event {
event: Box::new(event),
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,16 @@ pub enum ResourceIds {
#[strum(serialize = "Ethereal Silica")]
EtherealSilica = 21,
Dragonhide = 22,
Demonhide = 23,
#[strum(serialize = "Ancient Fragment")]
AncientFragment = 29,
Donkey = 249,
Knight = 250,
Crossbowman = 251,
Paladin = 252,
Lords = 253,
Wheat = 254,
Fish = 255,
AncientFragment = 24,
Donkey = 25,
Knight = 26,
Crossbowman = 27,
Paladin = 28,
Wheat = 29,
Fish = 30,
Lords = 31,
}

#[derive(FromPrimitive, Debug, Clone, Copy, strum_macros::Display)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use crate::{

use super::{ToDiscordMessage, UNKNOWN_USER};

const RESOURCE_PRECISION: u128 = 1_000_000_000;
#[derive(CairoSerde, Clone)]
pub struct BattlePillage {
pub id: u32,
Expand Down Expand Up @@ -42,7 +43,7 @@ impl ToDiscordMessage for BattlePillage {
.pillaged_resources
.iter()
.map(|(resource_id, amount)| {
format!("{} {}", amount / 1000, ResourceIds::from(*resource_id),)
format!("{} {}", amount / RESOURCE_PRECISION, ResourceIds::from(*resource_id),)
})
Comment on lines 43 to 47
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix formatting according to rustfmt standards.

The format! macro needs to be split across multiple lines.

-                format!("{} {}", amount / RESOURCE_PRECISION, ResourceIds::from(*resource_id),)
+                format!(
+                    "{} {}",
+                    amount / RESOURCE_PRECISION,
+                    ResourceIds::from(*resource_id),
+                )
πŸ“ Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
.pillaged_resources
.iter()
.map(|(resource_id, amount)| {
format!("{} {}", amount / 1000, ResourceIds::from(*resource_id),)
format!("{} {}", amount / RESOURCE_PRECISION, ResourceIds::from(*resource_id),)
})
.pillaged_resources
.iter()
.map(|(resource_id, amount)| {
format!(
"{} {}",
amount / RESOURCE_PRECISION,
ResourceIds::from(*resource_id),
)
})
🧰 Tools
πŸͺ› GitHub Actions: discord-bot

[error] 43-47: Code formatting does not match rustfmt style. The format! macro call needs to be split across multiple lines according to rustfmt standards.

.collect::<Vec<String>>()
.join(", ");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use super::{duration_to_string, ToDiscordMessage, UNKNOWN_USER};

// abigen!(
// _unused,
// "../contracts/target/dev/s0_eternum_e_BattleStartData.contract_class.json",
// "../contracts/target/dev/s1_eternum_e_BattleStartData.contract_class.json",
// );
// TODO have a build.rs that can load the abis of the types we care about and writes them to a file
// Dojo world can load local world from manifests and retrieve the abi
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
26 changes: 13 additions & 13 deletions client/apps/balancing/src/components/modules/resource-table.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table";
import {
BUILDING_COSTS_SCALED,
RESOURCE_BUILDING_COSTS,
RESOURCE_INPUTS_SCALED,
RESOURCE_OUTPUTS,
RESOURCE_RARITY,
RESOURCE_TIERS,
Resources,
WEIGHTS_GRAM,
BUILDING_COSTS_SCALED,
RESOURCE_BUILDING_COSTS,
RESOURCE_PRODUCTION_INPUT_RESOURCES_SCALED,
RESOURCE_PRODUCTION_OUTPUT_AMOUNTS,
RESOURCE_RARITY,
RESOURCE_TIERS,
Resources,
WEIGHTS_GRAM,
} from "@bibliothecadao/eternum";
import { Badge } from "../ui/badge";

Expand Down Expand Up @@ -46,16 +46,16 @@ export const ResourceTable = ({ resources }: { resources: Resources[] }) => {
const multiplier = RESOURCE_RARITY[resourceId as keyof typeof RESOURCE_RARITY] || 1; // Default multiplier is 1

return (
RESOURCE_INPUTS_SCALED[resourceId]?.map((input) => ({
RESOURCE_PRODUCTION_INPUT_RESOURCES_SCALED[resourceId]?.map((input) => ({
...input,
adjustedAmount: input.amount * multiplier,
})) || []
);
};
// Sum up how many times each resource is used as an input based on RESOURCE_INPUTS_SCALED and BUILDING_COSTS_SCALED
// Sum up how many times each resource is used as an input based on RESOURCE_PRODUCTION_INPUT_RESOURCES_SCALED and BUILDING_COSTS_SCALED
const resourceUsageCount = resources.reduce(
(acc, resource) => {
const inputUsageCount = Object.values(RESOURCE_INPUTS_SCALED).reduce((count, inputs) => {
const inputUsageCount = Object.values(RESOURCE_PRODUCTION_INPUT_RESOURCES_SCALED).reduce((count, inputs) => {
return count + inputs.filter((input: any) => input.resource === resource.id).length;
}, 0);
const buildingUsageCount = Object.values(BUILDING_COSTS_SCALED).reduce((count, costs) => {
Expand Down Expand Up @@ -125,7 +125,7 @@ export const ResourceTable = ({ resources }: { resources: Resources[] }) => {
<TableCell className="text-center">{getResourceTier(resource.id)}</TableCell>
<TableCell className="text-center">{getResourceWeight(resource.id)}</TableCell>
<TableCell className="rounded flex gap-2 justify-center">
{RESOURCE_INPUTS_SCALED[resource.id]?.map((input, idx) => (
{RESOURCE_PRODUCTION_INPUT_RESOURCES_SCALED[resource.id]?.map((input, idx) => (
<Badge className="border p-1" key={idx} style={{ borderColor: resourceColor(input.resource) }}>
<img src={getResourceImage(input.resource)} alt={resource.trait} className="w-6 h-6 mx-auto" /> x{" "}
{input.amount}
Expand All @@ -135,7 +135,7 @@ export const ResourceTable = ({ resources }: { resources: Resources[] }) => {
<TableCell className="text-center">
{sumAdjustedInputs(resource.id)} [{adjustedDemand[resource.id].toFixed(2)}]
</TableCell>
<TableCell className="text-center">{RESOURCE_OUTPUTS[resource.id]}</TableCell>
<TableCell className="text-center">{RESOURCE_PRODUCTION_OUTPUT_AMOUNTS[resource.id]}</TableCell>

<TableCell className="text-center">{resourceUsageCount[resource.id]}</TableCell>
<TableCell className="rounded flex gap-2 justify-center">
Expand Down
11 changes: 6 additions & 5 deletions client/apps/game-docs/docs/components/BuildingCosts.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { BuildingType, EternumGlobalConfig, findResourceById, ResourcesIds } from "@bibliothecadao/eternum";
import ResourceIcon from "./ResourceIcon";
import { BuildingType, configManager, findResourceById, ResourcesIds } from "@bibliothecadao/eternum";
import React from "react";
import { formatAmount } from "../utils/formatting";
import ResourceIcon from "./ResourceIcon";

type Props = {
buildingType: BuildingType;
};

export default function BuildingCosts({ buildingType }: Props) {
const costs = EternumGlobalConfig.buildings.buildingCosts[buildingType] || [];
const resourceCostsWheat = EternumGlobalConfig.resources.resourceBuildingCosts[ResourcesIds.Wood] || [];
const resourceCostsFish = EternumGlobalConfig.resources.resourceBuildingCosts[ResourcesIds.Stone] || [];
const costs = configManager.buildingCosts[buildingType] || [];
const resourceCostsWheat = configManager.resourceBuildingCosts[ResourcesIds.Wood] || [];
const resourceCostsFish = configManager.resourceBuildingCosts[ResourcesIds.Stone] || [];

if (buildingType === BuildingType.Resource) {
return (
Expand Down
6 changes: 3 additions & 3 deletions client/apps/game-docs/docs/components/QuestRewards.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { EternumGlobalConfig, QuestType, findResourceById } from "@bibliothecadao/eternum";
import { QuestType, findResourceById } from "@bibliothecadao/eternum";
import { addSpacesBeforeCapitals, formatAmount } from "../utils/formatting";
import ResourceIcon from "./ResourceIcon";
import { formatAmount, addSpacesBeforeCapitals } from "../utils/formatting";

export default function QuestRewards() {
return (
<div className="grid grid-cols-1 gap-6">
{Object.entries(EternumGlobalConfig.questResources).map(([questType, rewards]) => (
{Object.entries(ETERNUM_CONFIG().questResources).map(([questType, rewards]) => (
<div key={questType} className="p-4 rounded-lg border border-gray-200 dark:border-gray-700 bg-white/5">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

πŸ› οΈ Refactor suggestion

Optimize config access to prevent unnecessary re-renders.

Calling ETERNUM_CONFIG() directly in the render method could cause performance issues as it will be called on every render.

Consider using React's useMemo or useEffect to cache the config:

export default function QuestRewards() {
+  const [questResources, setQuestResources] = React.useState({});
+
+  React.useEffect(() => {
+    const loadConfig = async () => {
+      const config = await ETERNUM_CONFIG();
+      setQuestResources(config.questResources);
+    };
+    loadConfig();
+  }, []);
+
  return (
    <div className="grid grid-cols-1 gap-6">
-      {Object.entries(ETERNUM_CONFIG().questResources).map(([questType, rewards]) => (
+      {Object.entries(questResources).map(([questType, rewards]) => (

Committable suggestion skipped: line range outside the PR's diff.

<div className="font-bold text-lg mb-4">
{addSpacesBeforeCapitals(QuestType[Number(questType)] || "Unknown Quest")}
Expand Down
17 changes: 8 additions & 9 deletions client/apps/game-docs/docs/components/ResourceTable.tsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
import {
EternumGlobalConfig,
findResourceById,
RESOURCE_INPUTS,
RESOURCE_OUTPUTS,
ResourcesIds,
findResourceById,
RESOURCE_PRODUCTION_INPUT_RESOURCES,
RESOURCE_PRODUCTION_OUTPUT_AMOUNTS,
ResourcesIds
} from "@bibliothecadao/eternum";
import { useMemo } from "react";
import ResourceIcon from "./ResourceIcon";

export default function ResourceTable() {
const resourceTable = useMemo(() => {
const resources = [];
for (const resourceId of Object.keys(RESOURCE_INPUTS) as unknown as ResourcesIds[]) {
for (const resourceId of Object.keys(RESOURCE_PRODUCTION_INPUT_RESOURCES) as unknown as ResourcesIds[]) {
if (resourceId === ResourcesIds.Lords) continue;
const calldata = {
resource: findResourceById(Number(resourceId)),
amount: RESOURCE_OUTPUTS[resourceId],
amount: RESOURCE_PRODUCTION_OUTPUT_AMOUNTS[resourceId],
resource_type: resourceId,
cost: RESOURCE_INPUTS[resourceId].map((cost: any) => ({
cost: RESOURCE_PRODUCTION_INPUT_RESOURCES[resourceId].map((cost: any) => ({
...cost,
amount: cost.amount * EternumGlobalConfig.resources.resourcePrecision,
amount: cost.amount * ETERNUM_CONFIG().resources.resourcePrecision,
name: findResourceById(cost.resource)?.trait || "",
})),
};
Expand Down
13 changes: 6 additions & 7 deletions client/apps/game-docs/docs/components/TroopsTable.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import {
EternumGlobalConfig,
ResourcesIds,
TROOPS_FOOD_CONSUMPTION,
TROOPS_STAMINAS,
findResourceById,
ResourcesIds,
TROOPS_FOOD_CONSUMPTION,
TROOPS_STAMINAS,
findResourceById
} from "@bibliothecadao/eternum";
import { formatAmount, formatNumberWithSpaces } from "../utils/formatting";
import ResourceIcon from "./ResourceIcon";
Expand Down Expand Up @@ -67,12 +66,12 @@ export default function TroopsTable() {
<div className="grid grid-cols-3 gap-2">
<div className="text-left">
<div>Travel</div>
<div className="text-gray-400">{formatNumberWithSpaces(EternumGlobalConfig.stamina.travelCost)}</div>
<div className="text-gray-400">{formatNumberWithSpaces(ETERNUM_CONFIG().stamina.travelCost)}</div>
</div>

<div className="text-left">
<div>Explore</div>
<div className="text-gray-400">{formatNumberWithSpaces(EternumGlobalConfig.stamina.exploreCost)}</div>
<div className="text-gray-400">{formatNumberWithSpaces(ETERNUM_CONFIG().stamina.exploreCost)}</div>
</div>

<div className="flex justify-center items-center mt-4">
Expand Down
12 changes: 6 additions & 6 deletions client/apps/game-docs/docs/pages/development/contracts.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,17 @@ Things to note:
trait IBuildingContract<TContractState> {
fn create(
entity_id: ID,
building_coord: s0_eternum::models::position::Coord,
building_category: s0_eternum::models::buildings::BuildingCategory,
building_coord: s1_eternum::models::position::Coord,
building_category: s1_eternum::models::resource::production::building::BuildingCategory,
produce_resource_type: Option<u8>
);
}

#[dojo::contract]
mod building_systems {
use s0_eternum::alias::ID;
use s0_eternum::models::{
resources::{Resource, ResourceCost}, owner::Owner, hyperstructure::HyperStructure,
mod production_systems {
use s1_eternum::alias::ID;
use s1_eternum::models::{
resource::resource::{Resource, ResourceCost}, owner::Owner, hyperstructure::HyperStructure,
order::Orders, position::{Coord, Position, PositionTrait, Direction},
buildings::{BuildingCategory, Building, BuildingImpl},
production::{Production, ProductionRateTrait}, realm::{Realm, RealmImpl}
Expand Down
Loading
Loading