{"id":16203328,"url":"https://github.com/sschmid/gummi-commander","last_synced_at":"2025-08-04T16:45:28.200Z","repository":{"id":5802275,"uuid":"7016962","full_name":"sschmid/Gummi-Commander","owner":"sschmid","description":"Event Command Mapping System for Objective-C","archived":false,"fork":false,"pushed_at":"2013-03-18T21:24:37.000Z","size":530,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-02-13T20:44:22.969Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://sschmid.github.com/Gummi-Commander/","language":"Objective-C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sschmid.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-12-05T12:20:32.000Z","updated_at":"2023-07-03T16:50:20.000Z","dependencies_parsed_at":"2022-08-31T04:22:43.315Z","dependency_job_id":null,"html_url":"https://github.com/sschmid/Gummi-Commander","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sschmid%2FGummi-Commander","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sschmid%2FGummi-Commander/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sschmid%2FGummi-Commander/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sschmid%2FGummi-Commander/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sschmid","download_url":"https://codeload.github.com/sschmid/Gummi-Commander/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247713259,"owners_count":20983683,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-10T09:53:48.824Z","updated_at":"2025-04-07T19:18:35.697Z","avatar_url":"https://github.com/sschmid.png","language":"Objective-C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Gummi Commander\n![Gummi Commander Logo](http://sschmid.com/Libs/Gummi-Commander/Gummi-Commander-128.png)\n\n## Description\nGummi Commander is an Event Command Mapping System for Objective-C.\n\n## Dependencies\nGummi Commander uses\n* [Gummi Injection] (https://github.com/sschmid/Gummi-Injection) for Dependency Injection.\n* [Gummi Dispatcher] (https://github.com/sschmid/Gummi-Dispatcher) as a Messaging System.\n\n## Features\n* Execute multiple commands by dispatching one event\n* Supports nested Async and Sequence Commands\n* Add mappings with priority\n* Map blocks\n* Auto map triggers\n* Prevent certain commands to execute by adding Guards\n* Inject the corresponding event and other objects of interest into commands\n\n## How to use Gummi Commander\nYou can get started by simply allocating a commandMap.\n\nThe recommended way to use Gummi Commander is to put your configuration logic into `GCGIExtension` and add them to the Injector.\nThe provided `GummiCommanderModule` should be added first.\n\n```objective-c\nGIInjector *injector = [GIInjector sharedInjector];\n[injector addModule:[[GummiCommanderModule alloc] init]];\n\n[injector addModule:[[ApplicationExtension alloc] init]];\n[injector addModule:[[TrackingExtension alloc] init]];\n\n// Maybe add this extension later in the code,\n// right before the game starts\n[injector addModule:[[GameExtension alloc] init]];\n```\n\n## Commands\n* Commands are short lived objects.\n* Commands get created and executed when dispatching an event.\n* Commands can inject the corresponding event, models and more...\n* Commands get destroyed immediately after execution.\n\n```objective-c\n@implementation DropBombCommand\ninject(@\"event\", @\"model\")\n\n- (void)execute {\n    self.model.bombs--;\n    [self spawnBombAtPosition:self.event.position];\n}\n...\n@end\n```\n\n## Async and Sequence Commands\n\nGummi Commander also supports nested Async and Sequence Commands.\n\n* Sequence\n  * Async\n    * Command\n    * Sequence\n      * Async\n      * Async\n      * Command\n    * Command\n  * Async\n* Async\n* Command\n\n\nWith `stopWhenNoSuccess` you can decide, if a Sequence Command should stop or carry on, when any Command did execute without success.\n\nA Sequence Command\n\n```objective-c\n@implementation MySequenceCommand\n\n- (id)init {\n    self = [super init];\n    if (self) {\n\n        self.stopWhenNoSuccess = NO; // Default\n\n        [self addCommand:[MyAsyncCommand class]];\n        [self addCommand:[MyCommand class]];\n        [self addCommand:[MyOtherSequenceCommand class]];\n    }\n\n    return self;\n}\n\n@end\n```\n\nAn Async Command\n\n```objective-c\n@implementation MyAsyncCommand\n\n- (void)execute {\n    [self performSelector:@selector(doSth) withObject:nil afterDelay:1];\n}\n\n- (void) doSth {\n    [self didExecuteWithSuccess:YES];\n}\n\n@end\n```\n\n## The CommandMap\nWhen an instance of MyEvent gets dispatched, all mapped commands get executed\n\n```objective-c\n[commandMap mapAction:[MyCommand class] toTrigger:[MyEvent class]];\n\n[commandMap mapAction:[MyOtherCommand class] toTrigger:[MyEvent class]\n                           removeMappingAfterExecution:YES];\n\n[commandMap mapAction:[ACommand class] toTrigger:[MyEvent class]\n                                        priority: 5];\n\n[commandMap mapAction:[AnOtherCommand class] toTrigger:[MyEvent class]\n                                              priority: 10];\n\n// Will automatically map SomeCommand to SomeEvent\n// Auto mapped triggers must follow the naming convention XyzEvent\n// Commands must follow the naming convention XyzCommand\n[commandMap autoMapTrigger:[SomeEvent class]];\n```\n\nInstead of commands, you can also map blocks\n\n```objective-c\nvoid (^myBlock)(GIInjector *injector);\nmyBlock = ^(GIInjector * injector) {\n    MyEvent *event = [injector getObject:[MyEvent class]];\n    ...\n};\n\n[commandMap mapAction:myBlock toTrigger:[FlagAndStringEvent class]];\n```\n\n## Guards\n* Guards do only one thing: approve.\n* Guards decide, whether a command gets executed or not.\n* Only when all guards approve, a command gets executed.\n\n```objective-c\n@implementation IsInGridGuard\ninject(@\"event\", @\"grid\")\n\n- (BOOL)approve {\n    return [self.grid containsPosition:self.event.position];    \n}\n\n@end\n```\n\n#### You can add guards like this:\n\n```objective-c\n[[commandMap mapAction:[DropBombCommand class]\n                toTrigger:[DropBombEvent class]]\n             withGuards:@[[IsInGridGuard class]]];\n```\n\n## Extensions\nPut related configuration logic into extensions and add or remove them at will\n\n```objective-c\n@implementation GameExtension\n\n- (void)configure:(GIInjector *)injector {\n    [super configure:injector];\n\n    // Map commands to events\n    [[self mapAction:[DropBombCommand class]\n              toTrigger:[DropBombEvent class]]\n           withGuards:@[[IsInGridGuard class]]];\n\n    // Set injection rules\n    [self mapEagerSingleton:[MyService class] to:@protocol(RemoteService)];\n}\n\n- (void)unload {\n    Service *service = [_injector getObject:@protocol(RemoteService)];\n    [service close];\n\n    // All mappings from the CommandMap and the Injector made\n    // in this module get removed automatically.\n\n    [super unload];\n}\n```\n\n## Install Gummi Commander\nYou find the source files you need in Gummi-Commander/Classes.\n\nYou also need:\n* [Gummi Dispatcher] (https://github.com/sschmid/Gummi-Dispatcher) - Observe and dispatch any objects\n* [Gummi Injection] (https://github.com/sschmid/Gummi-Injection) - A lightweight dependency injection framework for Objective-C\n\n## CocoaPods\nInstall [CocoaPods] (http://cocoapods.org) and add the Gummi Commander reference to your Podfile\n\n```\nplatform :ios, '5.0'\n  pod 'Gummi-Commander'\nend\n```\n\n#### Add this remote\n\n```\n$ pod repo add sschmid-cocoapods-specs https://github.com/sschmid/cocoapods-specs\n```\n\n#### Install Gummi Commander\n\n```\n$ cd path/to/project\n$ pod install\n```\nOpen the created Xcode Workspace file.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsschmid%2Fgummi-commander","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsschmid%2Fgummi-commander","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsschmid%2Fgummi-commander/lists"}