Skip to content

Commit

Permalink
UUID + scale and path fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Stevertus committed Jun 27, 2023
1 parent 9b048be commit 3da5882
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 10 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

## 0.4.5

- added UUID object to represent uuids consisting out of 4 integers
- changed TextComponent & Entity to be gson serializable, so you don't have to call toMap manually
- fixed function tags load/tick generating with paths with `.mcfunction`
- fixed Storage.copyScore ignoring the scale parameter
- fixed Github testing workflows to run with Dart 3

## 0.4.5

- added new Time object for dealing with ticks, seconds, days and infinite Duration
- added time extensions to number allowing to write `10.seconds`, `2.ticks`, `2.4.minutes` etc. to generate time objects
- added FillBiome Widget
Expand Down
7 changes: 6 additions & 1 deletion example/files/load.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ class LoadFile extends Widget {

@override
Widget generate(Context context) {
return For.of([]);
return For.of([
Data.merge(Entity.All(), nbt: {
"uuid": UUID(1, 2, 3, 4),
'name': TextComponent('name'),
})
]);
}
}
13 changes: 10 additions & 3 deletions lib/src/basic/text_components.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// ignore_for_file: non_constant_identifier_names, constant_identifier_names

import 'package:objd/core.dart';
import 'package:objd/src/basic/command.dart';
import 'package:objd/src/basic/types/entity.dart';
import 'dart:convert';
Expand All @@ -8,7 +9,7 @@ import 'package:objd/src/basic/types/item.dart';
import 'package:objd/src/basic/types/location.dart';
import 'package:objd/src/basic/score.dart';

class TextComponent {
class TextComponent extends GsonValue {
late Map<String, dynamic> value;
Color? color;
bool? bold, underlined, strikethrough, obfuscated, italic;
Expand Down Expand Up @@ -310,10 +311,10 @@ class TextComponent {
value = {'selector': entity.toString()};
}

Map? toMap() {
Map<String, dynamic>? toMap() {
if (value.containsKey('text') && value['text'] == null) return null;

var ret = {};
var ret = <String, dynamic>{};
ret.addAll(value);
if (color != null) ret['color'] = color.toString();
if (bold != null) ret['bold'] = bold;
Expand All @@ -331,6 +332,12 @@ class TextComponent {
final m = toMap();
return m != null ? json.encode(m).replaceAll('\\[repl]\\', '\\') : null;
}

@override
String toString() => toJson() ?? '';

@override
Map<String, dynamic>? toSimple() => toMap();
}

/// Fires on left click, Part of TextComponent.
Expand Down
5 changes: 4 additions & 1 deletion lib/src/basic/types/entity.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ abstract class EntityClass {
String toString();
}

class Entity implements EntityClass {
class Entity extends GsonValue implements EntityClass {
@override
String selector;
Map arguments = {};
Expand Down Expand Up @@ -1156,6 +1156,9 @@ class Entity implements EntityClass {
}
return ret;
}

@override
String toSimple() => toString();
}

class Range {
Expand Down
15 changes: 15 additions & 0 deletions lib/src/basic/types/item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -366,3 +366,18 @@ Map<String, dynamic> _copyDeepMap(Map<String, dynamic>? map) {

return newMap;
}

class UUID extends GsonValue {
final int i1;
final int i2;
final int i3;
final int i4;

UUID(this.i1, this.i2, this.i3, this.i4);

@override
String toSimple() => toString();

@override
String toString() => '[I;$i1,$i2,$i3,$i4]';
}
4 changes: 2 additions & 2 deletions lib/src/build/build.dart
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,12 @@ Map<String, String> _getFiles(BuildProject prj, GenOptions options) {
// add load and main
if (pack.load != null && pack.load!.isNotEmpty && pack.isGenLoad) {
loadJson['values'].add(
'${pack.name}:${pack.load!.toString(false)}',
'${pack.name}:${pack.load!.toString(withExtension: false)}',
);
}
if (pack.main != null && pack.main!.isNotEmpty && pack.isGenMain) {
tickJson['values'].add(
'${pack.name}:${pack.main!.toString(false)}',
'${pack.name}:${pack.main!.toString(withExtension: false)}',
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/src/build/build_pack.dart
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class BuildPack {
// goes through all files (also considering added files while generating previous)
for (var i = 0; i < files.length; i++) {
final path = files.keys.toList()[i];
context.file = path.toString(false);
context.file = path.toString(withExtension: false);
files[path]!.generate(
context: context,
pack: this,
Expand Down
2 changes: 1 addition & 1 deletion lib/src/build/context.dart
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ class Path {
}

@override
String toString([bool withExtension = true]) => [
String toString({bool withExtension = true}) => [
...segments,
if (filename != null)
filename! + (withExtension ? '.${filetype ?? 'json'}' : ''),
Expand Down
3 changes: 2 additions & 1 deletion lib/src/utils/storage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ class Storage extends Widget {
Storage.copyScore(name,
autoNamespace: autoNamespace,
key: key,
scale: scale,
datatype: datatype,
score: score);

Expand Down Expand Up @@ -185,7 +186,7 @@ class Storage extends Widget {
target,
path: key!,
score: score,
scale: 1,
scale: scale,
datatype: datatype,
);
}
Expand Down

0 comments on commit 3da5882

Please sign in to comment.