Skip to content

Commit

Permalink
Json parser refactor.
Browse files Browse the repository at this point in the history
  • Loading branch information
cubism-dev committed Dec 20, 2018
1 parent be4d450 commit b5db751
Show file tree
Hide file tree
Showing 11 changed files with 290 additions and 165 deletions.
183 changes: 121 additions & 62 deletions Framework/cubismmodelsettingjson.ts

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions Framework/effect/cubismpose.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ export namespace Live2DCubismFramework
let root: Value = json.getRoot();

// フェード時間の指定
if(root.getMap().isExist(FadeIn))
if(!root.getValueByString(FadeIn).isNull())
{
ret._fadeTimeSeconds = root.getMap().getValue(FadeIn).toFloat(DefaultFadeInSeconds);
ret._fadeTimeSeconds = root.getValueByString(FadeIn).toFloat(DefaultFadeInSeconds);

if(ret._fadeTimeSeconds <= 0.0)
{
Expand All @@ -62,33 +62,33 @@ export namespace Live2DCubismFramework
}

// パーツグループ
let poseListInfo: Value = root.getMap().getValue(Groups);
let poseListInfo: Value = root.getValueByString(Groups);
const poseCount: number = poseListInfo.getSize();

for(let poseIndex: number = 0; poseIndex < poseCount; ++poseIndex)
{
let idListInfo: Value = poseListInfo.getVector().at(poseIndex);
let idListInfo: Value = poseListInfo.getValueByIndex(poseIndex);
const idCount: number = idListInfo.getSize();
let groupCount: number = 0;

for(let groupIndex: number = 0; groupIndex < idCount; ++groupIndex)
{
let partInfo: Value = idListInfo.getVector().at(groupIndex);
let partInfo: Value = idListInfo.getValueByIndex(groupIndex);
let partData: PartData = new PartData();
const parameterId: CubismIdHandle = CubismFramework.getIdManager().getId(partInfo.getMap().getValue(Id).getRawString());
const parameterId: CubismIdHandle = CubismFramework.getIdManager().getId(partInfo.getValueByString(Id).getRawString());

partData.partId = parameterId;

// リンクするパーツの設定
if(partInfo.getMap().isExist(Link))
if(!partInfo.getValueByString(Link).isNull())
{
let linkListInfo: Value = partInfo.getMap().getValue(Link);
let linkListInfo: Value = partInfo.getValueByString(Link);
const linkCount: number = linkListInfo.getSize();

for(let linkIndex: number = 0; linkIndex < linkCount; ++linkIndex)
{
let linkPart: PartData = new PartData();
const linkId: CubismIdHandle = CubismFramework.getIdManager().getId(linkListInfo.getVector().at(linkIndex).getString());
const linkId: CubismIdHandle = CubismFramework.getIdManager().getId(linkListInfo.getValueByIndex(linkIndex).getString());

linkPart.partId = linkId;

Expand Down
8 changes: 3 additions & 5 deletions Framework/live2dcubismframework.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,10 @@ export namespace Live2DCubismFramework
export class CubismFramework
{
/**
* @brief Cubism FrameworkのAPIを使用可能にする。<br>
* APIを実行する前に必ずこの関数を実行すること。<br>
* 引数に必ずメモリアロケータを渡してください。<br>
* 一度準備が完了して以降は、再び実行しても内部処理がスキップされます。
* Cubism FrameworkのAPIを使用可能にする。
* APIを実行する前に必ずこの関数を実行すること。
* 一度準備が完了して以降は、再び実行しても内部処理がスキップされます。
*
* @param allocator ICubismAllocatorクラスのインスタンス
* @param option Optionクラスのインスタンス
*
* @return 準備処理が完了したらtrueが返ります。
Expand Down
1 change: 1 addition & 0 deletions Framework/model/cubismmoc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* that can be found at http://live2d.com/eula/live2d-open-software-license-agreement_en.html.
*/

/// <reference path="../../Core/live2dcubismcore.d.ts" />
import {Live2DCubismFramework as cubismmodel} from "./cubismmodel";
import CubismModel = cubismmodel.CubismModel;
import { CSM_ASSERT } from "../utils/cubismdebug";
Expand Down
5 changes: 4 additions & 1 deletion Framework/model/cubismmodel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* that can be found at http://live2d.com/eula/live2d-open-software-license-agreement_en.html.
*/

/// <reference path="../../Core/live2dcubismcore" />
/// <reference path="../../Core/live2dcubismcore.d.ts" />
import {Live2DCubismFramework as cubismrenderer} from "../rendering/cubismrenderer";
import {Live2DCubismFramework as cubismid} from "../id/cubismid";
import {Live2DCubismFramework as cubismframework} from "../live2dcubismframework";
Expand Down Expand Up @@ -722,6 +722,7 @@ export namespace Live2DCubismFramework
const parameterIds: string[] = this._model.parameters.ids;
const parameterCount: number = this._model.parameters.count;

this._parameterIds.prepareCapacity(parameterCount);
for(let i: number = 0; i < parameterCount; ++i)
{
this._parameterIds.pushBack(CubismFramework.getIdManager().getId(parameterIds[i]));
Expand All @@ -732,6 +733,7 @@ export namespace Live2DCubismFramework
const partIds: string[] = this._model.parts.ids;
const partCount: number = this._model.parts.count;

this._partIds.prepareCapacity(partCount);
for(let i: number = 0; i < partCount; ++i)
{
this._partIds.pushBack(CubismFramework.getIdManager().getId(partIds[i]));
Expand All @@ -742,6 +744,7 @@ export namespace Live2DCubismFramework
const drawableIds: string[] = this._model.drawables.ids;
const drawableCount: number = this._model.drawables.count;

this._drawableIds.prepareCapacity(drawableCount);
for(let i: number = 0; i < drawableCount; ++i)
{
this._drawableIds.pushBack(CubismFramework.getIdManager().getId(drawableIds[i]));
Expand Down
10 changes: 5 additions & 5 deletions Framework/model/cubismmodeluserdatajson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export namespace Live2DCubismFramework
*/
public getUserDataCount(): number
{
return this._json.getRoot().getMap().getValue(Meta).getMap().getValue(UserDataCount).toInt();
return this._json.getRoot().getValueByString(Meta).getValueByString(UserDataCount).toInt();
}

/**
Expand All @@ -59,7 +59,7 @@ export namespace Live2DCubismFramework
*/
public getTotalUserDataSize(): number
{
return this._json.getRoot().getMap().getValue(Meta).getMap().getValue(TotalUserDataSize).toInt();
return this._json.getRoot().getValueByString(Meta).getValueByString(TotalUserDataSize).toInt();
}

/**
Expand All @@ -69,7 +69,7 @@ export namespace Live2DCubismFramework
*/
public getUserDataTargetType(i: number): string
{
return this._json.getRoot().getMap().getValue(UserData).getVector().at(i).getMap().getValue(Target).getRawString();
return this._json.getRoot().getValueByString(UserData).getValueByIndex(i).getValueByString(Target).getRawString();
}

/**
Expand All @@ -80,7 +80,7 @@ export namespace Live2DCubismFramework
*/
public getUserDataId(i: number): CubismIdHandle
{
return CubismFramework.getIdManager().getId(this._json.getRoot().getMap().getValue(UserData).getVector().at(i).getMap().getValue(Id).getRawString());
return CubismFramework.getIdManager().getId(this._json.getRoot().getValueByString(UserData).getValueByIndex(i).getValueByString(Id).getRawString());
}

/**
Expand All @@ -91,7 +91,7 @@ export namespace Live2DCubismFramework
*/
public getUserDataValue(i: number): string
{
return this._json.getRoot().getMap().getValue(UserData).getVector().at(i).getMap().getValue(Value).getRawString();
return this._json.getRoot().getValueByString(UserData).getValueByIndex(i).getValueByString(Value).getRawString();
}

private _json: CubismJson;
Expand Down
29 changes: 10 additions & 19 deletions Framework/motion/cubismexpressionmotion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,42 +55,33 @@ export namespace Live2DCubismFramework

let json: CubismJson = CubismJson.create(buffer, size);
let root: Value = json.getRoot();

// typescriptではnullを許容していないため仮の値を入れる
if(root.getMap().getValue(ExpressionKeyFadeIn) == null)
{
root.getMap().setValue(ExpressionKeyFadeIn, new JsonFloat(DefaultFadeTime));
}
if(root.getMap().getValue(ExpressionKeyFadeOut) == null)
{
root.getMap().setValue(ExpressionKeyFadeOut, new JsonFloat(DefaultFadeTime));
}

expression.setFadeInTime(root.getMap().getValue(ExpressionKeyFadeIn).toFloat(DefaultFadeTime)); // フェードイン
expression.setFadeOutTime(root.getMap().getValue(ExpressionKeyFadeOut).toFloat(DefaultFadeTime)); // フェードアウト
expression.setFadeInTime(root.getValueByString(ExpressionKeyFadeIn).toFloat(DefaultFadeTime)); // フェードイン
expression.setFadeOutTime(root.getValueByString(ExpressionKeyFadeOut).toFloat(DefaultFadeTime)); // フェードアウト

// 各パラメータについて
const parameterCount = root.getMap().getValue(ExpressionKeyParameters).getSize();
const parameterCount = root.getValueByString(ExpressionKeyParameters).getSize();
expression._parameters.prepareCapacity(parameterCount);

for(let i: number = 0; i < parameterCount; ++i)
{
let param: Value = root.getMap().getValue(ExpressionKeyParameters).getVector().at(i);
const parameterId: CubismIdHandle = CubismFramework.getIdManager().getId(param.getMap().getValue(ExpressionKeyId).getRawString()); // パラメータID
let param: Value = root.getValueByString(ExpressionKeyParameters).getValueByIndex(i);
const parameterId: CubismIdHandle = CubismFramework.getIdManager().getId(param.getValueByString(ExpressionKeyId).getRawString()); // パラメータID

const value: number = param.getMap().getValue(ExpressionKeyValue).toFloat(); // 値
const value: number = param.getValueByString(ExpressionKeyValue).toFloat(); // 値

// 計算方法の設定
let blendType: ExpressionBlendType;

if(param.getMap().getValue(ExpressionKeyBlend).isNull() || param.getMap().getValue(ExpressionKeyBlend).getString() == BlendValueAdd)
if(param.getValueByString(ExpressionKeyBlend).isNull() || param.getValueByString(ExpressionKeyBlend).getString() == BlendValueAdd)
{
blendType = ExpressionBlendType.ExpressionBlendType_Add;
}
else if(param.getMap().getValue(ExpressionKeyBlend).getString() == BlendValueMultiply)
else if(param.getValueByString(ExpressionKeyBlend).getString() == BlendValueMultiply)
{
blendType = ExpressionBlendType.ExpressionBlendType_Multiply;
}
else if(param.getMap().getValue(ExpressionKeyBlend).getString() == BlendValueOverwrite)
else if(param.getValueByString(ExpressionKeyBlend).getString() == BlendValueOverwrite)
{
blendType = ExpressionBlendType.ExpressionBlendType_Overwrite;
}
Expand Down
Loading

0 comments on commit b5db751

Please sign in to comment.