Skip to content

Commit

Permalink
docs
Browse files Browse the repository at this point in the history
  • Loading branch information
ebceu4 committed Jan 15, 2019
1 parent 3e8b0c0 commit 6c4841e
Show file tree
Hide file tree
Showing 8 changed files with 3,908 additions and 339 deletions.
92 changes: 9 additions & 83 deletions README.md
Expand Up @@ -14,88 +14,14 @@ and enables game developers to do the following:
### Usage

```js
import { WavesItems, ParamsVer, isResult } from "@waves/waves-games"

//'T' for testnet
//'W' for mainnet

const items = WavesItems('T')

async function howToCreateAnItem(seed) {

console.log(address(seed, 'T'))

const response = await items.create(seed, 100, false, {
version: ParamsVer.One,
main: {
name: 'The great slayer of pain',
img: 'https://cdn5.vectorstock.com/i/thumb-large/26/39/magic-sword-isolated-game-element-vector-20492639.jpg',
},
//user payload to use in game (arbitrary data)
misc: {
power: 10,
attack: 12
}
})

if (isResult(response)) {
//item created
const itemId = response.result.id
console.log(response.result)
} else {
//error
console.log(response.error)
}

async function howToCreateAnItem(creatorSeed) {

const { Items } = require('@waves/waves-games')
const { create } = Items(ChainId.Testnet)

const items = Items(ChainId.Testnet)
const request = create(100, true, { version: 1, main: { name: 'The sword of pain', img: 'img_url' }, misc: {} creatorSeed)
const item = await request.execute()

}

async function howToChangeItemSuplyIfItemIsNotLimited(seed, itemId) {

const response = await items.changeSuply(seed, itemId, +100)
if (isResult(response)) {
console.log(response.result)
}

}

async function howToGetPreviouslyCteatedItemInfo(itemId) {

const response = await items.getItemInfo(itemId, true)
if (isResult(response)) {
console.log(response.result)
}

}

async function howToGetItemListByGameAddress(gameAddress) {

const response = await items.getItemList(gameAddress)
if (isResult(response)) {
console.log(response.result)
}

}

async function howToSellAnItemForWaves(seed, itemId, priceInWaves, amount) {

const response = await items.sellItem(seed, itemId, items.waves(priceInWaves), amount)
if (isResult(response)) {
console.log(response.result)
}

}

async function howToGetAListOfItemsForSale(itemId) {
const response = await items.itemsForSale(itemId, 'WAVES')
if (isResult(response)) {
console.log(response.result)
/* response example
[
{ amount: 1, price: 1.2 }
]
*/
}
}


```
2 changes: 1 addition & 1 deletion build/package.json
@@ -1,6 +1,6 @@
{
"name": "@waves/waves-games",
"version": "1.0.5",
"version": "1.0.7",
"description": "Create and deliver game assets through Waves Platform",
"keywords": [
"waves",
Expand Down
2 changes: 1 addition & 1 deletion docs/globals.html
Expand Up @@ -172,7 +172,7 @@ <h3>Items</h3>
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in items.ts:33</li>
<li>Defined in items.ts:96</li>
</ul>
</aside>
<h4 class="tsd-parameters-title">Parameters</h4>
Expand Down
88 changes: 7 additions & 81 deletions docs/index.html
Expand Up @@ -75,90 +75,16 @@ <h1 id="-waves-waves-games-npm-version">@waves/waves-games <a href="https://www
<li>List items for sale by players or developers</li>
</ul>
<h3 id="usage">Usage</h3>
<pre><code class="language-js"><span class="hljs-keyword">import</span> { WavesItems, ParamsVer, isResult } <span class="hljs-keyword">from</span> <span class="hljs-string">"@waves/waves-games"</span>
<pre><code class="language-js"><span class="hljs-keyword">async</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">howToCreateAnItem</span>(<span class="hljs-params">creatorSeed</span>) </span>{

<span class="hljs-comment">//'T' for testnet</span>
<span class="hljs-comment">//'W' for mainnet</span>
<span class="hljs-keyword">const</span> { Items } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'@waves/waves-games'</span>)
<span class="hljs-keyword">const</span> { create } = Items(ChainId.Testnet)

<span class="hljs-keyword">const</span> items = WavesItems(<span class="hljs-string">'T'</span>)
<span class="hljs-keyword">const</span> items = Items(ChainId.Testnet)
<span class="hljs-keyword">const</span> request = create(<span class="hljs-number">100</span>, <span class="hljs-literal">true</span>, { <span class="hljs-attr">version</span>: <span class="hljs-number">1</span>, <span class="hljs-attr">main</span>: { <span class="hljs-attr">name</span>: <span class="hljs-string">'The sword of pain'</span>, <span class="hljs-attr">img</span>: <span class="hljs-string">'img_url'</span> }, <span class="hljs-attr">misc</span>: {} creatorSeed)
<span class="hljs-keyword">const</span> item = <span class="hljs-keyword">await</span> request.execute()

<span class="hljs-keyword">async</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">howToCreateAnItem</span>(<span class="hljs-params">seed</span>) </span>{

<span class="hljs-built_in">console</span>.log(address(seed, <span class="hljs-string">'T'</span>))

<span class="hljs-keyword">const</span> response = <span class="hljs-keyword">await</span> items.create(seed, <span class="hljs-number">100</span>, <span class="hljs-literal">false</span>, {
<span class="hljs-attr">version</span>: ParamsVer.One,
<span class="hljs-attr">main</span>: {
<span class="hljs-attr">name</span>: <span class="hljs-string">'The great slayer of pain'</span>,
<span class="hljs-attr">img</span>: <span class="hljs-string">'https://cdn5.vectorstock.com/i/thumb-large/26/39/magic-sword-isolated-game-element-vector-20492639.jpg'</span>,
},
<span class="hljs-comment">//user payload to use in game (arbitrary data)</span>
misc: {
<span class="hljs-attr">power</span>: <span class="hljs-number">10</span>,
<span class="hljs-attr">attack</span>: <span class="hljs-number">12</span>
}
})

<span class="hljs-keyword">if</span> (isResult(response)) {
<span class="hljs-comment">//item created </span>
<span class="hljs-keyword">const</span> itemId = response.result.id
<span class="hljs-built_in">console</span>.log(response.result)
} <span class="hljs-keyword">else</span> {
<span class="hljs-comment">//error</span>
<span class="hljs-built_in">console</span>.log(response.error)
}

}

<span class="hljs-keyword">async</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">howToChangeItemSuplyIfItemIsNotLimited</span>(<span class="hljs-params">seed, itemId</span>) </span>{

<span class="hljs-keyword">const</span> response = <span class="hljs-keyword">await</span> items.changeSuply(seed, itemId, +<span class="hljs-number">100</span>)
<span class="hljs-keyword">if</span> (isResult(response)) {
<span class="hljs-built_in">console</span>.log(response.result)
}

}

<span class="hljs-keyword">async</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">howToGetPreviouslyCteatedItemInfo</span>(<span class="hljs-params">itemId</span>) </span>{

<span class="hljs-keyword">const</span> response = <span class="hljs-keyword">await</span> items.getItemInfo(itemId, <span class="hljs-literal">true</span>)
<span class="hljs-keyword">if</span> (isResult(response)) {
<span class="hljs-built_in">console</span>.log(response.result)
}

}

<span class="hljs-keyword">async</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">howToGetItemListByGameAddress</span>(<span class="hljs-params">gameAddress</span>) </span>{

<span class="hljs-keyword">const</span> response = <span class="hljs-keyword">await</span> items.getItemList(gameAddress)
<span class="hljs-keyword">if</span> (isResult(response)) {
<span class="hljs-built_in">console</span>.log(response.result)
}

}

<span class="hljs-keyword">async</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">howToSellAnItemForWaves</span>(<span class="hljs-params">seed, itemId, priceInWaves, amount</span>) </span>{

<span class="hljs-keyword">const</span> response = <span class="hljs-keyword">await</span> items.sellItem(seed, itemId, items.waves(priceInWaves), amount)
<span class="hljs-keyword">if</span> (isResult(response)) {
<span class="hljs-built_in">console</span>.log(response.result)
}

}

<span class="hljs-keyword">async</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">howToGetAListOfItemsForSale</span>(<span class="hljs-params">itemId</span>) </span>{
<span class="hljs-keyword">const</span> response = <span class="hljs-keyword">await</span> items.itemsForSale(itemId, <span class="hljs-string">'WAVES'</span>)
<span class="hljs-keyword">if</span> (isResult(response)) {
<span class="hljs-built_in">console</span>.log(response.result)
<span class="hljs-comment">/* response example
[
{ amount: 1, price: 1.2 }
]
*/</span>
}
}

</code></pre>
}</code></pre>
</div>
</div>
<div class="col-4 col-menu menu-sticky-wrap menu-highlight">
Expand Down
69 changes: 61 additions & 8 deletions docs/interfaces/iitems.html
Expand Up @@ -105,7 +105,7 @@ <h3>buy</h3>
<div class="tsd-signature tsd-kind-icon">buy<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">function</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in items.ts:29</li>
<li>Defined in items.ts:92</li>
</ul>
</aside>
<div class="tsd-type-declaration">
Expand Down Expand Up @@ -145,7 +145,7 @@ <h3>cancel</h3>
<div class="tsd-signature tsd-kind-icon">cancel<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">function</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in items.ts:30</li>
<li>Defined in items.ts:93</li>
</ul>
</aside>
<div class="tsd-type-declaration">
Expand Down Expand Up @@ -182,7 +182,7 @@ <h3>change<wbr>Amount</h3>
<div class="tsd-signature tsd-kind-icon">change<wbr>Amount<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">function</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in items.ts:27</li>
<li>Defined in items.ts:90</li>
</ul>
</aside>
<div class="tsd-type-declaration">
Expand Down Expand Up @@ -222,9 +222,22 @@ <h3>create</h3>
<div class="tsd-signature tsd-kind-icon">create<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">function</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in items.ts:26</li>
<li>Defined in items.ts:89</li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
<div class="lead">
<p>Creates an item.</p>
</div>
<h3 id="usage">Usage</h3>
<pre><code class="language-js"><span class="hljs-keyword">const</span> { Items } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'@waves/waves-games'</span>)
<span class="hljs-keyword">const</span> { create } = Items(ChainId.Testnet)

<span class="hljs-keyword">const</span> items = Items(ChainId.Testnet)
<span class="hljs-keyword">const</span> request = create(<span class="hljs-number">100</span>, <span class="hljs-literal">true</span>, { <span class="hljs-attr">version</span>: <span class="hljs-number">1</span>, <span class="hljs-attr">main</span>: { <span class="hljs-attr">name</span>: <span class="hljs-string">'The sword of pain'</span>, <span class="hljs-attr">img</span>: <span class="hljs-string">'img_url'</span> }, <span class="hljs-attr">misc</span>: {} }, <span class="hljs-string">'creatorSeed'</span>)
<span class="hljs-keyword">const</span> item = <span class="hljs-keyword">await</span> request.execute()
</code></pre>
</div>
<div class="tsd-type-declaration">
<h4>Type declaration</h4>
<ul class="tsd-parameters">
Expand Down Expand Up @@ -262,9 +275,22 @@ <h3>get<wbr>Item</h3>
<div class="tsd-signature tsd-kind-icon">get<wbr>Item<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">function</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in items.ts:23</li>
<li>Defined in items.ts:38</li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
<div class="lead">
<p>Returns an item info from the blockchain.</p>
</div>
<h3 id="usage">Usage</h3>
<pre><code class="language-js"><span class="hljs-keyword">const</span> { Items } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'@waves/waves-games'</span>)
<span class="hljs-keyword">const</span> { getItem } = Items(ChainId.Testnet)

getItem(itemId).then(<span class="hljs-function"><span class="hljs-params">item</span> =&gt;</span> {
<span class="hljs-built_in">console</span>.log(item)
})
</code></pre>
</div>
<div class="tsd-type-declaration">
<h4>Type declaration</h4>
<ul class="tsd-parameters">
Expand Down Expand Up @@ -296,9 +322,22 @@ <h3>get<wbr>Item<wbr>List</h3>
<div class="tsd-signature tsd-kind-icon">get<wbr>Item<wbr>List<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">function</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in items.ts:24</li>
<li>Defined in items.ts:55</li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
<div class="lead">
<p>Returns an item list issued by particular game creator.</p>
</div>
<h3 id="usage">Usage</h3>
<pre><code class="language-js"><span class="hljs-keyword">const</span> { Items } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'@waves/waves-games'</span>)
<span class="hljs-keyword">const</span> { getItemList } = Items(ChainId.Testnet)

getItemList(<span class="hljs-string">'creatorAddress'</span>).then(<span class="hljs-function"><span class="hljs-params">items</span> =&gt;</span> {
<span class="hljs-built_in">console</span>.log(items)
})
</code></pre>
</div>
<div class="tsd-type-declaration">
<h4>Type declaration</h4>
<ul class="tsd-parameters">
Expand Down Expand Up @@ -327,7 +366,7 @@ <h3>sell</h3>
<div class="tsd-signature tsd-kind-icon">sell<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">function</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in items.ts:28</li>
<li>Defined in items.ts:91</li>
</ul>
</aside>
<div class="tsd-type-declaration">
Expand Down Expand Up @@ -374,9 +413,23 @@ <h3>get<wbr>Item<wbr>Suply</h3>
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in items.ts:25</li>
<li>Defined in items.ts:72</li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
<div class="lead">
<p>Returns an item available on market.</p>
</div>
<h3 id="usage">Usage</h3>
<pre><code class="language-js"><span class="hljs-keyword">const</span> { Items } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'@waves/waves-games'</span>)
<span class="hljs-keyword">const</span> { getItemSuply } = Items(ChainId.Testnet)

<span class="hljs-comment">//getting all orders for sale for BTC</span>
getItemSuply(<span class="hljs-string">'itemId'</span>, <span class="hljs-string">'BTC'</span>).then(<span class="hljs-function"><span class="hljs-params">items</span> =&gt;</span> {
<span class="hljs-built_in">console</span>.log(items)
})
</code></pre>
</div>
<h4 class="tsd-parameters-title">Parameters</h4>
<ul class="tsd-parameters">
<li>
Expand Down

0 comments on commit 6c4841e

Please sign in to comment.