Skip to content

Commit

Permalink
move IsAllItemHave to HasAllItems, and IsAnyItemHave to HasAnyItems
Browse files Browse the repository at this point in the history
  • Loading branch information
saronpasu committed Nov 14, 2015
1 parent b2c8ebc commit 6251a61
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 74 deletions.
24 changes: 12 additions & 12 deletions IsAllItemHave/IsAllItemHave.js → HasAllItems/HasAllItems.js
@@ -1,5 +1,5 @@
//=============================================================================
// IsAllItemHave.js
// HasAllItems.js
//=============================================================================

/*:
Expand All @@ -12,12 +12,12 @@
* @help
*
* Plugin Command:
* Command IsAllItemHave SwitchId ItemNameA, ItemNameB, ...
* Command HasAllItems SwitchId ItemNameA, ItemNameB, ...
* SwitchId -> check result.
* ItemNameA -> check ItemName
*
* Script:
* $gameParty.IsAllItemHave(['ItemNameA', 'ItemNameB']);
* $gameParty.HasAllItems(['ItemNameA', 'ItemNameB']);
* return -> true (have item)
* -> false (not have item)
*
Expand All @@ -31,12 +31,12 @@
* @help
*
* Plugin Command:
* Command IsAllItemHave SwitchId ItemNameA, ItemNameB, ...
* Command HasAllItems SwitchId ItemNameA, ItemNameB, ...
* SwitchId -> 持っているかどうかの結果を返すスイッチID
* ItemNameA -> 調べるアイテム名
*
* Script:
* $gameParty.IsAllItemHave(['ItemNameA', 'ItemNameB']);
* $gameParty.HasAllItems(['ItemNameA', 'ItemNameB']);
* return -> true (アイテムを持っている場合)
* -> false (アイテムを持っていない場合)
*
Expand All @@ -51,22 +51,22 @@
*/

var Imported = Imported || {};
Imported.IsAllItemHave = {};
Imported.HasAllItems = {};

(function() {

'use strict';

var parameters = PluginManager.parameters('IsAllItemHave');
var parameters = PluginManager.parameters('HasAllItems');

var _Game_Interpreter_pluginCommand =
Game_Interpreter.prototype.pluginCommand;
Game_Interpreter.prototype.pluginCommand = function(command, args) {
_Game_Interpreter_pluginCommand.call(this, command, args);
if (command === 'isAllItemHave') {
if (command === 'hasAllItems') {
if (/^[0-9]+$/.test(args[0])) {
var targets = args.filter(function(i){return /^[^0-9]+$/.test(i);});
var result = $gameParty.isAllItemHave(targets);
var result = $gameParty.hasAllItems(targets);
if (result) {
$gameSwitches.setValue(Number(args[0]), true);
}
Expand All @@ -85,7 +85,7 @@ Imported.IsAllItemHave = {};
return targets.filter(function(i){return isValidName(i);}).length !== 0;
};

Game_Party.prototype.isAllItemHave = function(targets) {
Game_Party.prototype.hasAllItems = function(targets) {
if (!isValidTargets(targets)) {
return false;
}
Expand All @@ -106,8 +106,8 @@ Imported.IsAllItemHave = {};

// クロージャの関数をテスト用にエクスポート
try {
if (should) {
exports.isAllItemHave = Game_Party.prototype.isAllItemHave;
if (isTest) {
exports.hasAllItems = Game_Party.prototype.hasAllItems;
exports.pluginCommand = Game_Interpreter.prototype.pluginCommand;
exports.isValidName = isValidName;
exports.isValidTargets = isValidTargets;
Expand Down
11 changes: 7 additions & 4 deletions IsAllItemHave/README.md → HasAllItems/README.md
Expand Up @@ -8,30 +8,33 @@
- プラグインコマンドの場合

```
IsAllItemHave スイッチID アイテム名1 アイテム名2 アイテム名3 ...
HasAllItems スイッチID アイテム名1 アイテム名2 アイテム名3 ...
```
- コマンド名は「IsAllItemHave」です。
- コマンド名は「HasAllItems」です。
- スイッチIDは数字で入力して下さい。そのIDのスイッチに結果が入ります。(ON:持ってる/OFF:持ってない)
- アイテム名は確認したいアイテム名を入れます。いくつでも入れられます。
- 注意事項:プラグインコマンドは半角スペースで区切って下さい。

- スクリプトコマンドの場合

```javascript
$gameParty.isAllItemHave(['アイテム名1', 'アイテム名2']);
$gameParty.hasAllItems(['アイテム名1', 'アイテム名2']);
```
- 結果は、アイテムを持っている場合は true 持ってない場合は false が返ります。



詳しい処理は IsAllItemHave.js を見て下さい。
詳しい処理は HasAllItems.js を見て下さい。



## History
version 0.0.1
- ツクった!

version 0.0.2
- 名前変更。あと変数名とか。

## Author
saronpasu

Expand Down
@@ -1,13 +1,15 @@
isTest = true;

should = require('chai').should();
sinon = require('sinon');

describe('IsAllItemHave', function() {
describe('HasAllItems', function() {
// initialize
before(function() {
// define mock PluginManager
PluginManager = {};
PluginManager.parameters = sinon.stub()
.withArgs('IsAllItemHave').returns({
.withArgs('HasAllItems').returns({
// PluginParam: 'default'
});
// define mock Game_Interpreter
Expand All @@ -20,13 +22,13 @@ describe('IsAllItemHave', function() {
Game_Party.prototype.members = function() {};

// import Test functions.
IsAllItemHave = require('../IsAllItemHave.js');
isAllItemHave = IsAllItemHave.isAllItemHave;
Game_Party.prototype.isAllItemHave = isAllItemHave;
pluginCommand = IsAllItemHave.pluginCommand;
HasAllItems = require('../HasAllItems.js');
hasAllItems = HasAllItems.hasAllItems;
Game_Party.prototype.hasAllItems = hasAllItems;
pluginCommand = HasAllItems.pluginCommand;
Game_Interpreter.prototype.pluginCommand = pluginCommand;
isValidName = IsAllItemHave.isValidName;
isValidTargets = IsAllItemHave.isValidTargets;
isValidName = HasAllItems.isValidName;
isValidTargets = HasAllItems.isValidTargets;
});

describe('validator', function() {
Expand Down Expand Up @@ -76,15 +78,15 @@ describe('IsAllItemHave', function() {
});

it('target find', function() {
gameParty.isAllItemHave(['targetName']).should.be.true;
gameParty.hasAllItems(['targetName']).should.be.true;
});

it('two target find', function() {
gameParty.isAllItemHave(['targetName', 'otherTarget']).should.be.false;
gameParty.hasAllItems(['targetName', 'otherTarget']).should.be.false;
});

it('target not found', function() {
gameParty.isAllItemHave(['notMatchName']).should.be.false;
gameParty.hasAllItems(['notMatchName']).should.be.false;
});
});

Expand All @@ -100,15 +102,15 @@ describe('IsAllItemHave', function() {
});

it('one target find', function() {
gameParty.isAllItemHave(['targetName1', 'notMatchName2']).should.be.false;
gameParty.hasAllItems(['targetName1', 'notMatchName2']).should.be.false;
});

it('two targets not found', function() {
gameParty.isAllItemHave(['targetName1', 'targetName2']).should.be.true;
gameParty.hasAllItems(['targetName1', 'targetName2']).should.be.true;
});

it('target not found', function() {
gameParty.isAllItemHave(['notMatchName1', 'notMatchName2']).should.be.false;
gameParty.hasAllItems(['notMatchName1', 'notMatchName2']).should.be.false;
});
});

Expand All @@ -134,15 +136,15 @@ describe('IsAllItemHave', function() {
});

it('target find', function() {
gameParty.isAllItemHave(['targetName']).should.be.true;
gameParty.hasAllItems(['targetName']).should.be.true;
});

it('two targets not found', function() {
gameParty.isAllItemHave(['targetName', 'otherTarget']).should.be.false;
gameParty.hasAllItems(['targetName', 'otherTarget']).should.be.false;
});

it('target not found', function() {
gameParty.isAllItemHave(['notMatchName']).should.be.false;
gameParty.hasAllItems(['notMatchName']).should.be.false;
});
});

Expand All @@ -168,20 +170,20 @@ describe('IsAllItemHave', function() {
});

it('one target find', function() {
gameParty.isAllItemHave(['targetName1', 'notMatchName2']).should.be.false;
gameParty.hasAllItems(['targetName1', 'notMatchName2']).should.be.false;
});

it('two target find', function() {
gameParty.isAllItemHave(['targetName1', 'targetName2']).should.be.true;
gameParty.hasAllItems(['targetName1', 'targetName2']).should.be.true;
});

it('target not found', function() {
gameParty.isAllItemHave(['notMatchName1', 'notMatchName2']).should.be.false;
gameParty.hasAllItems(['notMatchName1', 'notMatchName2']).should.be.false;
});
});

it('Party not have target item and equips', function() {
gameParty.isAllItemHave(['targetName']).should.be.false;
gameParty.hasAllItems(['targetName']).should.be.false;
});

describe('call from PluginCommand', function() {
Expand All @@ -203,16 +205,16 @@ describe('IsAllItemHave', function() {
sinon.stub($gameParty, 'allItems').returns(items);
sinon.stub($gameParty, 'members').returns([actor1, actor2]);

spy = sinon.spy($gameParty, 'isAllItemHave');
spy = sinon.spy($gameParty, 'hasAllItems');
});

it('valid argments', function() {
gameInterpreter.pluginCommand('isAllItemHave', ['1', 'foo', 'bar']);
gameInterpreter.pluginCommand('hasAllItems', ['1', 'foo', 'bar']);
spy.called.should.be.true;
});

it('invalid argments', function() {
gameInterpreter.pluginCommand('isAllItemHave', ['aaa', 'foo', 'bar']);
gameInterpreter.pluginCommand('hasAllItems', ['aaa', 'foo', 'bar']);
spy.called.should.be.false;
});

Expand Down
14 changes: 7 additions & 7 deletions IsAnyItemHave/IsAnyItemHave.js → HasAnyItems/HasAnyItems.js
Expand Up @@ -51,22 +51,22 @@
*/

var Imported = Imported || {};
Imported.IsAnyItemHave = {};
Imported.HasAnyItems = {};

(function() {

'use strict';

var parameters = PluginManager.parameters('IsAnyItemHave');
var parameters = PluginManager.parameters('HasAnyItems');

var _Game_Interpreter_pluginCommand =
Game_Interpreter.prototype.pluginCommand;
Game_Interpreter.prototype.pluginCommand = function(command, args) {
_Game_Interpreter_pluginCommand.call(this, command, args);
if (command === 'isAnyItemHave') {
if (command === 'hasAnyItems') {
if (/^[0-9]+$/.test(args[0])) {
var targets = args.filter(function(i){return /^[^0-9]+$/.test(i);});
var result = $gameParty.isAnyItemHave(targets);
var result = $gameParty.hasAnyItems(targets);
if (result) {
$gameSwitches.setValue(Number(args[0]), true);
}
Expand All @@ -85,7 +85,7 @@ Imported.IsAnyItemHave = {};
return targets.filter(function(i){return isValidName(i);}).length !== 0;
};

Game_Party.prototype.isAnyItemHave = function(targets) {
Game_Party.prototype.hasAnyItems = function(targets) {
if (!isValidTargets(targets)) {
return false;
}
Expand All @@ -106,8 +106,8 @@ Imported.IsAnyItemHave = {};

// クロージャの関数をテスト用にエクスポート
try {
if (should) {
exports.isAnyItemHave = Game_Party.prototype.isAnyItemHave;
if (isTest) {
exports.hasAnyItems = Game_Party.prototype.hasAnyItems;
exports.pluginCommand = Game_Interpreter.prototype.pluginCommand;
exports.isValidName = isValidName;
exports.isValidTargets = isValidTargets;
Expand Down
11 changes: 7 additions & 4 deletions IsAnyItemHave/README.md → HasAnyItems/README.md
Expand Up @@ -8,30 +8,33 @@
- プラグインコマンドの場合

```
IsAnyItemHave スイッチID アイテム名1 アイテム名2 アイテム名3 ...
HasAnyItems スイッチID アイテム名1 アイテム名2 アイテム名3 ...
```
- コマンド名は「IsAnyItemHave」です。
- コマンド名は「HasAnyItems」です。
- スイッチIDは数字で入力して下さい。そのIDのスイッチに結果が入ります。(ON:持ってる/OFF:持ってない)
- アイテム名は確認したいアイテム名を入れます。いくつでも入れられます。
- 注意事項:プラグインコマンドは半角スペースで区切って下さい。

- スクリプトコマンドの場合

```javascript
$gameParty.isAnyItemHave(['アイテム名1', 'アイテム名2']);
$gameParty.HasAnyItems(['アイテム名1', 'アイテム名2']);
```
- 結果は、アイテムを持っている場合は true 持ってない場合は false が返ります。



詳しい処理は IsAnyItemHave.js を見て下さい。
詳しい処理は HasAnyItems.js を見て下さい。



## History
version 0.0.1
- ツクった!

version 0.0.2
- 名前変更。あと変数名とか。

## Author
saronpasu

Expand Down

0 comments on commit 6251a61

Please sign in to comment.