v1.50a example

This commit is contained in:
Freddie 2022-04-16 15:46:31 +08:00
parent a9515e3b9e
commit d83ffade9d
4 changed files with 22 additions and 4 deletions

View File

@ -53,3 +53,7 @@ export const example: EPR = async (info, data, send) => {
export const changeName = async (data: any) => { export const changeName = async (data: any) => {
await DB.Update(data.refid, { collection: 'profile' }, { $set: { name: data.name } }); 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) });
};

View File

@ -1,4 +1,4 @@
import { example, changeName } from './handlers/example'; import { example, changeName, randomNumber } from './handlers/example';
export function register() { export function register() {
/* Register game code */ /* Register game code */
@ -14,7 +14,7 @@ export function register() {
default: 'EVENT_1', default: 'EVENT_1',
options: ['EVENT_1', 'EVENT_2'], options: ['EVENT_1', 'EVENT_2'],
}); });
/* /*
Register user-provided datafile Register user-provided datafile
This will allow user to upload their own data to the root of your plugin 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 */ /* Register a event and increment the click counter */
R.WebUIEvent('change', changeName); R.WebUIEvent('change', changeName);
/* Register a event that respond with a random number */
R.WebUIEvent('random', randomNumber);
/* Use --dev argument to enable console output. */ /* Use --dev argument to enable console output. */
console.log('Plugin Registered'); console.log('Plugin Registered');
/* /*
You can check the version of CORE using CORE_VERSION_MAJOR and CORE_VERSION_MINOR 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 Note: these value can be undefined, which means the CORE is version v1.18 and under

View File

@ -24,6 +24,11 @@
button.button.is-primary#plugin-click button.button.is-primary#plugin-click
| Send "click" event and refresh | 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() //- You can include custom javascripts and send data back to plugin using emit()
see profile_name.pug for sending data using form see profile_name.pug for sending data using form
script(src="static/js/custom_page.js") script(src="static/js/custom_page.js")

View File

@ -1,5 +1,11 @@
$('#plugin-click').on('click', () => { $('#plugin-click').on('click', () => {
emit('click', {}).then(() => { emit('click').then(() => {
location.reload(); location.reload();
}); });
}); });
$('#plugin-random').on('click', () => {
emit('random').then(result => {
$('#random-number').text(result.data.number);
});
});