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

Format revision and Spanish translation of farming game tutorial #187

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
1 change: 0 additions & 1 deletion docs/.vitepress/locales/en/components/sidebar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ export default [
{text: 'GUI for quests and leaderboards', link:'/build/tutorials/howto-create_farming_game/Part18'}
]
},

{
text: 'Tic-Tac-Toe Game',
link: '/build/tutorials/tic-tac-toe-game/',
Expand Down
25 changes: 25 additions & 0 deletions docs/.vitepress/locales/es/components/sidebar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,31 @@ export default [
link: '/es/build/tutorials/',
collapsed: true,
items: [
{
"text": "Cómo crear un juego de cultivo",
"link": "/es/build/tutorials/howto-create_farming_game/",
"collapsed": true,
"items": [
{"text": "Cómo crear un juego en WAX. Conceptos generales", "link": "/es/build/tutorials/howto-create_farming_game/Part1"},
{"text": "Creación de un objeto o ítem cultivable en el estándar AtomicAssets", "link": "/es/build/tutorials/howto-create_farming_game/Part2"},
{"text": "Creación de NFT de cultivo en Atomic Hub", "link": "/es/build/tutorials/howto-create_farming_game/Part3"},
{"text": "Qué son los recursos y tokens en nuestro proceso de creación de juegos", "link": "/es/build/tutorials/howto-create_farming_game/Part4"},
{"text": "Staking de NFTs", "link": "/es/build/tutorials/howto-create_farming_game/Part5"},
{"text": "Tipos de cultivo y proceso de cultivo", "link": "/es/build/tutorials/howto-create_farming_game/Part6"},
{"text": "Creación de GUI para juegos en WAX, staking y cultivo", "link": "/es/build/tutorials/howto-create_farming_game/Part7"},
{"text": "Mejoras de ítems de juego en juegos de WAX", "link": "/es/build/tutorials/howto-create_farming_game/Part8"},
{"text": "Mezclas de NFTs para juegos de WAX", "link": "/es/build/tutorials/howto-create_farming_game/Part9"},
{"text": "Implementación de avatares en juegos de WAX", "link": "/es/build/tutorials/howto-create_farming_game/Part10"},
{"text": "UI para mezclas, mejoras y avatares", "link": "/es/build/tutorials/howto-create_farming_game/Part11"},
{"text": "Intercambios de tokens y recursos", "link": "/es/build/tutorials/howto-create_farming_game/Part12"},
{"text": "Staking de tokens y votación en juegos", "link": "/es/build/tutorials/howto-create_farming_game/Part13"},
{"text": "Gobernanza en juegos", "link": "/es/build/tutorials/howto-create_farming_game/Part14"},
{"text": "GUI para intercambios, staking y gobernanza", "link": "/es/build/tutorials/howto-create_farming_game/Part15"},
{"text": "Tablas de clasificación en juegos", "link": "/es/build/tutorials/howto-create_farming_game/Part16"},
{"text": "Sistemas de misiones en el juego", "link": "/es/build/tutorials/howto-create_farming_game/Part17"},
{"text": "GUI para misiones y tablas de clasificación", "link": "/es/build/tutorials/howto-create_farming_game/Part18"}
]
},
{
text: 'Tic-Tac-Toe Game',
link: '/es/build/tutorials/tic-tac-toe-game/',
Expand Down
732 changes: 363 additions & 369 deletions docs/build/tutorials/howto-create_farming_game/Part10.md

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions docs/build/tutorials/howto-create_farming_game/Part11.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Building on our ReactJS and WAX smart contract interaction guide, this article a
**Blending assets**
-------------------

Blends in smart contracts allow collection owners to create new, improved assets by combining existing ones. Imagine upgrading your tools by blending two of the same type, resulting in a tool that extracts significantly more resources. 
Blends in smart contracts allow collection owners to create new, improved assets by combining existing ones. Imagine upgrading your tools by blending two of the same type, resulting in a tool that extracts significantly more resources.

This process enriches the user experience by adding depth to resource management and gameplay strategy, seamlessly integrated into the UI for easy user interaction.

Expand Down Expand Up @@ -79,7 +79,7 @@ export const blend = async ({ activeUser, componentIds, assets, blendId }) =>
from: activeUser.accountName,
to: 'dappgamemine',
assets_ids: assets,
memo: `blend:${blendId}`
memo: `blend:${blendId}`
}
});
};
Expand All @@ -106,7 +106,7 @@ Our tool starts at level 1, but we can upgrade it. When this tool is staking on

First, we need to decide which tool or workplace we want to improve. In order to perform this action, our tool needs to be staked. Then we pass it to the configuration of our action.

The UI should look at the maximum allowed level of the tool we want to upgrade before calling the action. It is written in the data of this tool. 
The UI should look at the maximum allowed level of the tool we want to upgrade before calling the action. It is written in the data of this tool.

The next level should be higher than the current one. For our example, let's assume that our instrument has an initial first level.

Expand Down Expand Up @@ -143,7 +143,7 @@ Here we use an action game called "upgradeitem".

- **owner** -- this is our nickname of the user who connected his wallet, we take it from activeUser.accountName;
- **item_to-upgrade** -- ID of the tool we want to upgrade;
- **stake_at_farmingitem** --  the ID of the workplace to which the tool is staking;
- **stake_at_farmingitem** -- the ID of the workplace to which the tool is staking;

After a successful upgrade, our tool becomes level 2:

Expand Down
26 changes: 11 additions & 15 deletions docs/build/tutorials/howto-create_farming_game/Part12.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
---
title: Part 12. Token and resource swaps
title: Part 12. Token and Resource Swaps
order: 60
---

In this article, we're building on previous discussions about upgrading items by introducing a method to exchange resources for tokens. We'll add a new table to track resources, where each entry includes a `key_id` (numerical ID for the resource), `resource_name`, and a `ratio` defining how many resources convert to one token. For instance, a ratio of 25 means 100 units of wood would exchange for 4 tokens. We'll also integrate the standard `eosio.token` contract, previously covered, to handle these transactions.
In this article, we're building on previous discussions about upgrading items by introducing a method to exchange resources for tokens. We'll add a new table to track resources, where each entry includes a `key_id` (numerical ID for the resource), `resource_name`, and a `ratio` defining how many resources convert to one token. For instance, a ratio of 25 means 100 units of wood would exchange for 4 tokens. We'll also integrate the standard `eosio.token` contract, previously covered, to handle these transactions.

```cpp
struct [[eosio::table]] resourcecost
{
uint64_t key_id;
std::string resource_name;
float ratio; // if user swap 100 wood and ration is 25 it means that user will receive 4 tokens
float ratio; // if user swaps 100 wood and the ratio is 25, it means that the user will receive 4 tokens

uint64_t primary_key() const { return blend_id; }
uint64_t primary_key() const { return key_id; }
};
typedef multi_index< "resourcecost"_n, resourcecost_j > resourcecost_t;
typedef multi_index< "resourcecost"_n, resourcecost > resourcecost_t;

```

Expand Down Expand Up @@ -63,7 +63,7 @@ void game::swap(const name& owner, const std::string& resource, const float& amo
auto resourcecost_table_itr = resourcecost_table.require_find(stringToUint64(resource), "Could not find resource cost config");

const float token_amount = amount2swap / resourcecost_table_itr->ratio;
const asset tokens2receive = asset(token_amount * 10000, symbol("GAME", 4)); // change to token you have deployed
const asset tokens2receive = asset(token_amount * 10000, symbol("GAME", 4)); // change to the token you have deployed

reduce_owner_resources_balance(owner, std::map<std::string, float>({{resource, amount2swap}}));
tokens_transfer(owner, tokens2receive);
Expand All @@ -82,13 +82,13 @@ where
To execute a resource-to-token swap in the game:

1. **Record Retrieval**: The function first retrieves the relevant record from the resource table based on the specified resource name. If the resource isn't found, an error is thrown.
2. **Token Calculation**: It then calculates the number of tokens the player should receive based on the amount of resource they want to swap and the predefined ratio in the table: *const* *float* token_amount = amount2swap / resourcecost_table_itr->ratio;
3. **Token Asset Creation**: An asset variable, representing the tokens, is created:\
This step formats the token amount to consider the token's decimal places, ensuring the proper amount is processed for the swap:  *const* **asset** tokens2receive = **asset**(token_amount * 10000, **symbol**("GAME", 4));
2. **Token Calculation**: It then calculates the number of tokens the player should receive based on the amount of resource they want to swap and the predefined ratio in the table: *const float token_amount = amount2swap / resourcecost_table_itr->ratio;*
3. **Token Asset Creation**: An asset variable, representing the tokens, is created:
This step formats the token amount to consider the token's decimal places, ensuring the proper amount is processed for the swap:  *const asset tokens2receive = asset(token_amount * 10000, symbol("GAME", 4));*

The multiplication by (10^4) is necessary because the GAME token is defined with 4 decimal places. To accurately reflect the decimal in transactions, the `token_amount` calculated must be scaled up by 10,000. Additionally, the token symbol configuration requires two parameters: the token's name ("GAME") and its number of decimal places (4). This setup ensures that the token amount and its representation are correctly handled in the system for precise and valid transactions.

Note. While making your own game, make sure to replace GAME with your token name.
Note: While making your own game, make sure to replace GAME with your token name.

```cpp
reduce_owner_resources_balance(owner, std::map<std::string, float>({{resource, amount2swap}}));
Expand Down Expand Up @@ -120,10 +120,6 @@ void game::tokens_transfer(const name& to, const asset& quantity)

To complete the resource-to-token exchange process, the function initiates a token transfer using the contract's token transfer functionality. You will need to replace the referenced token contract name with the name of your specific token contract to ensure the transfer aligns with your game's tokenomics and smart contract settings. This step finalizes the swap by moving the calculated token amount from the game contract to the player's account.

"tokencontr"_n

This article detailed the process of exchanging in-game resources for tokens within a smart contract framework. It covered setting up a table to define resource-to-token conversion rates, calculating the number of tokens based on resources submitted by players, and handling token transactions effectively by ensuring all data aligns with the defined token characteristics. The focus was on the seamless integration of these functionalities into the game's ecosystem, facilitating a dynamic exchange mechanism that enhances player interaction and game economics.

**PS.** The [Following link](https://github.com/dapplicaio/TokenSwaps) leads us to a repository that corresponds everything described, so you can simply build that code and use in a way you want.

###
**PS.** The [following link](https://github.com/dapplicaio/TokenSwaps) leads us to a repository that corresponds to everything described, so you can simply build that code and use it in a way you want.
26 changes: 7 additions & 19 deletions docs/build/tutorials/howto-create_farming_game/Part13.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ void game::receive_token_transfer
else
check(0, "Invalid memo");
}

```

and
Expand All @@ -77,13 +76,11 @@ void game::increase_tokens_balance(const name& owner, const asset& quantity)
});
}
}

```

The function for managing token staking operates by accessing the balance table to locate a specific player's entry. If the player already has a recorded balance, the function increments the number of staked tokens accordingly. If no existing balance is found, it creates a new record for the player, documenting the amount of tokens they have staked.

Voting
------
## Voting

Now that token staking is in place, we'll focus on implementing a voting system to change the rate in resource swaps. To facilitate this, we'll introduce a new table specifically designed to manage voting records. This table will track each vote related to rate adjustments, allowing staked token holders to influence the resource-to-token conversion rates based on their preferences and stake in the game. This mechanism integrates democratic decision-making into the game's economic model.

Expand All @@ -98,7 +95,6 @@ Now that token staking is in place, we'll focus on implementing a voting system
uint64_t primary_key() const { return voting_id; }
};
typedef multi_index< "changeration"_n, changeration_j > changeration_t;

```

To support voting on changes in resource swap rates, we will establish a new table structured as follows:
Expand Down Expand Up @@ -133,7 +129,6 @@ void game::createvoting(
new_row.new_ratio = new_ratio;
});
}

```

To begin with, we check whether such a resource exists in the config table:
Expand Down Expand Up @@ -206,7 +201,6 @@ void game::vote(
});
}
}

```

Let's describe the code above in parts:
Expand All @@ -217,7 +211,7 @@ Let's describe the code above in parts:
require_auth(player);
```

2\. For effective management and processing of player votes regarding resource-to-token ratio changes, the system incorporates critical data structures. These include the Token Balance Table to check players' staked tokens for voting power, the Resource Price Config to reference current and proposed ratio changes, and the Voting Table to accurately manage and tally votes using its iterators. These components are essential for ensuring transparency and integrity in the game's democratic decision-making process.
2. For effective management and processing of player votes regarding resource-to-token ratio changes, the system incorporates critical data structures. These include the Token Balance Table to check players' staked tokens for voting power, the Resource Price Config to reference current and proposed ratio changes, and the Voting Table to accurately manage and tally votes using its iterators. These components are essential for ensuring transparency and integrity in the game's democratic decision-making process.

```cpp
balance_t balance_table(get_self(), get_self().value);
Expand All @@ -229,23 +223,21 @@ auto changeration_table_itr = changeration_table.require_find(voting_id, "Could
auto resourcecost_table_itr = resourcecost_table.require_find(stringToUint64(changeration_table_itr->resource_name));
```

3\. For the voting process, a specific variable is initialized to track progress towards the approval threshold predefined in the vote setup. If this threshold is met, the vote is considered successful, and changes can be applied to the resource ratio settings.
3. For the voting process, a specific variable is initialized to track progress towards the approval threshold predefined in the vote setup. If this threshold is met, the vote is considered successful, and changes can be applied to the resource ratio settings.

```cpp
const asset goal_votes = asset(100 * 10000, symbol("GAME", 4)); // 100.0000 GAME tokens to apply changes
asset total_votes = asset(0, symbol("GAME", 4));

```

4\. So total votes count needs to be done
4. So total votes count needs to be done

```cpp
for (const auto& map_itr : changeration_table_itr->voted)
total_votes += map_itr.second;

```

5\. If the total votes reach the threshold set for the proposal, indicating approval by the players, then the resource price configuration they voted on is updated accordingly. Following this update, the specific vote is concluded and removed from the voting table, finalizing the decision and reflecting the players' collective choice in the game's settings.
5. If the total votes reach the threshold set for the proposal, indicating approval by the players, then the resource price configuration they voted on is updated accordingly. Following this update, the specific vote is concluded and removed from the voting table, finalizing the decision and reflecting the players' collective choice in the game's settings.

```cpp
if(total_votes + balance_table_itr->quantity >= goal_votes)
Expand All @@ -257,10 +249,9 @@ if(total_votes + balance_table_itr->quantity >= goal_votes)

changeration_table.erase(changeration_table_itr);
}

```

6\. otherwise, simply add the votes currently cast by the player
6. otherwise, simply add the votes currently cast by the player

```cpp
else
Expand All @@ -270,11 +261,8 @@ else
new_row.voted[player] = balance_table_itr->quantity;
});
}

```

This article focused on implementing a token staking and voting system within a game environment. It detailed setting up a voting structure for players to influence changes in resource-to-token exchange rates through a democratic process. Key components included creating tables for tracking votes and configuring tokens staked by players to determine their voting power. The article also described how votes are tallied and the conditions under which proposed changes are implemented, emphasizing the integration of these functionalities into the game's smart contract framework.

**PS.** The [Following link](https://github.com/dapplicaio/TokenStakingAndVoting) leads us to a repository that corresponds everything described.

###
**PS.** The [Following link](https://github.com/dapplicaio/TokenStakingAndVoting) leads us to a repository that corresponds everything described.
Loading