Add color maps
This commit is contained in:
parent
a8eb444991
commit
721abd6a8f
|
@ -195,6 +195,12 @@ The "$" is populated with an object's children. $.sword.damage will properly get
|
|||
|
||||
To access the entity's owner, it is through _. For example, the human can access the orc via _.Orc.
|
||||
|
||||
## The REPL
|
||||
|
||||
The REPL lets you poke around in the game. The first accessible item is the Primum. Everything else must be child to it. When an object is selected, its children are accessible in a more friendly way. You can do commands as if you "are" that object.
|
||||
|
||||
The ur-type of the object is always shown in purple. If it has no type, there is nothing shown.
|
||||
|
||||
## Entities
|
||||
Entities are things that exist in the game world.
|
||||
|
||||
|
|
|
@ -42,10 +42,8 @@ var descriptors = {};
|
|||
Object.deepfreeze = function(obj)
|
||||
{
|
||||
for (var key in obj) {
|
||||
if (typeof obj[key] === 'object') {
|
||||
Object.freeze(obj[key]);
|
||||
if (typeof obj[key] === 'object')
|
||||
Object.deepfreeze(obj[key]);
|
||||
}
|
||||
}
|
||||
Object.freeze(obj);
|
||||
}
|
||||
|
|
|
@ -108,10 +108,6 @@ var editor = {
|
|||
Game.objects.forEach(x => x.sync());
|
||||
|
||||
},
|
||||
|
||||
save_prototypes() {
|
||||
save_gameobjects_as_prototypes();
|
||||
},
|
||||
|
||||
/* Save the selected object as a new prototype, extending the chain */
|
||||
save_proto_as(name) {
|
||||
|
@ -139,7 +135,8 @@ var editor = {
|
|||
save_type_as(name) {
|
||||
if (name in gameobjects) {
|
||||
Log.info("Already an object with name '" + name + "'. Choose another one.");
|
||||
return;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
var newp = this.selectlist[0].__proto__.__proto__.clone(name);
|
||||
|
@ -455,6 +452,7 @@ var editor = {
|
|||
}
|
||||
|
||||
this.edit_level = Primum.spawn(ur.arena);
|
||||
this.edit_level.toString = function() { return "desktop"; };
|
||||
editor.edit_level.selectable = false;
|
||||
},
|
||||
|
||||
|
@ -484,30 +482,27 @@ var editor = {
|
|||
Debug.point(world2screen(this.cursor), 2, Color.green);
|
||||
|
||||
if (this.comp_info && this.sel_comp) {
|
||||
GUI.text(Input.print_pawn_kbm(this.sel_comp), [100,700],1);
|
||||
GUI.text(Input.print_pawn_kbm(this.sel_comp,false), [100,700],1);
|
||||
}
|
||||
|
||||
GUI.text("0,0", world2screen([0,0]));
|
||||
|
||||
var clvl = this.edit_level;
|
||||
var lvlcolorsample = 1;
|
||||
var ypos = 200;
|
||||
var lvlcolor = Color.white;
|
||||
while (clvl) {
|
||||
var lvlstr = clvl.file ? clvl.file : "NEW ENTITY";
|
||||
if (clvl.unique)
|
||||
lvlstr += "#";
|
||||
else if (clvl.dirty)
|
||||
var lvlstr = clvl.toString();
|
||||
if (clvl.dirty)
|
||||
lvlstr += "*";
|
||||
GUI.text(lvlstr, [0, ypos], 1, lvlcolor);
|
||||
|
||||
lvlcolor = Color.gray;
|
||||
GUI.text(lvlstr, [0, ypos], 1, ColorMap.Inferno.sample(lvlcolorsample));
|
||||
lvlcolorsample -= 0.1;
|
||||
|
||||
clvl = clvl.level;
|
||||
if (clvl) {
|
||||
GUI.text("^^^^^^", [0,ypos+5],1);
|
||||
ypos += 5;
|
||||
GUI.text("^^^^^^", [0,ypos-15],1);
|
||||
ypos -= 15;
|
||||
}
|
||||
ypos += 15;
|
||||
ypos -= 5;
|
||||
}
|
||||
|
||||
this.edit_level.objects.forEach(function(x) {
|
||||
|
@ -522,11 +517,8 @@ var editor = {
|
|||
|
||||
this.selectlist.forEach(function(x) {
|
||||
var color = x.color ? x.color : Color.white;
|
||||
var ojson = JSON.parse(JSON.stringify(x));
|
||||
delete ojson.pos;
|
||||
delete ojson.angle;
|
||||
var sname = x.ur.toString();
|
||||
if (!ojson.empty)
|
||||
if (!x.save_obj().empty)
|
||||
x.dirty = true;
|
||||
else
|
||||
x.dirty = false;
|
||||
|
@ -709,7 +701,6 @@ editor.inputs['C-a'] = function() {
|
|||
if (!editor.selectlist.empty) { editor.unselect(); return; }
|
||||
editor.unselect();
|
||||
editor.selectlist = editor.edit_level.objects.slice();
|
||||
Log.warn("C-a pressed.");
|
||||
};
|
||||
editor.inputs['C-a'].doc = "Select all objects.";
|
||||
|
||||
|
@ -724,7 +715,7 @@ editor.inputs['h'] = function() {
|
|||
};
|
||||
editor.inputs['h'].doc = "Toggle object hidden.";
|
||||
|
||||
editor.inputs['C-h'] = function() { Game.objects.forEach(function(x) { x.visible = true; }); };
|
||||
editor.inputs['C-h'] = function() { Primum.objects.forEach(function(x) { x.visible = true; }); };
|
||||
editor.inputs['C-h'].doc = "Unhide all objects.";
|
||||
|
||||
editor.inputs['C-e'] = function() { editor.openpanel(assetexplorer); };
|
||||
|
@ -736,7 +727,6 @@ editor.inputs['C-l'].doc = "Open list of spawned entities.";
|
|||
editor.inputs['C-i'] = function() {
|
||||
if (editor.selectlist.length !== 1) return;
|
||||
objectexplorer.obj = editor.selectlist[0];
|
||||
objectexplorer.on_close = editor.save_prototypes;
|
||||
editor.openpanel(objectexplorer);
|
||||
};
|
||||
editor.inputs['C-i'].doc = "Open the object explorer for a selected object.";
|
||||
|
@ -749,14 +739,6 @@ editor.inputs['C-d'] = function() {
|
|||
};
|
||||
editor.inputs['C-d'].doc = "Duplicate all selected objects.";
|
||||
|
||||
editor.inputs.f3 = function() {
|
||||
|
||||
editor.selectlist.forEach(function(x) {
|
||||
Log.say(JSON.stringify(x,null,2));
|
||||
// x.components.forEach(function(x) { Log.say(JSON.stringify(x,null,2)); Log.say(JSON.stringify(x.ur,null,2));});
|
||||
});
|
||||
};
|
||||
|
||||
editor.inputs['C-m'] = function() {
|
||||
if (editor.sel_comp) {
|
||||
if (editor.sel_comp.flipy)
|
||||
|
@ -794,15 +776,13 @@ editor.inputs.f.doc = "Find the selected objects.";
|
|||
|
||||
editor.inputs['C-f'] = function() {
|
||||
if (editor.selectlist.length !== 1) return;
|
||||
if (!editor.selectlist[0].file) return;
|
||||
|
||||
editor.edit_level = editor.selectlist[0];
|
||||
editor.unselect();
|
||||
editor.reset_undos();
|
||||
editor.curlvl = editor.edit_level.save();
|
||||
};
|
||||
editor.inputs['C-f'].doc = "Tunnel into the selected level object to edit it.";
|
||||
|
||||
editor.inputs['C-S-f'] = function() {
|
||||
editor.inputs['C-F'] = function() {
|
||||
if (!editor.edit_level.level) return;
|
||||
|
||||
editor.edit_level = editor.edit_level.level;
|
||||
|
@ -812,7 +792,7 @@ editor.inputs['C-S-f'] = function() {
|
|||
editor.edit_level.filejson = editor.edit_level.save();
|
||||
editor.edit_level.check_dirty();
|
||||
};
|
||||
editor.inputs['C-S-f'].doc = "Tunnel out of the level you are editing, saving it in the process.";
|
||||
editor.inputs['C-F'].doc = "Tunnel out of the level you are editing, saving it in the process.";
|
||||
|
||||
editor.inputs['C-r'] = function() { editor.selectlist.forEach(function(x) { x.angle = -x.angle; }); };
|
||||
editor.inputs['C-r'].doc = "Negate the selected's angle.";
|
||||
|
@ -896,6 +876,7 @@ editor.inputs.escape = function() { editor.openpanel(quitpanel); }
|
|||
editor.inputs.escape.doc = "Quit editor.";
|
||||
|
||||
editor.inputs['C-s'] = function() {
|
||||
|
||||
if (editor.edit_level.level) {
|
||||
if (!editor.edit_level.unique)
|
||||
editor.save_current();
|
||||
|
@ -911,10 +892,10 @@ editor.inputs['C-s'] = function() {
|
|||
};
|
||||
editor.inputs['C-s'].doc = "Save selected.";
|
||||
|
||||
editor.inputs['C-S-s'] = function() {
|
||||
editor.inputs['C-S'] = function() {
|
||||
editor.openpanel(saveaspanel);
|
||||
};
|
||||
editor.inputs['C-S-s'].doc = "Save selected as.";
|
||||
editor.inputs['C-S'].doc = "Save selected as.";
|
||||
|
||||
editor.inputs['C-z'] = function() { editor.undo(); };
|
||||
editor.inputs['C-z'].doc = "Undo the last change made.";
|
||||
|
@ -940,14 +921,14 @@ editor.inputs['C-n'] = function() {
|
|||
editor.inputs['C-n'].doc = "Open a new level.";
|
||||
|
||||
editor.inputs['C-o'] = function() {
|
||||
if (editor.edit_level.dirty()) {
|
||||
/* if (editor.edit_level.dirty) {
|
||||
editor.openpanel(gen_notify("Level is changed. Are you sure you want to close it?", function() {
|
||||
editor.clear_level();
|
||||
editor.openpanel(openlevelpanel);
|
||||
}.bind(editor)));
|
||||
return;
|
||||
}
|
||||
|
||||
*/
|
||||
editor.openpanel(openlevelpanel);
|
||||
};
|
||||
editor.inputs['C-o'].doc = "Open a level.";
|
||||
|
@ -1502,6 +1483,7 @@ var replpanel = Object.copy(inputpanel, {
|
|||
ecode += `var ${key} = editor.selectlist[0].$['${key}'];`;
|
||||
|
||||
ecode += this.value;
|
||||
Log.say(this.value);
|
||||
this.value = "";
|
||||
var ret = eval(ecode);
|
||||
if (ret) Log.say(ret);
|
||||
|
|
|
@ -83,6 +83,84 @@ Color.Apple = {
|
|||
|
||||
Object.deepfreeze(Color);
|
||||
|
||||
var ColorMap = {};
|
||||
ColorMap.makemap = function(map)
|
||||
{
|
||||
var newmap = Object.create(ColorMap);
|
||||
Object.assign(newmap, map);
|
||||
return newmap;
|
||||
}
|
||||
ColorMap.Jet = ColorMap.makemap({
|
||||
0: [0,0,131],
|
||||
0.125: [0,60,170],
|
||||
0.375: [5,255,255],
|
||||
0.625: [255,255,0],
|
||||
0.875: [250,0,0],
|
||||
1: [128,0,0]
|
||||
});
|
||||
|
||||
ColorMap.BlueRed = ColorMap.makemap({
|
||||
0: [0,0,255],
|
||||
1: [255,0,0]
|
||||
});
|
||||
|
||||
ColorMap.Inferno = ColorMap.makemap({
|
||||
0:[0,0,4],
|
||||
0.13: [31,12,72],
|
||||
0.25: [85,15,109],
|
||||
0.38: [136,34,106],
|
||||
0.5: [186,54,85],
|
||||
0.63: [227,89,51],
|
||||
0.75: [249,140,10],
|
||||
0.88: [249,201,50],
|
||||
1: [252,255,164]
|
||||
});
|
||||
|
||||
ColorMap.Bathymetry = ColorMap.makemap({
|
||||
0: [40,26,44],
|
||||
0.13: [59.49,90],
|
||||
0.25: [64,76,139],
|
||||
0.38: [63,110,151],
|
||||
0.5: [72,142,158],
|
||||
0.63: [85,174,163],
|
||||
0.75: [120,206,163],
|
||||
0.88: [187,230,172],
|
||||
1: [253,254,204]
|
||||
});
|
||||
|
||||
ColorMap.Viridis = ColorMap.makemap({
|
||||
0: [68,1,84],
|
||||
0.13: [71,44,122],
|
||||
0.25: [59,81,139],
|
||||
0.38: [44,113,142],
|
||||
0.5: [33,144,141],
|
||||
0.63: [39,173,129],
|
||||
0.75: [92,200,99],
|
||||
0.88: [170,220,50],
|
||||
1: [253,231,37]
|
||||
});
|
||||
|
||||
ColorMap.sample = function(t, map)
|
||||
{
|
||||
map ??= this;
|
||||
if (t < 0) return map[0];
|
||||
if (t > 1) return map[1];
|
||||
|
||||
var lastkey = 0;
|
||||
for (var key of Object.keys(map).sort()) {
|
||||
if (t < key) {
|
||||
var b = map[key];
|
||||
var a = map[lastkey];
|
||||
var tt = (key - lastkey) * t;
|
||||
return a.lerp(b, tt);
|
||||
}
|
||||
lastkey = key;
|
||||
}
|
||||
return map[1];
|
||||
}
|
||||
|
||||
Object.freeze(ColorMap);
|
||||
|
||||
function bb2wh(bb) {
|
||||
return [bb.r-bb.l, bb.t-bb.b];
|
||||
};
|
||||
|
@ -623,6 +701,7 @@ var preprimum = {};
|
|||
preprimum.add_child = function() {};
|
||||
var World = gameobject.make(gameobject.ur, preprimum);
|
||||
var Primum = World;
|
||||
Primum.toString = function() { return "Primum"; };
|
||||
Primum.selectable = false;
|
||||
World.reparent = function(parent) { Log.warn("Cannot reparent the Primum."); }
|
||||
World.unparent = function() { Log.warn("The Primum has no parent, always."); }
|
||||
|
|
|
@ -13,7 +13,8 @@ function grab_from_points(pos, points, slop) {
|
|||
var gameobject = {
|
||||
save: true,
|
||||
selectable: true,
|
||||
|
||||
ed_locked: false,
|
||||
|
||||
layer_nuke() {
|
||||
Nuke.label("Collision layer");
|
||||
Nuke.newline(Collision.num);
|
||||
|
@ -28,8 +29,6 @@ var gameobject = {
|
|||
for (var i = 0; i < 5; i++)
|
||||
this.draw_layer = Nuke.radio(i, this.draw_layer, i);
|
||||
},
|
||||
|
||||
ed_locked: false,
|
||||
|
||||
_visible: true,
|
||||
get visible(){ return this._visible; },
|
||||
|
@ -40,6 +39,8 @@ var gameobject = {
|
|||
this.components[key].visible = x;
|
||||
}
|
||||
}
|
||||
for (var key in this.$)
|
||||
this.$[key].visible = x;
|
||||
},
|
||||
|
||||
phys_nuke() {
|
||||
|
@ -93,11 +94,20 @@ var gameobject = {
|
|||
return bb.t-bb.b;
|
||||
},
|
||||
|
||||
stop() {},
|
||||
save_obj() {
|
||||
var json = JSON.stringify(this);
|
||||
if (!json) return {};
|
||||
var o = JSON.parse(json);
|
||||
delete o.pos;
|
||||
delete o.angle;
|
||||
return o;
|
||||
},
|
||||
|
||||
/* Make a unique object the same as its prototype */
|
||||
revert() {
|
||||
// unmerge(this, this.prop_obj());
|
||||
var save = this.save_obj();
|
||||
for (var key in save)
|
||||
this[key] = this.ur[key];
|
||||
},
|
||||
|
||||
gui() {
|
||||
|
@ -225,7 +235,6 @@ var gameobject = {
|
|||
disable() { this.components.forEach(function(x) { x.disable(); });},
|
||||
enable() { this.components.forEach(function(x) { x.enable(); });},
|
||||
sync() { },
|
||||
dirty() { return false; },
|
||||
|
||||
spawn(ur) {
|
||||
if (typeof ur === 'string')
|
||||
|
@ -330,7 +339,6 @@ var gameobject = {
|
|||
if ('ur' in p) {
|
||||
obj[prop] = obj.spawn(prototypes.get_ur(p.ur));
|
||||
obj.$[prop] = obj[prop];
|
||||
// Object.assign(obj[prop], p);
|
||||
} else if ('make' in p) {
|
||||
obj[prop] = p.make(obj.body);
|
||||
obj.components[prop] = obj[prop];
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
var GUI = {
|
||||
text(str, pos, size, color, wrap) {
|
||||
size = size ? size : 1;
|
||||
|
||||
color = color ? color : [255,255,255,255];
|
||||
wrap = wrap ? wrap : -1;
|
||||
|
||||
|
|
|
@ -65,6 +65,7 @@ Input.print_pawn_kbm = function(pawn) {
|
|||
if (!('inputs' in pawn)) return;
|
||||
var str = "";
|
||||
for (var key in pawn.inputs) {
|
||||
if (!pawn.inputs[key].doc) continue;
|
||||
str += `${key} | ${pawn.inputs[key].doc}\n`;
|
||||
}
|
||||
return str;
|
||||
|
|
Loading…
Reference in a new issue