Skip to content

Commit

Permalink
Add Documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
irfaardy committed Jul 6, 2020
1 parent c4a2349 commit 59928ed
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 3 deletions.
6 changes: 4 additions & 2 deletions example.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
<!DOCTYPE html>
<html>
<head>
<title>Gatcha</title>
<title>Basic Usage Example</title>
<meta name="viewport" content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0'>
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.5.0/css/bootstrap.min.css">
</head>
<body>
Expand Down Expand Up @@ -39,9 +40,10 @@
'item 21' => 8.3,

])->spin()."</h2>" ?>
</h2><h2>
</h2>
</div>
</div>
</div>
</div>
</body>
</html>
38 changes: 38 additions & 0 deletions src/Roll.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
/*
Author:Irfa Ardiansyah <[email protected]>
Simple Items Gatcha with PHP
v2.1
https://github.com/irfaardy/php-gacha
*/
namespace Irfa\Gatcha;

Expand All @@ -12,32 +14,68 @@ class Roll extends Roulette {

private static $items;

/**
* Put items to $items.
*/
public static function put($items)
{
self::$items = $items;

return new static();
}

/**
* Spin Roullete.
*
* @return string
*/
public static function spin()
{
return self::getItem();
}

/**
* Spin Roullete json result.
*
* @return json
*/
public static function jsonSpin()
{
$ret = self::getItem();
return self::jsonItem($ret);
}

/**
* Add dropup rate.
*
* @param string $item
* @param float $rate
* @return mixed
*/
public static function dropUp($items, $rate)
{
$items_bucket = self::$items;
self::putDropUp(self::itemDropUp($items_bucket, $items, $rate));
return new static();
}

/**
* Get Spinned items.
*
* @return string
*/
private static function getItem() {
$ret = self::get(self::$items);
self::$items = null;
return $ret;
}

/**
* put dropup item to $items variable.
*
* @param array $arr
* @return void
*/
private static function putDropUp($arr) {
foreach ($arr as $k => $v) {
self::$items[$k] = $v;
Expand Down
19 changes: 19 additions & 0 deletions src/Roulette/RateUp.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,37 @@
/*
Author:Irfa Ardiansyah <[email protected]>
Simple Items Gatcha with PHP
v2.1
https://github.com/irfaardy/php-gacha
*/
namespace Irfa\Gatcha\Roulette;

use Exception;

class RateUp {

/**
* Add drop up rate to items.
*
* @param mixed $item_list
* @param array $items
* @param float $rate
* @return array
*/
protected static function _itemDropUp($item_list, $items, $rate)
{
$rt = new RateUp();
return $rt->calc_rate($item_list, $items, $rate);
}

/**
* Calculate Drop Up Rate.
*
* @param mixed $item_list
* @param array $items
* @param float $rate
* @return array
*/
private function calc_rate($item_list, $items, $rate)
{
$item = [];
Expand Down
26 changes: 25 additions & 1 deletion src/Roulette/Roulette.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,46 @@
/*
Author:Irfa Ardiansyah <[email protected]>
Simple Items Gatcha with PHP
v2.1
https://github.com/irfaardy/php-gacha
*/
namespace Irfa\Gatcha\Roulette;

use Exception;
use Irfa\Gatcha\Roulette\RateUp;

class Roulette extends RateUp {


/**
* encode to Json.
*
* @param string $dt
* @return json
*/
protected static function jsonItem($dt) {
$data['data'] = ['item' => $dt];
return json_encode($data);
}

/**
* Add drop up rate to items.
*
* @param mixed $item_list
* @param array $items
* @param float $rate
* @return array
*/
protected static function itemDropUp($item_list, $items, $rate)
{
return self::_itemDropUp($item_list, $items, $rate);
}

/**
* Get Item.
*
* @param array $item
* @return string
*/
protected static function get($items) {
if (is_array($items))
{
Expand Down

0 comments on commit 59928ed

Please sign in to comment.