{"id":22205358,"url":"https://github.com/stevertus/objd_gen","last_synced_at":"2025-03-25T03:25:07.474Z","repository":{"id":107780804,"uuid":"330256034","full_name":"Stevertus/objd_gen","owner":"Stevertus","description":"A package of code generators for objD Annotations","archived":false,"fork":false,"pushed_at":"2023-06-26T21:03:04.000Z","size":14,"stargazers_count":1,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-30T04:17:07.266Z","etag":null,"topics":["datapack","minecraft","objd"],"latest_commit_sha":null,"homepage":"https://pub.dev/packages/objd_gen","language":"Dart","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Stevertus.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-01-16T20:55:52.000Z","updated_at":"2024-01-01T13:30:15.000Z","dependencies_parsed_at":"2023-06-12T12:30:45.010Z","dependency_job_id":null,"html_url":"https://github.com/Stevertus/objd_gen","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Stevertus%2Fobjd_gen","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Stevertus%2Fobjd_gen/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Stevertus%2Fobjd_gen/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Stevertus%2Fobjd_gen/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Stevertus","download_url":"https://codeload.github.com/Stevertus/objd_gen/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245390643,"owners_count":20607486,"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":["datapack","minecraft","objd"],"created_at":"2024-12-02T17:30:03.097Z","updated_at":"2025-03-25T03:25:07.450Z","avatar_url":"https://github.com/Stevertus.png","language":"Dart","funding_links":[],"categories":[],"sub_categories":[],"readme":"## objd_gen\n\nThis package contains code generators made with source_gen. With annotations Widgets, Files, Packs and Projects can be written much more consisely.\n\n### Installation\n\nInclude the package along with build_runner in your pubspec.yaml as a dev dependency:\n\n```\ndev_dependencies:\n  build_runner:\n  objd_gen: ^0.0.2\n```\n\nThe generators put the new dart classes and functions in a new file alongside your annotated file. To make it available include it with the part statement:\n\n```dart\nimport 'package:objd/core.dart';\n\npart '[your_filename].g.dart';\n```\n\nAfter writing all your Widgets,this package generates the associated classes and functions with:\n\n```\npub run build_runner build\n```\n\nOr if you want it to generate automatically after saving run:\n\n```\npub run build_runner watch\n```\n\n### Widget\n\nWriting a Widget becomes much simpler with the `@Wdg` annotation. You can just give it a function with needed parameters which returns a new Widget and the generators will figure out a Widget class to go along with it.\n\nOne simple case would be:\n\n```dart\n@Wdg\nWidget helloWorld() =\u003e Log('Hello World!');\n```\n\nAfter running build_runner a new Widget **HelloWorld** is generated(inherited from the function name), so it is advisable to use lowercase functions.\n\nParameters also work like you exspect and you even get access to the widget context if you need to:\n\n```dart\n@Wdg\nWidget helloName(String name, {String lastname = '', Context context}) =\u003e For.of([\n  Comment('This was generated by HelloName on version ${context.version}'),\n  Log('Hello $name $lastname!'),\n]);\n```\n\nThis would translate to a Widget in the following way, which you can use everywhere in your projects from now on:\n\n```dart\nclass HelloName extends Widget {\n  final String name;\n  final String lastname;\n\n  HelloName(\n    this.name, {\n    this.lastname = '',\n  });\n\n  @override\n  Widget generate(Context context) =\u003e helloName(\n        name,\n        lastname: lastname,\n        context: context,\n      );\n}\n```\n\n### File\n\nWriting Minecrafts functions this style also becomes really easy. Just annotate a Widget variable that should be inside of your function with `@Func()`:\n\n```dart\n@Func()\nfinal Widget load = HelloWorld();\n```\n\nThis again would read the variable name `load` and generate a new variable called `LoadFile`, which includes the File Widget:\n\n```dart\nfinal File LoadFile = File(\n  '/load',\n  child: load,\n);\n```\n\nInside the parentheses of `@Func()` you can also provide various parameters to customize the file generation:\n\n| @Func   |                                                                          |\n| ------- | ------------------------------------------------------------------------ |\n| name    | Provide a custom filename different from the variable name               |\n| path    | Give a custom path for your function                                     |\n| execute | whether to execute your File(when included somewhere in the widget tree) |\n| create  | whether to actually create the file or not                               |\n\n**Example:**\n\n```dart\n@Func(\n  name: 'main',\n  path: 'folder',\n  execute: false,\n  create: true,\n)\nfinal Widget main_widget = Comment('main file');\n```\n\n### Pack\n\nThe `@Pck()` annotation works similar to @Func. You annotate a File List variable and it generates a Widget for this Pack.\n\n| @Pck |                           |\n| ---- | ------------------------- |\n| name | namespace of this pack    |\n| main | path of the main function |\n| load | path of the load function |\n\nIf you decide to not provide a namespace it again chooses your variable name.\n\n**Example:**\n\n```dart\n@Pck(name: 'namespace', main: 'main', load: 'load')\nfinal List\u003cFile\u003e myPack = [\n  LoadFile,\n  MainFile,\n];\n```\n\nThis generates this widget:\n\n```dart\nclass NamespacePack extends Widget {\n  @override\n  Widget generate(Context context) =\u003e Pack(\n        name: 'namespace',\n        files: myPack,\n        load: File('load', create: false),\n        main: File('main', create: false),\n      );\n}\n```\n\n### Project\n\nAnd the last piece of creating a datapack is a `@Prj`. This can automatically generate a main function with all necessary pieces to actually generate all packs and files.\n\n| @Prj        |                                                                                                   |\n| ----------- | ------------------------------------------------------------------------------------------------- |\n| name        | Name of the datapack                                                                              |\n| version     | targeted minecraft version(as integer)                                                            |\n| target      | directory to generate the datapack in                                                             |\n| description | a description for the pack.mcdata                                                                 |\n| genMain     | set this to false if you dont want a main function generated(will be generate\\_[varname] instead) |\n\nOnce again we must annotate a Widget variable, that is the root of our widget tree:\n\n```dart\n@Prj(\n  name: 'My awesome Datapack',\n  target: './datapacks/',\n  version: 17,\n  description: 'A simple dp for demonstrating annotations',\n)\nfinal myProject = NamespacePack();\n```\n\nThis generates the following in the `g.dart`:\n\n```dart\nvoid main([List\u003cString\u003e args = const []]) =\u003e createProject(\n      Project(\n        name: 'My awesome Datapack',\n        target: './datapacks/',\n        version: 17,\n        description: 'A simple dp for demonstrating annotations',\n        generate: myProject,\n      ),\n      args,\n    );\n```\n\n### Full example\n\nAnd thats it, you can now make an entire datapack in one objD file just with some functions and variables. Of course you can extend this principle to as many dart files as you like and make your datapack as complex and modular as you like.\n\nYou can see the full example [here](https://pub.dev/packages/objd_gen/example).\n\nI hope these code generators help with making datapacks using objD. In case you encounter any problems or have any idea or feedback, feel free to reach out via [Discord](https://discord.gg/WvtCkyg) or [Email](mailto://contact@stevertus.com).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstevertus%2Fobjd_gen","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstevertus%2Fobjd_gen","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstevertus%2Fobjd_gen/lists"}