Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F15292840
D17422.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
7 KB
Referenced Files
None
Subscribers
None
D17422.diff
View Options
diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -2021,6 +2021,7 @@
'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 @@
'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 @@
'PhabricatorBadgesBadgeQualityTransaction' => 'PhabricatorBadgesBadgeTransactionType',
'PhabricatorBadgesBadgeRevokeTransaction' => 'PhabricatorBadgesBadgeTransactionType',
'PhabricatorBadgesBadgeStatusTransaction' => 'PhabricatorBadgesBadgeTransactionType',
+ 'PhabricatorBadgesBadgeTestDataGenerator' => 'PhabricatorTestDataGenerator',
'PhabricatorBadgesBadgeTransactionType' => 'PhabricatorModularTransactionType',
'PhabricatorBadgesCommentController' => 'PhabricatorBadgesController',
'PhabricatorBadgesController' => 'PhabricatorController',
@@ -6993,6 +6996,7 @@
'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
--- /dev/null
+++ b/src/applications/badges/lipsum/PhabricatorBadgesBadgeTestDataGenerator.php
@@ -0,0 +1,71 @@
+<?php
+
+final class PhabricatorBadgesBadgeTestDataGenerator
+ extends PhabricatorTestDataGenerator {
+
+ const GENERATORKEY = 'badges';
+
+ public function getGeneratorName() {
+ return pht('Badges');
+ }
+
+ public function generateObject() {
+ $author = $this->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
--- /dev/null
+++ b/src/applications/badges/lipsum/PhabricatorBadgesLootContextFreeGrammar.php
@@ -0,0 +1,88 @@
+<?php
+
+final class PhabricatorBadgesLootContextFreeGrammar
+ extends PhutilContextFreeGrammar {
+
+ protected function getRules() {
+ return array(
+ 'start' => 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',
+ ),
+ );
+ }
+
+}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Mar 6, 2:59 AM (7 h, 20 m ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7228611
Default Alt Text
D17422.diff (7 KB)
Attached To
Mode
D17422: Add a lipsum generator for Badges
Attached
Detach File
Event Timeline
Log In to Comment