Skip to content

JS Api Docs

Han Programer edited this page Jan 8, 2022 · 2 revisions

CoreCoder: Develop - Plugins API Documentation

The CoreCoder plugins API allows developers to add template, autocomplete rule, action, or a theme to the editor, by creating a plugin which adds a module to the editor.

Plugins are written in Javascript.

The structure of a plugin should be:

- manifest.json

- icon.png

- main.js

All plugins modules will be subclass of JsModule class

Function callbacks

These are functions that can be hooked

onInitialized()   : void    //called when user fetch the project templates

onGetAutocomplete(String language, String lastToken)   : void    //called when user fetch the autocomplete

API Modules:

CoreCoder : module to interact with the app itself

FileIO               : module to write/read files or directory

Globals:

n/a

CoreCoder:

print(str) : Prints something to the console

getProjectPath(str moduleFolderName, str ProjectName) : Get a cross platform external path for projects

addTemplate(obj) : Adds a template to the project creation dialog

Example code:

 var emptyTemplate = {

 "name":"Empty Project",

 "description":"Empty game project with basic structures",

 "version":"Love2D (Lua5.0)",

 "identifier":"com.hanprogramer.cclove2d.emptyTemplate",

 "options":{

 // Options : Type

 "Name": "String",

 "Description": "String",

 "Author": "String",

 },

 "onCreate" : function(args){

 CoreCoder.print("onCreates");

 CoreCoder.print(args.Name);

 CoreCoder.print(args.Description);

 CoreCoder.print(args.Author);

 CoreCoder.print("onCreates2");

 }

 };

 CoreCoder.addTemplate(emptyTemplate);

FileIO:

writeFile(str path, str content) : writes something to a specified path, if not exists, then create

appendFile(str path, str content) : append to a file at the end instead of creating new one

readFile(str path) : reads a file entirely

isExists(str path) : check if a file is exists

isFile(str path) : check if a file at the specified path is a file or even exists

isDirectory(str path) : check if a entity at the specified path is a folder or even exists

mkdir(str path) : creates a folder

mkdirRecursive(str path) : creates a folder and all missing parent folder

rmdir(str path) : deletes an entire folder permanently

readFileAsync(str path): read file asynchronously and returning a promise

writeFileAsync(str path): write file asynchronously and returning a promise

Notes:

*You can’t use import or require (due to the script is read without any location context) (but this is also untested)

Clone this wiki locally