|
1 | 1 | import { Runner } from './runner';
|
2 | 2 | import { PluginEditor } from './plugin-editor';
|
3 | 3 | import { ResourcesEditor } from './resources-editor';
|
| 4 | +export const EXAMPLE = ` |
| 5 | +() => { |
| 6 | + return { |
| 7 | + // use the modules option to import modules from addresses or from the plugins gist |
| 8 | + modules: [ |
| 9 | + // if a module is a web address, it can be included this way |
| 10 | + "https://unpkg.com/[email protected]/dist/kaplay.js", |
| 11 | + // this is how you can include the contents of other files from the list |
| 12 | + //'kaplay-dist.js', // <-- copy of kaplay.js can also be stored in the gist and imported like so |
| 13 | + // you can host a module on the same gist |
| 14 | + ], |
| 15 | + // if passed, inkjs or bondagejs will be included in the output - can be ink or yarn |
| 16 | + parser: 'ink', |
| 17 | + // Use the script option to write your code that uses any imported modules |
| 18 | + script: () => { |
| 19 | + // since we imported kaplayjs in the modules option, we can now use it like this to render to the Test tab |
| 20 | + const k = kaplay(); |
| 21 | + k.loadSprite("bean", "public/icon.png") |
| 22 | + k.scene("main", () => { |
| 23 | + k.add([ |
| 24 | + k.pos(200, 100), |
| 25 | + k.sprite("bean"), |
| 26 | + ]); |
| 27 | + k.add([ |
| 28 | + k.text("ohhimark fdfg"), |
| 29 | + ]) |
4 | 30 |
|
| 31 | + }); |
| 32 | + k.go("main"); |
| 33 | + // inkjs becomes available because we used parser: 'ink' option |
| 34 | + } |
| 35 | + } |
| 36 | +} |
| 37 | +` |
| 38 | +export const INTERNAL_EXAMPLE = ` |
| 39 | +() => { |
| 40 | + return { |
| 41 | + name: 'ExamplePlugin', |
| 42 | + Constructor: function( { |
| 43 | + app, |
| 44 | + createButton, |
| 45 | + createToggle, |
| 46 | + getPluginStore, |
| 47 | + setPluginStore, |
| 48 | + addSettingsItem, |
| 49 | + onYarnLoadedData, |
| 50 | + onYarnEditorOpen, |
| 51 | + onYarnInPreviewMode, |
| 52 | + onYarnSavedNode, |
| 53 | + onYarnSetLanguage, |
| 54 | + onYarnLoadedStateFromLocalStorage, |
| 55 | + onYarnSavedStateToLocalStorage, |
| 56 | + onYarnSetDocumentType, |
| 57 | + onKeyUp, |
| 58 | + onKeyDown, |
| 59 | + onLoad, |
| 60 | + }) { |
| 61 | + const self = this; |
| 62 | + this.name = 'ExamplePlugin'; |
| 63 | + this.onOpenPluginEditor = ()=> { |
| 64 | + alert("YAY!") |
| 65 | + } |
| 66 | + createButton(self.name, { |
| 67 | + name: 'ExamplePlugin', |
| 68 | + attachTo: app.settings.developmentModeEnabled() ? 'appHeader': 'fileMenuDropdown', |
| 69 | + onClick: 'onOpenPluginEditor()', |
| 70 | + iconName: 'cog', |
| 71 | + }); |
| 72 | + } |
| 73 | + } |
| 74 | +} |
| 75 | +` |
5 | 76 | const PLUGINS = [Runner, PluginEditor, ResourcesEditor];
|
6 | 77 |
|
7 | 78 | const PublicLibs = {}
|
@@ -230,7 +301,7 @@ export var Plugins = function (app) {
|
230 | 301 | };
|
231 | 302 |
|
232 | 303 | const dbStorage = app.data.db;
|
233 |
| - const getVloatilePlugins = () => dbStorage.getDbValue('volatilePlugins'); |
| 304 | + const getVloatilePlugins = () => dbStorage.getDbValue('volatilePlugins', { ['example.js']: {content: EXAMPLE}}); |
234 | 305 | const setVloatilePlugins = value => dbStorage.save('volatilePlugins', value);
|
235 | 306 | const setVloatilePlugin = (key, value) => {
|
236 | 307 | return getVloatilePlugins().then(prev => {
|
@@ -337,7 +408,7 @@ export var Plugins = function (app) {
|
337 | 408 | const getExtensionScriptData = (fileContents) => {
|
338 | 409 | try {
|
339 | 410 | const extension = new Function("parameters", `return ${fileContents}`);//();
|
340 |
| - //console.log({isFunction: typeof extension === 'function', fileContents}) |
| 411 | + //console.log({isFunction: typeof extension === 'function', fileContents}) |
341 | 412 | if (typeof extension === 'function') {
|
342 | 413 | const data = extension();
|
343 | 414 | if (data) {
|
|
0 commit comments