Update: I made some improvements to Personlib. All setter functions that don't normally have a return value now return the person object for method chaining (see updated example)
I finally got around to completing my Personlib library that I mentioned a while ago. The syntax is almost identical to the Sphere 1.x, with some changes to account for miniSphere's differences. It also makes good use of miniSphere's threading capabilities, and adds some convenience functions of its own. For example:
// Cellscript.mjs
install('@/lib', files('lib/personlib.mjs'));
// main.mjs
import { Person } from "personlib";
var player = new Person("player","player.rss",false); // similar arguments to CreatePerson()
player.on_update = function() {
this
.attachInput()
.attachCamera();
var adjacent = this.getAdjacentObstructions(5); // where 5 is the offset in pixels
var rand_r = Math.floor(Math.random());
var rand_g = Math.floor(Math.random());
var rand_b = Math.floor(Math.random());
var rand_a = Math.floor(Math.random());
this.setMask(new Color(rand_r, rand_g, rand_b, rand_a)); // setMask detects if the parameter is a miniSphere color object or a 1.x color object, and getMask allows you specify which one you want
if(adjacent.north.tile > -1 || adjacent.north.person != "") Sphere.abort("You are ded. RIP in pieces.");
else this.queueCommand(COMMAND_MOVE_NORTH, true);
return true;
}
In this example, player.on_update is optional, but if you do set on_update, on_render, etc, they need to be set immediately after the Person object is instantiated. Otherwise they won't be used.
Most of the object methods are just call the legacy function given the appropriate arguments, so if you run into issues, there's a decent chance that it's miniSphere's fault. If you suspect that isn't the case or you have some suggestions, let me know.