Skip to content

Commit

Permalink
Merge pull request #19 from Stevertus/null-safety
Browse files Browse the repository at this point in the history
Added Null safety
  • Loading branch information
Stevertus authored Mar 26, 2021
2 parents 618b680 + 8687349 commit 50ef9af
Show file tree
Hide file tree
Showing 117 changed files with 2,373 additions and 2,019 deletions.
14 changes: 0 additions & 14 deletions .packages

This file was deleted.

106 changes: 27 additions & 79 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,30 @@
## 0.4.0

- added Folder Widget to dynamically create folders. All Files and Rawfiles in the child marked with inheritFolder will choose this folder as a default
- added Textcomponent.none for the edge case that you want to clear a previous set text
- added predicate parameter to Selector
- added Scoreboard.modify(whoever uses that)
- added self, all and player getters on a Scoreboard to easily use the most common score entities
- added path argument to Context to retrieve the current path set by Folders
- added a check to help to not exceed the 16 char limit on scoreboards
- added additional metrics to measure project generation
- updated all blocks, items and particles to include additions in 21w11a
- migrated to null safety, read more here: https://dart.dev/null-safety
- refactored apis, arrangement of required values and nullable types
- refactored filepaths and path concatenation
- changed dependencies (removed meta and changed colorize to ansicolor)
- fixed Area generating NULL instead of 0 by default
- fixed triggering hotreload if only properties on project changed and refactored mechanics

You need at least Dart 1.12 for this version of objD and most likely have to migrate to null safety yourself (which is easy with the provided tools: https://dart.dev/go/null-safety-migration)

After doing so, ensure your version constaint is set to this to ensure all features are active:

```yaml
environment:
sdk: ">=2.12.0 <3.0.0"
```
## 0.3.6
- added Pose class and corresponding pose argument in ArmorStand
Expand Down Expand Up @@ -85,39 +112,6 @@ Thanks White Blizzard and Bonesdog for making suggestions for this version.

Thanks to kadmuffin for contributing and fixing typos!

## 0.3.3-beta.5

- added new 1.16 blocks, items, particles and entities
- added Spawnpoint Widget
- added Attribute Widget
- added Score.setToWidget to allow storing the result of Widgets in a Score
- added Attribute Type and an Attribute List to support Minecraft attributes
- added useTag argument in the If Widget to allow custom tags marking the else statement
- fixed missing increment for Ifs objd_is_true tag
- fixed if an else option is provided for If, encapsulate would not have an effect
- fixed crash when leaving the generate parameter of Project empty
- fixed bug with Trigger.enable
- fixed Do Widget to also execept null as translate parameter

## 0.3.3-beta.4

- updated Blocks, Items and Particles for 20w15a

## 0.3.3-beta.3

- fixed errors when trying to use gson component in a give command

## 0.3.3-beta.2

- updated Blocks, Items and Particles for 20w10a
- removed all deprecated and unessary parts

## 0.3.3-beta.1

- added an optional bool property to Slot.chest to support Enderchests
- fixed that Entity.not used to reset all previous applied tags
- updated Blocks, Items and Particles for 1.16

## 0.3.2

- added setToCondition to the Score to allow values based on a condition
Expand Down Expand Up @@ -155,52 +149,6 @@ Thanks to kadmuffin for contributing and fixing typos!
- fixed missing tags when using Condition.tag
- refactoring code

## 0.3.2-beta.4

- added a PassTrait widget, that uses the Context to provide Data across the successive widget tree
- added support for Dart Web, enabling online generators powered by objD
- added Zip Exporter that can be enabled with the --zip flag or by builing the project in production mode
- added --no-zip flag to allow usual file generation
- added an web example
- added getArchive and saveAsZip methods to manually create and modify the Zip encoder
- updated the gson library to also support Dart Web
- fixed that a score ignored the second parameter on an operation
- fixed that Execute.If generated nothing
- fixed missing tags when using Condition.tag
- fixed missing Particles export

## 0.3.2-beta.3

- added HideFlags method that calculates the hideFlags for you
- added getAllFiles and getJsonMap functions to allow 3rd party developers and the web to use objDs output
- added setToCondition to the Score to allow values based on a condition
- added an Item.SpawnEgg constructor to allow generating spawn eggs more quicker
- moved Block, ItemType, EntityType and ParticleTypes constants to seperate Blocks, Items, Entities and Particle classes
- moved the file generator to a new file seperating it from the system io
- fixed the conversionFlags parameter for TextComponents, accepts TextComponents now
- fixed crash when Scoreboard was used without any load File
- fixed Tag toggle wrong negation
- fixed text options with the conversionFlags in TextComponent.translate
- refactoring code

## 0.3.2-beta.2

- added Predicates subpackage, that allows to create all major types of predicates right in objD
- added Predicate Widget to register a new Predicate with content
- added VersionCheck and ServerVersionCheck
- added Storage.toData to convert to a Data Widget
- added global Scoreboard.prefix and Tag.prefix that get applied to all created Scoreboards and Tags
- added the [] operator to scoreboard to quickly retrieve its scores
- added Comment.seperate to generate a comment line
- added Comment.fileHeader to generate a file header with author, description, context and calledin
- added header field to File to be able to add a header to a file directly
- added Spectate and Gamemode Widgets
- updated Condition.predicate and If to allow for Predicates(and automatically register them)
- updated Block class to allow public insight into nbt and states
- changed If Then and Else to `then` and `orElse`, old syntax is deprecated
- extended the ForEach widget to support translation location for each step
- further code refactoring and formatting

## 0.3.1

- added Schedule.append, Schedule.appendFile and ScheduleMode for the upcoming 1.15 release
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Open the pubspec.yaml file and add
```yaml
name: [unique_namespace]
dependencies:
objd: ^0.3.6
objd: ^0.4.0
```
Also remember to replace the `[unique_namespace]` with your own project name.
Expand Down
2 changes: 1 addition & 1 deletion analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ include: package:pedantic/analysis_options.yaml
analyzer:
exclude: [build/**]
strong-mode:
implicit-casts: false
implicit-casts: false
1 change: 1 addition & 0 deletions example/example.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// import the core of the framework:

import 'package:objd/core.dart';
// import the custom pack:
import './packs/examplePack.dart';
Expand Down
1 change: 1 addition & 0 deletions lib/annotations.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Export Annotation classes

export 'src/annotations/file.dart';
export 'src/annotations/widget.dart';
export 'src/annotations/pack.dart';
Expand Down
1 change: 1 addition & 0 deletions lib/core.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// all build functions

export 'src/build/build.dart';

// Annotations
Expand Down
34 changes: 15 additions & 19 deletions lib/custom_block.dart
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import 'package:meta/meta.dart';
import 'package:objd/core.dart';

/// This Module allows you to create infinite new blocks in the game. It works by providing a [block] and an [item] that acts as a model for the new block.
class CustomBlock extends Module {
String id;
String name;
String? name;
Block block;
Item item;
Item blockModel;
Widget main;
Widget onBreak;
Widget onPlaced;
Item? blockModel;
Widget? main;
Widget? onBreak;
Widget? onPlaced;
List<String> tags;
bool generatePack;
bool useItemFrame;
Expand Down Expand Up @@ -59,7 +58,7 @@ class CustomBlock extends Module {
CustomBlock(
this.id,
this.item, {
@required this.block,
required this.block,
this.blockModel,
this.main,
this.onBreak,
Expand All @@ -70,10 +69,7 @@ class CustomBlock extends Module {
this.name,
this.useItemFrame = false,
this.yOffset = 1,
}) : assert(id != null),
assert(block != null),
assert(item != null),
assert(
}) : assert(
item.getId().contains('spawn_egg'),
'You have to provide a spawn egg.',
);
Expand All @@ -89,26 +85,26 @@ class CustomBlock extends Module {
}
},
count: item.count ?? 1,
name: name != null ? TextComponent(name, italic: false) : null,
name: name != null ? TextComponent(name!, italic: false) : null,
);

Widget _setblock({Widget fireTimer}) {
Widget _setblock({Widget? fireTimer}) {
final headItem = (blockModel ?? item).copyWith(count: 1);
return For.of([
SetBlock(block, location: Location.here()),
Clear(
Entity.Player(gamemode: Gamemode.creative, distance: Range.to(6)),
item.copyWith(count: 1),
),
useItemFrame != null && useItemFrame
useItemFrame
? Summon(
Entities.item_frame,
location: Location.rel(y: yOffset),
tags: ['objd_$id', ...tags],
nbt: {
'Invisible': 1,
'Fixed': 1,
'Item': headItem.copyWith(name: TextComponent(null)).getMap(),
'Item': headItem.copyWith(name: TextComponent.none()).getMap(),
'Facing': 1,
'Invulnerable': 1,
},
Expand All @@ -119,11 +115,11 @@ class CustomBlock extends Module {
head: headItem,
),
onPlaced,
if (fire != null && fire) fireTimer,
if (fire) fireTimer,
]);
}

Widget _blockLogic({Widget onbreak}) => For.of([
Widget _blockLogic({required Widget onbreak}) => For.of([
If(
Condition.and([
Condition(Entity.Player(distance: Range.to(6))),
Expand Down Expand Up @@ -157,8 +153,8 @@ class CustomBlock extends Module {

@override
Widget generate(Context context) {
assert(id != null && id.isNotEmpty);
assert(block != null && block.toString().isNotEmpty);
assert(id.isNotEmpty);
assert(block.toString().isNotEmpty);

final path = generatePack ? '' : 'objd_blocks/$id';

Expand Down
11 changes: 6 additions & 5 deletions lib/src/annotations/file.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
/// Writing Minecrafts functions annotations becomes really easy. Just annotate a Widget variable that should be inside of your function with `@Func()`:
class Func {
final String name;
final String path;
final String pack;
final bool execute;
final bool create;
final String? name;
final String? path;
final String? pack;
final bool? execute;
final bool? create;

/// Writing Minecrafts functions annotations becomes really easy. Just annotate a Widget variable that should be inside of your function with `@Func()`:
/// ```dart
Expand Down
7 changes: 4 additions & 3 deletions lib/src/annotations/pack.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/// The `@Pck()` annotation works similar to @Func. You annotate a File List variable and it generates a Widget for this Pack.
class Pck {
final String name;
final String main;
final String load;
final String? name;
final String? main;
final String? load;

/// The `@Pck()` annotation works similar to @Func. You annotate a File List variable and it generates a Widget for this Pack.
///
Expand Down
11 changes: 6 additions & 5 deletions lib/src/annotations/project.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
/// This can automatically generate a main function with all necessary pieces to actually generate all packs and files.
class Prj {
final String name;
final int version;
final String target;
final String description;
final String? name;
final int? version;
final String? target;
final String? description;
final bool genMain;

/// This can automatically generate a main function with all necessary pieces to actually generate all packs and files.
Expand All @@ -30,5 +31,5 @@ class Prj {
this.target,
this.description,
this.genMain = true,
}) : assert(genMain != null);
});
}
1 change: 1 addition & 0 deletions lib/src/annotations/widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
/// Log('Hello $name $lastname!'),
///]);
///```
const Wdg = WidgetAnnotation();

/// Writing a Widget becomes much simpler with the `@WidgetAnnotation()` 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.
Expand Down
18 changes: 9 additions & 9 deletions lib/src/basic/command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import 'package:objd/src/basic/text.dart';
import 'package:objd/src/basic/for_list.dart';

class CommandList<T> extends RestActionAble {
List<Command> _commands;
late List<Command> _commands;

/// There is a more efficient way to list raw Minecraft commands.
///
Expand All @@ -28,14 +28,14 @@ class CommandList<T> extends RestActionAble {
throw ('Please insert a string or a list into CommandList');
}
}
CommandList.str(String str) {
_commands = str
.replaceAll(RegExp(r'[ \t]{2,}'), '')
.split('\n')
.where((i) => i.isNotEmpty && i != ' ')
.map((x) => Command(x))
.toList();
}
CommandList.str(String str)
: _commands = str
.replaceAll(RegExp(r'[ \t]{2,}'), '')
.split('\n')
.where((i) => i.isNotEmpty && i != ' ')
.map((x) => Command(x))
.toList();

@override
Widget generate(Context context) {
return For.of(_commands);
Expand Down
Loading

0 comments on commit 50ef9af

Please sign in to comment.