Skip to content

Commit

Permalink
Merge pull request #21 from Live2D/feature/activate_log
Browse files Browse the repository at this point in the history
Activate log.
  • Loading branch information
itoh-at-live2d-com authored Jan 16, 2019
2 parents 102eda3 + 0ae2767 commit 38fb3ba
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 65 deletions.
72 changes: 48 additions & 24 deletions Framework/live2dcubismframework.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 cubismjson} from "./utils/cubismjson";
import {Live2DCubismFramework as cubismidmanager} from "./id/cubismidmanager";
import {Live2DCubismFramework as cubismrenderer} from "./rendering/cubismrenderer";
Expand Down Expand Up @@ -98,32 +99,37 @@ export namespace Live2DCubismFramework
{
if(s_isStarted)
{
CubismLogInfo("CubismFramework::StartUp() is already done.");
CubismLogInfo("CubismFramework.startUp() is already done.");
return s_isStarted;
}

s_option = option;

if(s_option != null)
{
// TODO Core::csmSetLogFunction(s_option->LogFunction);
Live2DCubismCore.Logging.csmSetLogFunction(s_option.logFunction);
}

s_isStarted = true;

// Live2D Cubism Coreバージョン情報を表示
if(s_isStarted)
{
const version: number = 1; // TODO Core::csmGetVersion()
const version: number = Live2DCubismCore.Version.csmGetVersion();
const major: number = ((version & 0xFF000000) >> 24);
const minor: number = ((version & 0x00FF0000) >> 16);
const patch: number = ((version & 0x0000FFFF));
const versionNumber: number = version;

CubismLogInfo("Live2D Cubism Core version: %02d.%02d.%04d (%d)", major, minor, patch, versionNumber);
CubismLogInfo(`Live2D Cubism Core version: {0}.{1}.{2} ({3})`,
('00' + major).slice(-2),
('00' + minor).slice(-2),
('0000' + patch).slice(-4),
versionNumber
);
}

CubismLogInfo("CubismFramework::StartUp() is complete.");
CubismLogInfo("CubismFramework.startUp() is complete.");

return s_isStarted;
}
Expand Down Expand Up @@ -158,7 +164,7 @@ export namespace Live2DCubismFramework
// 再度Initialize()するには先にDispose()を実行する必要がある。
if (s_isInitialized)
{
CubismLogWarning("CubismFramework::Initialize() skipped, already initialized.");
CubismLogWarning("CubismFramework.initialize() skipped, already initialized.");
return;
}

Expand All @@ -169,7 +175,7 @@ export namespace Live2DCubismFramework

s_isInitialized = true;

CubismLogInfo("CubismFramework::Initialize() is complete.");
CubismLogInfo("CubismFramework.initialize() is complete.");
}

/**
Expand All @@ -190,7 +196,7 @@ export namespace Live2DCubismFramework
// dispose()するには先にinitialize()を実行する必要がある。
if(!s_isInitialized) // false...リソース未確保の場合
{
CubismLogWarning("CubismFramework::Dispose() skipped, not initialized.");
CubismLogWarning("CubismFramework.dispose() skipped, not initialized.");
return;
}

Expand All @@ -204,23 +210,10 @@ export namespace Live2DCubismFramework

s_isInitialized = false;

CubismLogInfo("CubismFramework::Dispose() is complete.");
}

/**
* 現在のログ出力レベル設定の値を返す。
*
* @return 現在のログ出力レベル設定の値
*/
public static getLoggingLevel(): LogLevel
{
if (s_option != null)
{
return s_option.loggingLevel;
}
return LogLevel.LogLevel_Off;
CubismLogInfo("CubismFramework.dispose() is complete.");
}


/**
* Cubism FrameworkのAPIを使用する準備が完了したかどうか
* @return APIを使用する準備が完了していればtrueが返ります。
Expand All @@ -229,7 +222,7 @@ export namespace Live2DCubismFramework
{
return s_isStarted;
}

/**
* Cubism Frameworkのリソース初期化がすでに行われているかどうか
* @return リソース確保が完了していればtrueが返ります
Expand All @@ -239,6 +232,36 @@ export namespace Live2DCubismFramework
return s_isInitialized;
}

/**
* Core APIにバインドしたログ関数を実行する
*
* @praram message ログメッセージ
*/
public static coreLogFunction(message: string): void
{
// Return if logging not possible.
if(!Live2DCubismCore.Logging.csmGetLogFunction())
{
return;
}

Live2DCubismCore.Logging.csmGetLogFunction()(message);
}

/**
* 現在のログ出力レベル設定の値を返す。
*
* @return 現在のログ出力レベル設定の値
*/
public static getLoggingLevel(): LogLevel
{
if (s_option != null)
{
return s_option.loggingLevel;
}
return LogLevel.LogLevel_Off;
}

/**
* IDマネージャのインスタンスを取得する
* @return CubismManagerクラスのインスタンス
Expand All @@ -261,6 +284,7 @@ export namespace Live2DCubismFramework

export class Option
{
logFunction: Live2DCubismCore.csmLogFunction; // ログ出力の関数オブジェクト
loggingLevel: LogLevel; // ログ出力レベルの設定
}

Expand Down
56 changes: 27 additions & 29 deletions Framework/utils/cubismdebug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
* that can be found at http://live2d.com/eula/live2d-open-software-license-agreement_en.html.
*/

import {Live2DCubismFramework as live2dcubismframework, LogLevel} from "../live2dcubismframework";
import CubismFramework = live2dcubismframework.CubismFramework;
import { CSM_LOG_LEVEL, CSM_LOG_LEVEL_VERBOSE, CSM_LOG_LEVEL_DEBUG, CSM_LOG_LEVEL_INFO, CSM_LOG_LEVEL_WARNING, CSM_LOG_LEVEL_ERROR } from "../cubismframeworkconfig";
import {Live2DCubismFramework as cubismframework, LogLevel} from "../live2dcubismframework";
import {CSM_LOG_LEVEL, CSM_LOG_LEVEL_VERBOSE, CSM_LOG_LEVEL_DEBUG, CSM_LOG_LEVEL_INFO, CSM_LOG_LEVEL_WARNING, CSM_LOG_LEVEL_ERROR} from "../cubismframeworkconfig";

export const CubismLogPrint = (level: LogLevel, fmt: string, ... args: any[]) =>

export const CubismLogPrint = (level: LogLevel, fmt: string, args: any[]) =>
{
Live2DCubismFramework.CubismDebug.print(level, "[CSM]" + fmt, args);
}

export const CubismLogPrintIn = (level: LogLevel, fmt: string, ... args: any[]) =>
export const CubismLogPrintIn = (level: LogLevel, fmt: string, args: any[]) =>
{
CubismLogPrint(level, fmt + "\n", args);
}
Expand Down Expand Up @@ -133,32 +133,30 @@ export namespace Live2DCubismFramework
*
* @param logLevel ログレベルの設定
* @param format 書式付き文字列
* @param ... args 可変長引数
* @param args 可変長引数
*/
public static print(logLevel: LogLevel, format: string, ... args: any[]): void
public static print(logLevel: LogLevel, format: string, args?: any[]): void
{
// オプションで設定されたログ出力レベルを下回る場合はログに出さない
// if(logLevel < CubismFramework.getLoggingLevel())
// {
// return;
// }

// TODO
// const Core::csmLogFunction logPrint = CubismFramework::CoreLogFunction;

// if (!logPrint)
// return;

let buffer: string = format;
buffer = buffer.replace(
/\{(\d+)\}/g,
(m, k) => // m="{0}", k="0"
{
return args[k];
}
);

// logPrint(buffer);
if(logLevel < cubismframework.CubismFramework.getLoggingLevel())
{
return;
}

const logPrint: Live2DCubismCore.csmLogFunction = cubismframework.CubismFramework.coreLogFunction;

if (!logPrint)
return;

let buffer: string =
format.replace(
/\{(\d+)\}/g,
(m, k) =>
{
return args[k];
}
);
logPrint(buffer);
}

/**
Expand All @@ -175,7 +173,7 @@ export namespace Live2DCubismFramework
{
if (i % 16 == 0 && i > 0) this.print(logLevel, "\n");
else if (i % 8 == 0 && i > 0) this.print(logLevel, " ");
this.print(logLevel, "{0} ", (data[i] & 0xFF));
this.print(logLevel, "{0} ", [(data[i] & 0xFF)]);
}

this.print(logLevel, "\n");
Expand Down
23 changes: 13 additions & 10 deletions Sample/TypeScript/Demo/src/lappdelegate.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
/*
* Copyright(c) Live2D Inc. All rights reserved.
*
* Use of this source code is governed by the Live2D Open Software license
* that can be found at http://live2d.com/eula/live2d-open-software-license-agreement_en.html.
*/
* Copyright(c) Live2D Inc. All rights reserved.
*
* Use of this source code is governed by the Live2D Open Software license
* that can be found at http://live2d.com/eula/live2d-open-software-license-agreement_en.html.
*/

import {Live2DCubismFramework as live2dcubismframework, Option as Csm_Option} from "../../../../Framework/live2dcubismframework";
import {Live2DCubismFramework as cubismmatrix44} from "../../../../Framework/math/cubismmatrix44";
import Csm_CubismMatrix44 = cubismmatrix44.CubismMatrix44;
import Csm_CubismFramework = live2dcubismframework.CubismFramework;
import { LAppView } from "./lappview";
import { LAppPal } from "./lapppal";
import { LAppTextureManager } from "./lapptexturemanager";
import { LAppLive2DManager } from "./lapplive2dmanager";
import {LAppView} from "./lappview";
import {LAppPal} from "./lapppal";
import {LAppTextureManager} from "./lapptexturemanager";
import {LAppLive2DManager} from "./lapplive2dmanager";
import {LAppDefine} from "./lappdefine";

export let canvas: HTMLCanvasElement = null;
export let s_instance: LAppDelegate = null;
Expand Down Expand Up @@ -271,7 +272,9 @@ export class LAppDelegate
public initializeCubism(): void
{
// setup cubism
Csm_CubismFramework.startUp();
this._cubismOption.logFunction = LAppPal.printMessage;
this._cubismOption.loggingLevel = LAppDefine.CubismLoggingLevel;
Csm_CubismFramework.startUp(this._cubismOption);

// initialize cubism
Csm_CubismFramework.initialize();
Expand Down
4 changes: 2 additions & 2 deletions Sample/TypeScript/Demo/src/lapppal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export class LAppPal
/\{(\d+)\}/g,
(m, k) =>
{
return args[k];
return args[k];
}
)
);
Expand All @@ -91,7 +91,7 @@ export class LAppPal
*/
public static printMessage(message: string): void
{
this.printLog(message);
LAppPal.printLog(message);
}

static lastUpdate = Date.now();
Expand Down

0 comments on commit 38fb3ba

Please sign in to comment.