Add UserData ioDevice for setting and getting username from blocks

This commit is contained in:
Paul Kaplan committed 2018-07-23 09:38:58 -04:00
1 parent 378fd672fc
commit 6d4c6df692
5 files changed
+56 -4

No files matched your search

+2 -3
View File
@@ -308,9 +308,8 @@ class Scratch3SensingBlocks {
return 0;
}
getUsername () {
// Logged out users get empty string. Return that for now.
return '';
getUsername (args, util) {
return util.ioQuery('userData', 'getUsername');
}
}
+2
View File
@@ -21,6 +21,7 @@ const DeviceManager = require('../io/deviceManager');
const Keyboard = require('../io/keyboard');
const Mouse = require('../io/mouse');
const MouseWheel = require('../io/mouseWheel');
const UserData = require('../io/userData');
const Video = require('../io/video');
const StringUtil = require('../util/string-util');
@@ -259,6 +260,7 @@ class Runtime extends EventEmitter {
keyboard: new Keyboard(this),
mouse: new Mouse(this),
mouseWheel: new MouseWheel(this),
userData: new UserData(),
video: new Video(this)
};
+24
View File
@@ -0,0 +1,24 @@
class UserData {
constructor () {
this._username = '';
}
/**
* Handler for updating the username
* @param {object} data Data posted to this ioDevice.
* @property {!string} username The new username.
*/
postData (data) {
this._username = data.username;
}
/**
* Getter for username. Initially empty string, until set via postData.
* @returns {!string} The current username
*/
getUsername () {
return this._username;
}
}
module.exports = UserData;