mirror of
https://github.com/asphyxia-core/plugin-template.git
synced 2026-03-21 17:24:33 -05:00
v1.50a example
This commit is contained in:
parent
a9515e3b9e
commit
d83ffade9d
|
|
@ -53,3 +53,7 @@ export const example: EPR = async (info, data, send) => {
|
|||
export const changeName = async (data: any) => {
|
||||
await DB.Update(data.refid, { collection: 'profile' }, { $set: { name: data.name } });
|
||||
};
|
||||
|
||||
export const randomNumber = async (data: any, send: WebUISend) => {
|
||||
send.json({ number: Math.floor(Math.random() * 100) });
|
||||
};
|
||||
|
|
|
|||
9
index.ts
9
index.ts
|
|
@ -1,4 +1,4 @@
|
|||
import { example, changeName } from './handlers/example';
|
||||
import { example, changeName, randomNumber } from './handlers/example';
|
||||
|
||||
export function register() {
|
||||
/* Register game code */
|
||||
|
|
@ -14,7 +14,7 @@ export function register() {
|
|||
default: 'EVENT_1',
|
||||
options: ['EVENT_1', 'EVENT_2'],
|
||||
});
|
||||
|
||||
|
||||
/*
|
||||
Register user-provided datafile
|
||||
This will allow user to upload their own data to the root of your plugin
|
||||
|
|
@ -44,9 +44,12 @@ export function register() {
|
|||
/* Register a event and increment the click counter */
|
||||
R.WebUIEvent('change', changeName);
|
||||
|
||||
/* Register a event that respond with a random number */
|
||||
R.WebUIEvent('random', randomNumber);
|
||||
|
||||
/* Use --dev argument to enable console output. */
|
||||
console.log('Plugin Registered');
|
||||
|
||||
|
||||
/*
|
||||
You can check the version of CORE using CORE_VERSION_MAJOR and CORE_VERSION_MINOR
|
||||
Note: these value can be undefined, which means the CORE is version v1.18 and under
|
||||
|
|
|
|||
|
|
@ -24,6 +24,11 @@
|
|||
button.button.is-primary#plugin-click
|
||||
| Send "click" event and refresh
|
||||
|
||||
p#random-number RandomNumber: Click the button below to get a random number
|
||||
p
|
||||
button.button.is-primary#plugin-random
|
||||
| Use emit() to get a random number
|
||||
|
||||
//- You can include custom javascripts and send data back to plugin using emit()
|
||||
see profile_name.pug for sending data using form
|
||||
script(src="static/js/custom_page.js")
|
||||
|
|
@ -1,5 +1,11 @@
|
|||
$('#plugin-click').on('click', () => {
|
||||
emit('click', {}).then(() => {
|
||||
emit('click').then(() => {
|
||||
location.reload();
|
||||
});
|
||||
});
|
||||
|
||||
$('#plugin-random').on('click', () => {
|
||||
emit('random').then(result => {
|
||||
$('#random-number').text(result.data.number);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user