Source: class_doc.js

  1. /**
  2. * 色情報を表す。
  3. * 基本的な色は"red"や"black"などで指定可能。
  4. *
  5. * https://www.w3.org/TR/SVG11/types.html#ColorKeywords
  6. *
  7. * または"#FF0000"のような16進数表記も可能。console.logで表示するときはこちらになる。
  8. * Live.rgb(1,1,1)のような関数を使って指定することも可能
  9. *
  10. * @example
  11. * function start() {
  12. * model.multiplyColor = "red"
  13. * console.log(model.multiplyColor) // #FF0000
  14. *
  15. * model.multiplyColor = "#FFFFFF"
  16. * model.screenColor = Live.rgb(0, 0, 1)
  17. * }
  18. */
  19. class Color {
  20. /**
  21. * 有効かどうか
  22. * @type {boolean}
  23. */
  24. valid = 0
  25. /**
  26. * 赤成分
  27. * @type {number}
  28. */
  29. r = 0
  30. /**
  31. * 緑成分
  32. * @type {number}
  33. */
  34. g = 0
  35. /**
  36. * 青成分
  37. * @type {number}
  38. */
  39. b = 0
  40. }
  41. /**
  42. * paint関数で引数として渡ってくる、描画のためのオブジェクト
  43. * @example
  44. * function paint(painter) {
  45. * painter.clear()
  46. * painter.pen = "black"
  47. * painter.drawRect(0, 0, 100, 100)
  48. * painter.pen = "green"
  49. * painter.drawEllipse(0, 0, 100, 100)
  50. * painter.pen = "blue"
  51. * painter.drawLine(0, 0, 100, 100)
  52. * painter.pen = "red"
  53. * painter.drawText(20, 20, "Hello, World!")
  54. * }
  55. */
  56. class Painter {
  57. /**
  58. * 画面の横幅
  59. * @type {number}
  60. */
  61. width = 0
  62. /**
  63. * 画面の高さ
  64. * @type {number}
  65. */
  66. height = 0
  67. /**
  68. * 描画時の色
  69. * @type {Color}
  70. */
  71. pen = "red"
  72. /**
  73. * 文字のサイズ
  74. * @type {number}
  75. */
  76. pixelSize = 1
  77. /**
  78. * 文字のサイズ
  79. * @type {number}
  80. */
  81. pointSize = 1
  82. /**
  83. * 線の太さ
  84. * @type {number}
  85. */
  86. penWidth = 1
  87. /**
  88. * フォントの指定
  89. * @type {string}
  90. */
  91. font = ""
  92. /**
  93. * 有効なフォントの一覧
  94. * @type {string[]}
  95. */
  96. fontList = [""]
  97. /**
  98. * 塗りつぶしの色
  99. * @type {Color}
  100. */
  101. brush = "black"
  102. /**
  103. * 描画したものを初期化する
  104. */
  105. clear() { }
  106. /**
  107. * 文字を描画する
  108. * @param x {number}
  109. * @param y {number} 文字の左上を基準とする( API 1.0.0(nL1.8.0)から )
  110. * @param text {string}
  111. */
  112. drawText(x, y, text) { }
  113. /**
  114. * 線を描画する
  115. * @param x1 {number}
  116. * @param y1 {number}
  117. * @param x2 {number}
  118. * @param y2 {number}
  119. */
  120. drawLine(x1, y1, x2, y2) { }
  121. /**
  122. * 点を描画する
  123. * @param x {number}
  124. * @param y {number}
  125. */
  126. drawPoint(x, y) { }
  127. /**
  128. * 楕円を描画する
  129. * @param centerX {number}
  130. * @param centerY {number}
  131. * @param rx {number}
  132. * @param ry {number}
  133. */
  134. drawEllipse(centerX, centerY, rx, ry) { }
  135. /**
  136. * 四角形を描画する
  137. * @param x {number}
  138. * @param y {number}
  139. * @param width {number}
  140. * @param height {number}
  141. */
  142. drawRect(x, y, width, height) { }
  143. /**
  144. * 円を描画する
  145. * @param x {number}
  146. * @param y {number}
  147. * @param radius {number}
  148. */
  149. drawCircle(x, y, radius) { }
  150. /**
  151. * 画像を描画する
  152. * @param x {number}
  153. * @param y {number}
  154. * @param image {string} scriptsフォルダにある画像ファイル名
  155. */
  156. drawImage(x, y, image) { }
  157. }
  158. /**
  159. * Cubismのパラメータを表すオブジェクト
  160. * @example
  161. * function start(){
  162. * for(let param of model.parameters){
  163. * console.log("ID:",param.id)
  164. * console.log(" Name:",param.name)
  165. * console.log(" Default Value:",param.defaultValue)
  166. * console.log(" Max:",param.max)
  167. * console.log(" Min:",param.min)
  168. * console.log(" Value:",param.value)
  169. * }
  170. * }
  171. */
  172. class Parameter {
  173. /**
  174. * パラメータのID
  175. * @type {string}
  176. */
  177. id = ""
  178. /**
  179. * パラメータの値
  180. * @type {number}
  181. */
  182. value = 0
  183. /**
  184. * パラメータの名前。cdi.jsonに記載が無い場合は空文字列
  185. * @type {string}
  186. */
  187. name = ""
  188. /**
  189. * パラメータの最小値
  190. * @type {number}
  191. */
  192. min = 0
  193. /**
  194. * パラメータの最大値
  195. * @type {number}
  196. */
  197. max = 1
  198. /**
  199. * パラメータの初期値
  200. * @type {number}
  201. */
  202. defaultValue = 0
  203. }
  204. /**
  205. * Cubismのパーツを表すオブジェクト
  206. * @example
  207. * function start(){
  208. * for(let part of model.parts){
  209. * console.log("ID:",part.id)
  210. * console.log(" Name:",part.name)
  211. * console.log(" Opacity:",part.opacity)
  212. * console.log(" Parent Part:",part.parentPart?.id)
  213. * console.log(" MultiplyColor:",part.multiplyColor)
  214. * console.log(" ScreenColor:",part.screenColor)
  215. * console.log(" Drawable Children Count:",part.drawables.length)
  216. * console.log(" Part Children Count:",part.parts.length)
  217. * }
  218. * }
  219. */
  220. class Part {
  221. /**
  222. * パーツID
  223. * Cubism Editorで設定したもの
  224. * @type {string}
  225. */
  226. id = ""
  227. /**
  228. * パーツ名。cdi.jsonに記載が無い場合は空文字列
  229. * @type {string}
  230. */
  231. name = ""
  232. /**
  233. * 親パーツ
  234. * @type {Part}
  235. */
  236. parentPart = {}
  237. /**
  238. * パーツの不透明度
  239. * @type {number}
  240. */
  241. opacity = 1
  242. /**
  243. * 子パーツ
  244. * @type {Part[]}
  245. */
  246. parts = []
  247. /**
  248. * 子描画オブジェクト
  249. * @type {Drawable[]}
  250. */
  251. drawables = []
  252. /**
  253. * パーツの乗算色
  254. * @type {Color}
  255. */
  256. multiplyColor = {}
  257. /**
  258. * パーツのスクリーン色
  259. * @type {Color}
  260. */
  261. screenColor = {}
  262. }
  263. /**
  264. * Cubismの描画オブジェクトを表すオブジェクト
  265. * @example
  266. * function start(){
  267. * for(let drawable of model.drawables){
  268. * console.log("ID",drawable.id)
  269. * console.log(" Opacity",drawable.opacity)
  270. * console.log(" DrawOrder",drawable.drawOrder)
  271. * console.log(" Parent Part:",drawable.parentPart?.id)
  272. * console.log(" MultiplyColor:",drawable.multiplyColor)
  273. * console.log(" ScreenColor:",drawable.screenColor)
  274. * }
  275. * }
  276. */
  277. class Drawable {
  278. /**
  279. * 描画オブジェクトID
  280. * Cubism Editorで設定したもの
  281. * @type {string}
  282. * @readonly
  283. */
  284. id = ""
  285. /**
  286. * 親パーツ
  287. * @type {{}}
  288. * @readonly
  289. */
  290. parentPart = {}
  291. /**
  292. * 不透明度
  293. * @type {number}
  294. * @readonly
  295. */
  296. opacity = 1
  297. /**
  298. * 描画順
  299. * @type {number}
  300. * @readonly
  301. */
  302. drawOrder = 1
  303. /**
  304. * 乗算色
  305. * @type {Color}
  306. */
  307. multiplyColor = {}
  308. /**
  309. * スクリーン色
  310. * @type {Color}
  311. */
  312. screenColor = {}
  313. }
  314. /**
  315. * Cubismのモーションを表すオブジェクト
  316. * @example
  317. * function start(){
  318. * for(let motion of model.motions){
  319. * console.log("Name",motion.name)
  320. * }
  321. *
  322. * if(model.motions.length>0){
  323. * let motion=model.motions[Math.floor(Math.random() * model.motions.length)];
  324. * motion.start()
  325. * }
  326. * }
  327. */
  328. class Motion {
  329. /**
  330. * モーション名
  331. * @type {string}
  332. */
  333. name = ""
  334. /**
  335. * モーションを開始する
  336. */
  337. start() {
  338. }
  339. /**
  340. * 停止する
  341. */
  342. stop() {
  343. }
  344. }
  345. /**
  346. * Cubismの表情を表すオブジェクト
  347. * @example
  348. * function start(){
  349. * for(let expression of model.expressions){
  350. * console.log("Name",expression.name)
  351. * }
  352. *
  353. * if(model.expressions.length>0){
  354. * let expression=model.expressions[Math.floor(Math.random() * model.expressions.length)];
  355. * expression.start()
  356. * console.log("Start Expression",expression.name)
  357. * }
  358. * }
  359. */
  360. class Expression {
  361. /**
  362. * 表情名
  363. * @type {string}
  364. */
  365. name = ""
  366. /**
  367. * 表情を再生する
  368. */
  369. start() {
  370. }
  371. /**
  372. * 表情を停止する
  373. */
  374. stop() {
  375. }
  376. }
  377. /**
  378. * Live2Dモデルを操作するオブジェクト
  379. * @example
  380. * function start(){
  381. * console.log("parameters",model.parameters.length)
  382. * console.log("parts",model.parts.length)
  383. * console.log("drawables",model.drawables.length)
  384. * console.log("motions",model.motions.length)
  385. * console.log("expressions",model.expressions.length)
  386. * }
  387. */
  388. class Model {
  389. /**
  390. * パラメータの一覧
  391. * @type {Parameter[]}
  392. */
  393. parameters = []
  394. /**
  395. * パラメータを取得する。
  396. * @param id {string} IDが無い場合は名前で検索する
  397. * @returns {Parameter}
  398. */
  399. parameter(id) {
  400. return new Parameter()
  401. }
  402. /**
  403. * パーツの一覧
  404. * @type {Part[]}
  405. */
  406. parts = []
  407. /**
  408. * パーツを取得する。
  409. * @param id {string} IDが無い場合は名前で検索する
  410. * @returns {Part}
  411. */
  412. part(id) {
  413. return new Part()
  414. }
  415. /**
  416. * 描画オブジェクトの一覧
  417. * @type {Drawable[]}
  418. */
  419. drawables = []
  420. /**
  421. * 描画オブジェクトを取得する。
  422. * @param id {string} IDが無い場合は名前で検索する
  423. * @returns {Drawable}
  424. */
  425. drawable(id) {
  426. return new Drawable()
  427. }
  428. /**
  429. * モーション(motion3.json)の一覧
  430. * @type {Motion[]}
  431. */
  432. motions = []
  433. /**
  434. * モーションを取得する。
  435. * @param name {string}
  436. * @returns {Motion}
  437. */
  438. motion(name) {
  439. return new Motion()
  440. }
  441. /**
  442. * 表情(exp3.json)の一覧
  443. * @type {Expression[]}
  444. */
  445. expressions = []
  446. /**
  447. * 表情を取得する。
  448. * @param name {string} ファイル名またはmodel3.jsonに記載の名前
  449. * @returns {Expression}
  450. */
  451. expression(name) {
  452. return new Expression()
  453. }
  454. /**
  455. * 乗算色
  456. * @type {Color}
  457. * @example
  458. * function start(){
  459. * model.multiplyColor="#00ff00"
  460. * console.log(model.multiplyColor)
  461. * }
  462. */
  463. multiplyColor = {}
  464. /**
  465. * スクリーン色
  466. * @type {Color}
  467. * @example
  468. * function start(){
  469. * model.screenColor="#ff0000"
  470. * console.log(model.screenColor)
  471. * }
  472. */
  473. screenColor = {}
  474. /**
  475. * 再生中のモーションを終了する関数
  476. */
  477. stopMotion() {
  478. }
  479. /**
  480. * モデルを移動する
  481. * @param {Object} param - 設定オブジェクト。
  482. * @param {number} [param.PositionX] - X座標
  483. * @param {number} [param.PositionX] - Y座標
  484. * @param {number} [param.Scale] - 大きさ
  485. * @param {number} [param.Rotation] - 回転
  486. * @param {number} [param.Delay=1] - 完了までの秒数
  487. * @param {boolean} [param.Absolute=false] - 絶対座標で移動するかどうか
  488. * @param {string} [param.InterpolationType="Linear"] - 補間方法
  489. * @example
  490. model.move({
  491. Rotation: 90,
  492. Delay: 3
  493. })
  494. */
  495. move(param) {
  496. }
  497. }
  498. /**
  499. * アイテム
  500. */
  501. class Item{
  502. /**
  503. * ID
  504. * @type {string}
  505. */
  506. id = ""
  507. }
  508. /**
  509. * 画像
  510. */
  511. class Image{
  512. /**
  513. * ID
  514. * @type {string}
  515. */
  516. id = ""
  517. width = 0
  518. height = 0
  519. }
  520. /**
  521. * シーン
  522. * @example
  523. * function start() {
  524. * console.log("ID:",scene.id)
  525. * console.log(" Model:",scene.models.length)
  526. * console.log(" Item:",scene.items.length)
  527. * }
  528. */
  529. class Scene {
  530. /**
  531. * ID
  532. * @type {string}
  533. */
  534. id = ""
  535. /**
  536. * モデル一覧(Live2Dアイテムを除く)
  537. * @type {Model[]}
  538. */
  539. models = []
  540. /**
  541. * アイテム一覧
  542. * @type {Item[]}
  543. */
  544. items = []
  545. }
  546. /**
  547. * グローバルにアクセスできるオブジェクト
  548. */
  549. class Live {
  550. /**
  551. * スクリプトのバージョン
  552. * @type {string}
  553. */
  554. version = "2.0.0"
  555. /**
  556. * すべてのシーンのモデルの一覧
  557. * @type {Model[]}
  558. */
  559. models = []
  560. /**
  561. * すべてのシーンのアイテムの一覧
  562. * @type {Item[]}
  563. */
  564. items = []
  565. /**
  566. * 右上にメッセージを表示する
  567. * @param message {string}
  568. */
  569. showMessage(message) {
  570. }
  571. /**
  572. * シーンの一覧
  573. * @type {Scene[]}
  574. */
  575. scenes = []
  576. /**
  577. * LIVEパラメータの一覧
  578. * @type {Array<{id: string, createdBy: string, group: string, base: number, min: number, max: number, repeat: boolean}>}
  579. * @property {string} id パラメータのID。{@link LiveParameters}を参照
  580. * @property {string} createdBy パラメータの作成者
  581. * @property {string} group パラメータのグループ名
  582. * @property {number} base パラメータの基準値
  583. * @property {number} min パラメータの最小値
  584. * @property {number} max パラメータの最大値
  585. * @property {boolean} repeat 最大値と最小値がつながる場合にtrue
  586. */
  587. parameters = []
  588. /**
  589. * LIVEパラメータを追加する
  590. * @param {Object} param - パラメータ設定オブジェクト。
  591. * @param {string} param.Id - パラメータのID。
  592. * @param {string} param.Group - パラメータが属するグループ。
  593. * @param {number} param.Base - パラメータの基本値。
  594. * @param {number} param.Max - パラメータの最大値。
  595. * @param {number} param.Min - パラメータの最小値。
  596. * @param {boolean} param.Repeat - パラメータが繰り返し可能かどうか。
  597. */
  598. insertParameter(param) {
  599. }
  600. /**
  601. * 色の数値から#FFFFFFの形式に変更
  602. * @param red {number} 0~1
  603. * @param green {number} 0~1
  604. * @param blue {number} 0~1
  605. * @returns {Color}
  606. */
  607. rgb(red, green, blue) {
  608. }
  609. /**
  610. * コンボボックスでの選択ダイアログを開く
  611. * ※ モーダルダイアログで開きます
  612. * @param title {string} ウィンドウタイトル
  613. * @param text {string} 本文
  614. * @param list {string[]} 選択肢の一覧
  615. * @param selectedCallback {Function} 選択したときに呼ばれる関数
  616. * @param canceledCallback {Function} キャンセルしたときに呼ばれる関数
  617. * @param changedCallback {Function} 変更があったときに呼ばれる関数
  618. */
  619. openListDialog(title, text, list,
  620. selectedCallback, canceledCallback = {}, changedCallback = {}) {
  621. }
  622. /**
  623. * カラーダイアログを開く
  624. */
  625. openColorDialog(selectedCallback, canceledCallback = {}, changedCallback = {}) { }
  626. /**
  627. * テキスト入力ダイアログを開く
  628. */
  629. openTextDialog(title, text, selectedCallback, canceledCallback = {}, changedCallback = {}) { }
  630. /**
  631. * 複数行のテキスト入力ダイアログを開く
  632. */
  633. openMultiTextDialog(title, text, selectedCallback, canceledCallback = {}, changedCallback = {}) { }
  634. /**
  635. * 整数入力ダイアログを開く
  636. */
  637. openIntDialog(title, text, min = 0, value = 0, max = 100, selectedCallback = {}, canceledCallback = {}, changedCallback = {}) { }
  638. /**
  639. * 小数入力ダイアログを開く
  640. */
  641. openFloatDialog(title, text, min = 0, value = 0, max = 100, selectedCallback = {}, canceledCallback = {}, changedCallback = {}) { }
  642. /**
  643. * エラーダイアログを開く
  644. */
  645. openErrorDialog(title, text, acceptedCallback = {}) { }
  646. /**
  647. * メッセージダイアログを開く
  648. */
  649. openMessageDialog(title, text, acceptedCallback = {}, canceledCallback = {}, detail = {}) { }
  650. }