UNPKG

avg-core-ts

Version:

Develop Adventure Game (or ADV, Visual Novel, Galgame, etc.) on your own!

70 lines (58 loc) 2.23 kB
/** * @file Textwindow manager * @author MicroMatrix <yangpan.1985@bytedance.com> * @copyright 2012-2020 bytedance * @link git@code.byted.org:yangpan.1985/avg.git */ /* eslint-disable */ import core from 'core/core'; import TextWindow from './TextWindow'; const logger = core.getLogger('TextwindowManager'); const SpriteManager = null; let CurrentTextWindow = null; const Methods = { create(index) { let textwindow = SpriteManager.fromIndex(index); if (textwindow && !(textwindow instanceof TextWindow)) { logger.warn(`Index<${index}> is not empty, which may be an other kind of Sprite. However, it will be destroyed to create a new TextWindow.`); textwindow.destroy(); } else if (textwindow) { logger.warn(`Index<${index}> has been used by a TextWindow, ignored.`); return; } textwindow = CurrentTextWindow.clone(); textwindow.setIndex(index); textwindow.clearText(); SpriteManager.insert(index, textwindow); SpriteManager.addto(index, -1, 50); }, switchTo(index) { const textwindow = SpriteManager.fromIndex(index); if (textwindow && textwindow instanceof TextWindow) { CurrentTextWindow = textwindow; } else { logger.warn(`Index<${index}> does not exist, or it is not a TextWindow, ignored.`); } }, }; export default function Manager(SpriteManager) { // create default textwindow const textwindow = new TextWindow(); textwindow.setIndex(-2); SpriteManager.insert(-2, textwindow); SpriteManager.addto(-2, -1, 50); CurrentTextWindow = textwindow; // return new Proxy(Methods, { // get: function(target, property, receiver) { // if (target.hasOwnProperty(property)) { // // console.log(`getting ${property} from Methods!`); // return Reflect.get(target, property, receiver); // } // else { // // console.log(`getting ${property} from CurrentTextWindow!`); // return Reflect.get(CurrentTextWindow, property, CurrentTextWindow); // } // }, // set: function(target, key, value, receiver) { // // console.log(`setting ${key}!`); // return Reflect.set(CurrentTextWindow, key, value, CurrentTextWindow); // } // }) }