Skip to content

Commit

Permalink
optimized pull merge
Browse files Browse the repository at this point in the history
  • Loading branch information
Stevertus committed Jan 1, 2022
1 parent 3f5371b commit 66bb5cf
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 65 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

## 0.4.4

- added PlayerJoin.rejoin to only detect once joined players
- added version aware translation of barrier and light particles when setting version to 18
- added `--clean`(`-c`) option to easily remove all files and folders that would be generated by objD with the same options to easily clean junk
- added experimental Multithreading option `--useIsolates` for saving files, let me know if you see performance improvements using it
- added type property to `Score` to easily change scoreboard types and inherit right type from Scoreboard[] method
- updated enums to use latest Dart 2.15 features
- updated blocks and items to 1.18.1
- updated default version to 1.18, also changing pack format
- updated PlayerJoin to correctly handle initial joins as well(Thanks to SyntheticDev for the implementation)
- fixed `.mcfunction` extension appearing in Context's file path(used by File.recursive and others)
- fixed JsonFile not being exported
- fixed Team Widget wrongly generate seeFriendlyInvisible when seeInvisible is set
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ name: [unique_namespace]
environment:
sdk: ">=2.15.0 <3.0.0"
dependencies:
objd: ^0.4.3
objd: ^0.4.4
```
Also remember to replace the `[unique_namespace]` with your own project name.
Expand Down
23 changes: 17 additions & 6 deletions lib/src/basic/score.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,13 @@ class Score extends RestActionAble {
/// Score(Entity.Selected(),'score',addNew: true)
///```
Score(this.entity, this.score,
{bool addNew = true, List<Widget>? commands, this.type = 'dummy'}) {
Score(
this.entity,
this.score, {
bool addNew = true,
List<Widget>? commands,
this.type = 'dummy',
}) {
if (commands != null) _commands = commands;
if (addNew) {
_commands.add(
Expand All @@ -51,8 +56,11 @@ class Score extends RestActionAble {
/// Score.fromSelected('objective').set(3)
/// ⇒ scoreboard players set @s objective 3
/// ```
Score.fromSelected(this.score, {bool addNew = true, this.type = 'dummy'})
: entity = Entity.Self() {
Score.fromSelected(
this.score, {
bool addNew = true,
this.type = 'dummy',
}) : entity = Entity.Self() {
if (addNew) {
_commands.add(
Scoreboard(score, type: type),
Expand Down Expand Up @@ -82,8 +90,11 @@ class Score extends RestActionAble {
/// Score.con(5)
/// ⇒ scoreboard players set #5 objd_consts 5
/// ```
Score.con(int number, {bool addNew = true, this.type = 'dummy'})
: score = 'objd_consts',
Score.con(
int number, {
bool addNew = true,
this.type = 'dummy',
}) : score = 'objd_consts',
entity = Entity.PlayerName(
'#' + number.toString(),
) {
Expand Down
89 changes: 40 additions & 49 deletions lib/src/basic/scoreboard.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import 'package:objd/src/basic/widget.dart';
import 'package:objd/src/basic/command.dart';
import 'package:objd/src/basic/text_components.dart';
import 'package:objd/src/basic/extend.dart';
import 'package:objd/src/basic/for_list.dart';
import 'package:objd/src/build/build.dart';
import 'package:objd/src/wrappers/comment.dart';

Expand All @@ -14,10 +13,9 @@ class Scoreboard extends RestActionAble {
static String? prefix;

late String subcommand;
final String subcommand;
String name;
late String type;
bool? removeOld;
bool? useHearts;

/// A scoreboard objective holds values, kind a like a Variable inside Minecraft.
Expand All @@ -30,62 +28,62 @@ class Scoreboard extends RestActionAble {
this.type = 'dummy',
TextComponent? display,
bool addIntoLoad = true,
bool removeOld = false,
}) {
subcommand = addIntoLoad ? 'add' : 'addHere';
}) : subcommand = addIntoLoad ? 'add' : 'addHere' {
if (display != null) type += ' ' + display.toJson()!;
prefixName();
}

/// The `Scoreboard.click` constructor adds a carrot on a stick click event objective
Scoreboard.click(
this.name, {
factory Scoreboard.click(
String name, {
TextComponent? display,
bool addIntoLoad = true,
bool removeOld = false,
}) {
type = 'minecraft.used:minecraft.carrot_on_a_stick';
subcommand = addIntoLoad ? 'add' : 'addHere';
if (display != null) type += ' ' + display.toJson()!;
prefixName();
}
}) =>
Scoreboard(
name,
type: 'minecraft.used:minecraft.carrot_on_a_stick',
display: display,
addIntoLoad: addIntoLoad,
);

/// The `Scoreboard.click` constructor adds a carrot on a stick click event objective
Scoreboard.villager(
this.name, {
factory Scoreboard.villager(
String name, {
TextComponent? display,
bool addIntoLoad = true,
bool removeOld = false,
}) {
type = 'minecraft.custom:minecraft.talked_to_villager';
subcommand = addIntoLoad ? 'add' : 'addHere';
if (display != null) type += ' ' + display.toJson()!;
prefixName();
}
}) =>
Scoreboard(
name,
type: 'minecraft.custom:minecraft.talked_to_villager',
display: display,
addIntoLoad: addIntoLoad,
);

/// The `Scoreboard.trigger` constructor adds a trigger objective
Scoreboard.trigger(
this.name, {
factory Scoreboard.trigger(
String name, {
TextComponent? display,
bool addIntoLoad = true,
bool removeOld = false,
}) {
type = 'trigger';
subcommand = addIntoLoad ? 'add' : 'addHere';
if (display != null) type += ' ' + display.toJson()!;
prefixName();
}
}) =>
Scoreboard(
name,
type: 'trigger',
display: display,
addIntoLoad: addIntoLoad,
);

/// The `Scoreboard.add` constructor does exactly the same as Scoreboard but puts the result without checking in the current file.
Scoreboard.add(this.name, {this.type = 'dummy', TextComponent? display}) {
subcommand = 'addHere';
Scoreboard.add(this.name, {this.type = 'dummy', TextComponent? display})
: subcommand = 'addHere' {
if (display != null) type += ' ' + display.toJson()!;
prefixName();
}

/// `Scoreboard.remove` removes an objective by its name again.
Scoreboard.remove(this.name) {
subcommand = 'remove';
Scoreboard.remove(this.name) : subcommand = 'remove' {
prefixName();
}

Expand All @@ -96,9 +94,9 @@ class Scoreboard extends RestActionAble {
/// |String|name of the objective(required)|
/// |display|String for display location (default = sidebar)|
Scoreboard.setdisplay(this.name, {String display = 'sidebar'}) {
subcommand = 'setdisplay';
type = display;
Scoreboard.setdisplay(this.name, {String display = 'sidebar'})
: subcommand = 'setdisplay',
type = display {
prefixName();
}
Scoreboard.modify(
Expand All @@ -119,22 +117,15 @@ class Scoreboard extends RestActionAble {
);
}

List<Command> commands = [];
if (removeOld != null && removeOld!) {
commands.add(Command('scoreboard objectives remove $name'));
}

switch (subcommand) {
case 'add':
commands.add(Command('scoreboard objectives add $name $type'));
return Extend(
context.loadFile ?? 'load',
child: CommandList(commands),
child: Command('scoreboard objectives add $name $type'),
first: true,
);
case 'addHere':
commands.add(Command('scoreboard objectives add $name $type'));
return CommandList(commands);
return Command('scoreboard objectives add $name $type');
case 'remove':
return Command('scoreboard objectives remove $name');
case 'modify':
Expand All @@ -157,13 +148,13 @@ class Scoreboard extends RestActionAble {
}

/// Scoreboard.self is a shortcut for Scoreboard[Entity.Self()]
Score get self => Score(Entity.Self(), name, addNew: false);
Score get self => Score(Entity.Self(), name);

/// Scoreboard.all is a shortcut for Scoreboard[Entity.All()]
Score get all => Score(Entity.All(), name, addNew: false);
Score get all => Score(Entity.All(), name);

/// Scoreboard.player is a shortcut for Scoreboard[Entity.Player()]
Score get player => Score(Entity.Player(), name, addNew: false);
Score get player => Score(Entity.Player(), name);

@override
Map toMap() {
Expand Down
20 changes: 11 additions & 9 deletions lib/src/utils/player_join.dart
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,19 @@ class PlayerJoin extends Widget {
return For.of([
s,
// This will only pass if the player doesn't have the score (the score cannot be below 0), therefore triggering on first join
Execute.as(t, children: [
If.not(Condition.score(self >= 0), then: [
then!,
self >> 0,
])
]),
Execute.as(
t.copyWith(scores: [self > 0]),
t,
children: [
then!,
self >> 0,
If(
Condition.or([
Condition.not(self >= 0),
self > 0,
]),
then: [
then!,
self >> 0,
],
)
],
)
]);
Expand Down

0 comments on commit 66bb5cf

Please sign in to comment.