diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 0fd7dd8418..33e24ddc07 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -2021,6 +2021,7 @@ phutil_register_library_map(array( 'PhabricatorBadgesBadgeQualityTransaction' => 'applications/badges/xaction/PhabricatorBadgesBadgeQualityTransaction.php', 'PhabricatorBadgesBadgeRevokeTransaction' => 'applications/badges/xaction/PhabricatorBadgesBadgeRevokeTransaction.php', 'PhabricatorBadgesBadgeStatusTransaction' => 'applications/badges/xaction/PhabricatorBadgesBadgeStatusTransaction.php', + 'PhabricatorBadgesBadgeTestDataGenerator' => 'applications/badges/lipsum/PhabricatorBadgesBadgeTestDataGenerator.php', 'PhabricatorBadgesBadgeTransactionType' => 'applications/badges/xaction/PhabricatorBadgesBadgeTransactionType.php', 'PhabricatorBadgesCommentController' => 'applications/badges/controller/PhabricatorBadgesCommentController.php', 'PhabricatorBadgesController' => 'applications/badges/controller/PhabricatorBadgesController.php', @@ -2035,6 +2036,7 @@ phutil_register_library_map(array( 'PhabricatorBadgesEditor' => 'applications/badges/editor/PhabricatorBadgesEditor.php', 'PhabricatorBadgesIconSet' => 'applications/badges/icon/PhabricatorBadgesIconSet.php', 'PhabricatorBadgesListController' => 'applications/badges/controller/PhabricatorBadgesListController.php', + 'PhabricatorBadgesLootContextFreeGrammar' => 'applications/badges/lipsum/PhabricatorBadgesLootContextFreeGrammar.php', 'PhabricatorBadgesMailReceiver' => 'applications/badges/mail/PhabricatorBadgesMailReceiver.php', 'PhabricatorBadgesPHIDType' => 'applications/badges/phid/PhabricatorBadgesPHIDType.php', 'PhabricatorBadgesProfileController' => 'applications/badges/controller/PhabricatorBadgesProfileController.php', @@ -6979,6 +6981,7 @@ phutil_register_library_map(array( 'PhabricatorBadgesBadgeQualityTransaction' => 'PhabricatorBadgesBadgeTransactionType', 'PhabricatorBadgesBadgeRevokeTransaction' => 'PhabricatorBadgesBadgeTransactionType', 'PhabricatorBadgesBadgeStatusTransaction' => 'PhabricatorBadgesBadgeTransactionType', + 'PhabricatorBadgesBadgeTestDataGenerator' => 'PhabricatorTestDataGenerator', 'PhabricatorBadgesBadgeTransactionType' => 'PhabricatorModularTransactionType', 'PhabricatorBadgesCommentController' => 'PhabricatorBadgesController', 'PhabricatorBadgesController' => 'PhabricatorController', @@ -6993,6 +6996,7 @@ phutil_register_library_map(array( 'PhabricatorBadgesEditor' => 'PhabricatorApplicationTransactionEditor', 'PhabricatorBadgesIconSet' => 'PhabricatorIconSet', 'PhabricatorBadgesListController' => 'PhabricatorBadgesController', + 'PhabricatorBadgesLootContextFreeGrammar' => 'PhutilContextFreeGrammar', 'PhabricatorBadgesMailReceiver' => 'PhabricatorObjectMailReceiver', 'PhabricatorBadgesPHIDType' => 'PhabricatorPHIDType', 'PhabricatorBadgesProfileController' => 'PhabricatorController', diff --git a/src/applications/badges/lipsum/PhabricatorBadgesBadgeTestDataGenerator.php b/src/applications/badges/lipsum/PhabricatorBadgesBadgeTestDataGenerator.php new file mode 100644 index 0000000000..9b29ecb4f8 --- /dev/null +++ b/src/applications/badges/lipsum/PhabricatorBadgesBadgeTestDataGenerator.php @@ -0,0 +1,71 @@ +loadRandomUser(); + + list($name, $description) = $this->newLoot(); + + $xactions = array(); + + $xactions[] = array( + 'type' => 'name', + 'value' => $name, + ); + + $xactions[] = array( + 'type' => 'description', + 'value' => $description, + ); + + $params = array( + 'transactions' => $xactions, + ); + + $result = id(new ConduitCall('badges.edit', $params)) + ->setUser($author) + ->execute(); + + return $result['object']['phid']; + } + + private function newLoot() { + $drop = id(new PhabricatorBadgesLootContextFreeGrammar()) + ->generate(); + + $drop = preg_replace_callback( + '/<(\d+)-(\d+)>/', + array($this, 'rollDropValue'), + $drop); + + $effect_pattern = '/\s*\(([^)]+)\)/'; + + $matches = null; + if (preg_match_all($effect_pattern, $drop, $matches)) { + $description = $matches[1]; + $description = implode("\n", $description); + } else { + $description = ''; + } + + $drop = preg_replace($effect_pattern, '', $drop); + + return array($drop, $description); + } + + public function rollDropValue($matches) { + $min = (int)$matches[1]; + $max = (int)$matches[2]; + return mt_rand($min, $max); + } + + +} diff --git a/src/applications/badges/lipsum/PhabricatorBadgesLootContextFreeGrammar.php b/src/applications/badges/lipsum/PhabricatorBadgesLootContextFreeGrammar.php new file mode 100644 index 0000000000..2a4092e3c7 --- /dev/null +++ b/src/applications/badges/lipsum/PhabricatorBadgesLootContextFreeGrammar.php @@ -0,0 +1,88 @@ + array( + '[jewelry]', + ), + 'jewelry' => array( + 'Ring [jewelry-suffix]', + 'Ring [jewelry-suffix]', + '[jewelry-prefix] Ring', + '[jewelry-prefix] Ring', + 'Amulet [jewelry-suffix]', + 'Amulet [jewelry-suffix]', + '[jewelry-prefix] Amulet', + '[jewelry-prefix] Amulet', + '[jewelry-prefix] Ring [jewelry-suffix]', + '[jewelry-prefix] Amulet [jewelry-suffix]', + '[unique-jewelry]', + ), + 'jewelry-prefix' => array( + '[mana-prefix]', + ), + + 'jewelry-suffix' => array( + '[dexterity-suffix]', + '[dexterity-suffix-jewelry]', + ), + 'mana-prefix' => array( + 'Hyena\'s (-<11-25> Mana)', + 'Frog\'s (-<1-10> Mana)', + 'Spider\'s (+<10-15> Mana)', + 'Raven\'s (+<15-20> Mana)', + 'Snake\'s (+<21-30> Mana)', + 'Serpent\'s (+<31-40> Mana)', + 'Drake\'s (+<41-50> Mana)', + 'Dragon\'s (+<51-60> Mana)', + ), + 'dexterity-suffix' => array( + 'of Paralysis (-<6-10> Dexterity)', + 'of Atrophy (-<1-5> Dexterity)', + 'of Dexterity (+<1-5> Dexterity)', + 'of Skill (+<6-10> Dexterity)', + 'of Accuracy (+<11-15> Dexterity)', + 'of Precision (+<16-20> Dexterity)', + ), + 'dexterity-suffix-jewelry' => array( + '[dexterity-suffix]', + '[dexterity-suffix]', + '[dexterity-suffix]', + '[dexterity-suffix]', + '[dexterity-suffix]', + '[dexterity-suffix]', + '[dexterity-suffix]', + '[dexterity-suffix]', + '[dexterity-suffix]', + 'of Perfection (+<21-30> Dexterity)', + ), + 'unique-jewelry' => array( + '[jewelry]', + '[jewelry]', + '[jewelry]', + '[jewelry]', + '[jewelry]', + '[jewelry]', + '[jewelry]', + '[jewelry]', + '[unique-ring]', + '[unique-amulet]', + ), + 'unique-ring' => array( + 'The Bleeder', + 'The Bramble', + 'Constricting Ring', + 'Empyrean Band', + 'Ring of Engagement', + 'Ring of Regha', + ), + 'unique-amulet' => array( + 'Optic Amulet', + ), + ); + } + +}