From 0ceff1c8f928f0c1960eedbde8d50002abd73e09 Mon Sep 17 00:00:00 2001 From: Jun Koyama Date: Sat, 26 Jun 2021 16:55:48 +0900 Subject: [PATCH 1/4] Fix returing value on out of index args --- src/motion/cubismmotionjson.ts | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/motion/cubismmotionjson.ts b/src/motion/cubismmotionjson.ts index eace15b..ee55db0 100644 --- a/src/motion/cubismmotionjson.ts +++ b/src/motion/cubismmotionjson.ts @@ -8,6 +8,7 @@ import { CubismIdHandle } from '../id/cubismid'; import { CubismFramework } from '../live2dcubismframework'; import { csmString } from '../type/csmstring'; +import { csmVector } from '../type/csmvector'; import { CubismJson } from '../utils/cubismjson'; // JSON keys @@ -225,12 +226,12 @@ export class CubismMotionJson { * @return false 存在しない */ public isExistMotionCurveFadeInTime(curveIndex: number): boolean { - return !this._json + const value = this._json .getRoot() .getValueByString(Curves) .getValueByIndex(curveIndex) - .getValueByString(FadeInTime) - .isNull(); + .getValueByString(FadeInTime); + return !(value.isNull() || value.isError()); } /** @@ -240,12 +241,12 @@ export class CubismMotionJson { * @return false 存在しない */ public isExistMotionCurveFadeOutTime(curveIndex: number): boolean { - return !this._json + const value = this._json .getRoot() .getValueByString(Curves) .getValueByIndex(curveIndex) - .getValueByString(FadeOutTime) - .isNull(); + .getValueByString(FadeOutTime); + return !(value.isNull() || value.isError()); } /** @@ -287,7 +288,7 @@ export class CubismMotionJson { .getValueByString(Curves) .getValueByIndex(curveIndex) .getValueByString(Segments) - .getVector() + .getVector(new csmVector()) .getSize(); } From 8040d3fc6ba8af9be839cfa97d0abfb5aa6ac2fb Mon Sep 17 00:00:00 2001 From: Jun Koyama Date: Sat, 26 Jun 2021 20:28:56 +0900 Subject: [PATCH 2/4] Initialize default error value --- src/utils/cubismjson.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/utils/cubismjson.ts b/src/utils/cubismjson.ts index 93a41a3..c05d33d 100644 --- a/src/utils/cubismjson.ts +++ b/src/utils/cubismjson.ts @@ -195,6 +195,7 @@ export abstract class Value { JsonError.errorValue = new JsonError('ERROR', true); this.nullValue = new JsonNullvalue(); + this.errorValue = new JsonError('ERROR', true); Value.s_dummyKeys = new csmVector(); } From bec7c21ac4be0e87b7e916cacedac085b264c7d0 Mon Sep 17 00:00:00 2001 From: Jun Koyama Date: Sat, 26 Jun 2021 22:41:25 +0900 Subject: [PATCH 3/4] Polish implementation --- src/motion/cubismmotionjson.ts | 15 +++++++-------- src/utils/cubismjson.ts | 25 ++++++++++++------------- 2 files changed, 19 insertions(+), 21 deletions(-) diff --git a/src/motion/cubismmotionjson.ts b/src/motion/cubismmotionjson.ts index ee55db0..eace15b 100644 --- a/src/motion/cubismmotionjson.ts +++ b/src/motion/cubismmotionjson.ts @@ -8,7 +8,6 @@ import { CubismIdHandle } from '../id/cubismid'; import { CubismFramework } from '../live2dcubismframework'; import { csmString } from '../type/csmstring'; -import { csmVector } from '../type/csmvector'; import { CubismJson } from '../utils/cubismjson'; // JSON keys @@ -226,12 +225,12 @@ export class CubismMotionJson { * @return false 存在しない */ public isExistMotionCurveFadeInTime(curveIndex: number): boolean { - const value = this._json + return !this._json .getRoot() .getValueByString(Curves) .getValueByIndex(curveIndex) - .getValueByString(FadeInTime); - return !(value.isNull() || value.isError()); + .getValueByString(FadeInTime) + .isNull(); } /** @@ -241,12 +240,12 @@ export class CubismMotionJson { * @return false 存在しない */ public isExistMotionCurveFadeOutTime(curveIndex: number): boolean { - const value = this._json + return !this._json .getRoot() .getValueByString(Curves) .getValueByIndex(curveIndex) - .getValueByString(FadeOutTime); - return !(value.isNull() || value.isError()); + .getValueByString(FadeOutTime) + .isNull(); } /** @@ -288,7 +287,7 @@ export class CubismMotionJson { .getValueByString(Curves) .getValueByIndex(curveIndex) .getValueByString(Segments) - .getVector(new csmVector()) + .getVector() .getSize(); } diff --git a/src/utils/cubismjson.ts b/src/utils/cubismjson.ts index c05d33d..d8097a0 100644 --- a/src/utils/cubismjson.ts +++ b/src/utils/cubismjson.ts @@ -74,7 +74,7 @@ export abstract class Value { /** * 要素をコンテナで返す(array) */ - public getVector(defaultValue?: csmVector): csmVector { + public getVector(defaultValue = new csmVector()): csmVector { return defaultValue; } @@ -192,11 +192,8 @@ export abstract class Value { public static staticInitializeNotForClientCall(): void { JsonBoolean.trueValue = new JsonBoolean(true); JsonBoolean.falseValue = new JsonBoolean(false); - - JsonError.errorValue = new JsonError('ERROR', true); - this.nullValue = new JsonNullvalue(); - this.errorValue = new JsonError('ERROR', true); - + Value.errorValue = new JsonError('ERROR', true); + Value.nullValue = new JsonNullvalue(); Value.s_dummyKeys = new csmVector(); } @@ -206,13 +203,7 @@ export abstract class Value { public static staticReleaseNotForClientCall(): void { JsonBoolean.trueValue = null; JsonBoolean.falseValue = null; - JsonError.errorValue = null; - Value.nullValue = null; - Value.s_dummyKeys = null; - - JsonBoolean.trueValue = null; - JsonBoolean.falseValue = null; - JsonError.errorValue = null; + Value.errorValue = null; Value.nullValue = null; Value.s_dummyKeys = null; } @@ -971,6 +962,14 @@ export class JsonNullvalue extends Value { return true; } + /** + * Valueにエラー値をセットする + */ + public setErrorNotForClientCall(s: string): Value { + this._stringBuffer = s; + return JsonError.nullValue; + } + /** * コンストラクタ */ From 4f1b9ffb3c17d29af9e5595805abebdbb12e50ec Mon Sep 17 00:00:00 2001 From: nakayasui Date: Tue, 27 Jul 2021 12:30:06 +0900 Subject: [PATCH 4/4] Update CHANGELOG.md --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index fdbbb2c..bb38e3a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). +## [Unreleased] + +### Fixed + +* Fix return correct error values for out-of-index arguments in cubismjson. + ## [4-r.3] - 2021-06-10