Skip to content

Commit

Permalink
Return subcommands + Project supported formats
Browse files Browse the repository at this point in the history
  • Loading branch information
Stevertus committed Jan 5, 2024
1 parent e7a2951 commit 11010ff
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 8 deletions.
7 changes: 6 additions & 1 deletion lib/src/build/build.dart
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,12 @@ Map<String, String> _getFiles(BuildProject prj, GenOptions options) {
// create mcmeta
if (!options.minified && prj.isGenMeta) {
Map mcmeta = <String, dynamic>{
'pack': {'pack_format': prj.pack_format, 'description': prj.description}
'pack': {
'pack_format': prj.pack_format,
'description': prj.description,
if (prj.supportedFormats != null)
'supported_formats': prj.supportedFormats,

Check warning on line 98 in lib/src/build/build.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/build/build.dart#L94-L98

Added lines #L94 - L98 were not covered by tests
}
};
files['pack.mcmeta'] = json.encode(mcmeta);
}
Expand Down
2 changes: 2 additions & 0 deletions lib/src/build/build_project.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class BuildProject {
String name;
String description;
int pack_format;
List<int>? supportedFormats;
bool prod;
bool isGen = true;
bool isGenMeta = true;
Expand All @@ -22,6 +23,7 @@ class BuildProject {
name = prj.name,
description = prj.description,
pack_format = prj.getPackFormat(),
supportedFormats = prj.supportedFormats,

Check warning on line 26 in lib/src/build/build_project.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/build/build_project.dart#L26

Added line #L26 was not covered by tests
context = Context(prod: false, version: prj.version) {
packs = findPacks(prj.generate, context: context)
.map(
Expand Down
2 changes: 2 additions & 0 deletions lib/src/build/project.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class Project {
final String description;
final double version;
final int? packFormat;
final List<int>? supportedFormats;
Widget generate;

/// The project is a special Widget which is just defined once.
Expand All @@ -29,6 +30,7 @@ class Project {
this.version = 20.4,
this.target = './',
this.packFormat,
this.supportedFormats,
this.description = 'This is a datapack generated with objd by Stevertus',
});

Expand Down
13 changes: 8 additions & 5 deletions lib/src/wrappers/effect.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:objd/core.dart';

class Effect extends RestActionAble {
class Effect extends RestActionAble implements GsonValue {
EffectType? effect;
Entity? entity;

Expand Down Expand Up @@ -40,15 +40,18 @@ class Effect extends RestActionAble {

Map getMap() {
var ret = {};
if (effect != null) ret['Id'] = EffectType.values.indexOf(effect!) + 1;
ret['Amplifier'] = Byte(amplifier != null ? amplifier! - 1 : 0);
ret['Duration'] = duration != null ? duration!.ticks : 0;
ret['ShowParticles'] = Byte(
if (effect != null) ret['id'] = EffectType.values.indexOf(effect!) + 1;
ret['amplifier'] = Byte(amplifier != null ? amplifier! - 1 : 0);
ret['duration'] = duration != null ? duration!.ticks : 0;
ret['show_particles'] = Byte(

Check warning on line 46 in lib/src/wrappers/effect.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/wrappers/effect.dart#L43-L46

Added lines #L43 - L46 were not covered by tests
showParticles != null && showParticles! ? 1 : 0,
);
return ret;
}

@override
String toSimple() => gson.encode(getMap());

Check warning on line 53 in lib/src/wrappers/effect.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/wrappers/effect.dart#L52-L53

Added lines #L52 - L53 were not covered by tests

@override
Widget generate(Context context) {
if (_type == 'clear') {
Expand Down
20 changes: 19 additions & 1 deletion lib/src/wrappers/return.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,38 @@ import 'package:objd/core.dart';
/// Simple return command with integer return value
class Return extends Widget {
final int val;
final Widget? run;

/// Simple return command with integer return value
///
/// Can be used in conjunction with *File* and scores to calculate with the return value:
/// ```dart
/// Score(Entity.Self(),'test') << File('filename', child: Return(5));
/// ```
Return(this.val);
Return(this.val) : run = null;

/// Returns the result of a command
///
/// The provided Widget should just return a single command!
Return.run(Widget this.run) : val = 0;

/// Returns a failing state(success & value = 0)
Return.fail()
: val = 0,
run = Comment.LineBreak();

@override
Widget generate(Context context) {
if (context.version < 20) {
throw "Return requires at least version 20";
}
if (run != null) {
if (run case Comment(text: '')) return Command('return fail');
return Command(
'return run ${getCommands(run!.generate(context), context: context).first}',
);
}

return Command('return $val');
}
}
10 changes: 9 additions & 1 deletion test/simple_wrappers_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,15 @@ void main() {
);
});

command('Return', Return(30), "return 30");
group('Return', () {
command('integer', Return(30), "return 30");
command('fail', Return.fail(), "return fail");
command(
'run',
Return.run(Data.get(Entity.All(), path: 'path')),
"return run data get entity @a path",
);
});

group('Damage', () {
final e = Entity.All();
Expand Down

0 comments on commit 11010ff

Please sign in to comment.