From 5e376ad86a80705395e2acd98c8c1c156f12a82e Mon Sep 17 00:00:00 2001 From: yuko fuyutsuki Date: Sat, 27 Mar 2021 00:33:59 +0900 Subject: [PATCH] More property {ft.texts} FloatingTextObjectVariable * Update README --- .github/readme/ja_jp.md | 4 +- README.md | 6 +-- .../variable/FloatingTextObjectVariable.php | 39 ++++++++++++------- 3 files changed, 29 insertions(+), 20 deletions(-) diff --git a/.github/readme/ja_jp.md b/.github/readme/ja_jp.md index ee735e4..30388bc 100644 --- a/.github/readme/ja_jp.md +++ b/.github/readme/ja_jp.md @@ -49,7 +49,7 @@ Texterは複数ワールドに対応した、FloatingText(浮き文字)の追加 #### 変数 -[Mineflow >= 1.3](https://poggit.pmmp.io/p/Mineflow)を導入している場合、浮き文字に変数を適用することが出来ます。 +[Mineflow >= 2.0](https://poggit.pmmp.io/p/Mineflow)を導入している場合、浮き文字に変数を適用することが出来ます。 |変数名|型|使用できるプロパティ| |:----|:-|:----------------| @@ -57,7 +57,7 @@ Texterは複数ワールドに対応した、FloatingText(浮き文字)の追加 |`microtime`|number|| |`time`|string|| |`date`|string|| -|`default_level`|string|| +|`default_world`|string|| |`player`|Player|[Mineflow#Player](https://github.com/aieuo/Mineflow#player)| |`ft`|FloatingText|`name(string), pos(Position), spacing(Position)`| diff --git a/README.md b/README.md index a348b10..f6a5b63 100644 --- a/README.md +++ b/README.md @@ -49,15 +49,15 @@ All commands have permissions set to `texter.command.txt` (OP only). #### Variables -If you have installed [Mineflow >= 1.3](https://poggit.pmmp.io/p/Mineflow), you can apply variables to floating characters. +If you have installed [Mineflow >= 2.0](https://poggit.pmmp.io/p/Mineflow), you can apply variables to floating characters. |name|type|available properties| |:----|:-|:----------------| |`server_name`|string|| |`microtime`|number|| |`time`|string|| -|`date`|string|||`default_level`|string -|`default_level`|string||||`player`|Player +|`date`|string|| +|`default_world`|string|| |`player`|Player|[Mineflow#Player](https://github.com/aieuo/Mineflow#player)| |`ft`|FloatingText|`name(string), pos(Position without world), spacing(Position without world)`| diff --git a/src/jp/mcbe/fuyutsuki/Texter/mineflow/variable/FloatingTextObjectVariable.php b/src/jp/mcbe/fuyutsuki/Texter/mineflow/variable/FloatingTextObjectVariable.php index 6abbae1..2b83a70 100644 --- a/src/jp/mcbe/fuyutsuki/Texter/mineflow/variable/FloatingTextObjectVariable.php +++ b/src/jp/mcbe/fuyutsuki/Texter/mineflow/variable/FloatingTextObjectVariable.php @@ -5,12 +5,12 @@ namespace jp\mcbe\fuyutsuki\Texter\mineflow\variable; use aieuo\mineflow\variable\DummyVariable; -use aieuo\mineflow\variable\object\PositionObjectVariable; +use aieuo\mineflow\variable\ListVariable; +use aieuo\mineflow\variable\object\Vector3ObjectVariable; use aieuo\mineflow\variable\ObjectVariable; use aieuo\mineflow\variable\StringVariable; use aieuo\mineflow\variable\Variable; use jp\mcbe\fuyutsuki\Texter\text\FloatingTextCluster; -use pocketmine\level\Position; /** * Class FloatingTextObjectVariable @@ -20,25 +20,33 @@ class FloatingTextObjectVariable extends ObjectVariable { public const DEFAULT_NAME = "ft"; - public const PROPERTY_NAME = "name"; public const PROPERTY_POSITION = "pos"; + public const PROPERTY_NAME = "name"; public const PROPERTY_SPACING = "spacing"; + public const PROPERTY_TEXTS = "texts"; - public function __construct(FloatingTextCluster $floatingText, string $name = self::DEFAULT_NAME, ?string $str = null) { - parent::__construct($floatingText, $name, $str); + public function __construct(FloatingTextCluster $floatingTextCluster, ?string $str = null) { + parent::__construct($floatingTextCluster, $str); } public function getValueFromIndex(string $index): ?Variable { - $floatingText = $this->floatingText(); + $floatingTextCluster = $this->floatingText(); switch ($index) { + case self::PROPERTY_POSITION: + $variable = new Vector3ObjectVariable($floatingTextCluster->position(), self::PROPERTY_POSITION); + break; case self::PROPERTY_NAME: - $variable = new StringVariable($floatingText->name(), self::PROPERTY_NAME); + $variable = new StringVariable($floatingTextCluster->name()); break; - case self::PROPERTY_POSITION:// TODO: Mineflow should implements Vector3ObjectVariable - $variable = new PositionObjectVariable(Position::fromObject($floatingText->position()), self::PROPERTY_POSITION); + case self::PROPERTY_SPACING: + $variable = new Vector3ObjectVariable($floatingTextCluster->spacing(), self::PROPERTY_SPACING); break; - case self::PROPERTY_SPACING:// TODO: Mineflow should implements Vector3ObjectVariable - $variable = new PositionObjectVariable(Position::fromObject($floatingText->spacing()), self::PROPERTY_SPACING); + case self::PROPERTY_TEXTS: + $texts = []; + foreach ($floatingTextCluster->all() as $floatingText) { + $texts[] = new StringVariable($floatingText->text()); + } + $variable = new ListVariable($texts, self::PROPERTY_TEXTS); break; default: $variable = null; @@ -52,11 +60,12 @@ public function floatingText(): FloatingTextCluster { return $value; } - public static function getValuesDummy(string $name): array { + public static function getValuesDummy(): array { return [ - new DummyVariable("{$name}." . self::PROPERTY_NAME, DummyVariable::STRING), - new DummyVariable("{$name}." . self::PROPERTY_POSITION, DummyVariable::POSITION), - new DummyVariable("{$name}." . self::PROPERTY_SPACING, DummyVariable::POSITION) + self::PROPERTY_POSITION => new DummyVariable(DummyVariable::VECTOR3), + self::PROPERTY_NAME => new DummyVariable(DummyVariable::STRING), + self::PROPERTY_SPACING => new DummyVariable(DummyVariable::VECTOR3), + self::PROPERTY_TEXTS => new DummyVariable(DummyVariable::LIST), ]; }