diff --git a/client/types.h b/client/types.h index aeecd7d..8d65dca 100644 --- a/client/types.h +++ b/client/types.h @@ -1,11 +1,21 @@ -typedef struct Entity { - char Name[24]; +typedef struct Stats { unsigned char Strength; unsigned char Endurance; unsigned char Intelligence; unsigned char Wisdom; unsigned char Charisma; unsigned char Faith; +} Stats; + +typedef struct HiddenStats { + unsigned char Luck; + unsigned char Stealth; + unsigned char Attractiveness; + unsigned char Affluence; + unsigned char Notoriety; +} HiddenStats; + +typedef struct Skills { unsigned char Artisan; unsigned char Metalworking; unsigned char Alchemy; @@ -25,10 +35,12 @@ typedef struct Entity { unsigned char Gardening; unsigned char History; unsigned char Perception; - unsigned char Luck; - unsigned char Stealth; - unsigned char Attractiveness; - unsigned char Affluence; - unsigned char Notoriety; +} Skills; + +typedef struct Entity { + char Name[24]; + Stats Stats; + HiddenStats HiddenStats; + Skills Skills; } Entity; diff --git a/server/components/Entity.js b/server/components/Entity.js index ef4efb4..af91575 100644 --- a/server/components/Entity.js +++ b/server/components/Entity.js @@ -1,3 +1,6 @@ +import Stats from "./Stats" +import HiddenStats from "./HiddenStats" +import Skills from "./Skills" class Entity { get Name() { return this._decoder.decode(new Uint8Array(this._ptr.slice(0, 24))); @@ -5,186 +8,27 @@ class Entity { set Name(v) { this._data.set(this._encoder.encode(v), 0); } - get Strength() { - return this._data.getUint8(24, true); + get Stats() { + return new Stats({}, new Uint8Array(this._ptr.slice(24, 30))); } - set Strength(v) { - return this._data.setUint8(24, v, true); + set Stats(v) { + this._data.set(v.bytes(), 24); } - get Endurance() { - return this._data.getUint8(25, true); + get HiddenStats() { + return new HiddenStats({}, new Uint8Array(this._ptr.slice(30, 35))); } - set Endurance(v) { - return this._data.setUint8(25, v, true); + set HiddenStats(v) { + this._data.set(v.bytes(), 30); } - get Intelligence() { - return this._data.getUint8(26, true); + get Skills() { + return new Skills({}, new Uint8Array(this._ptr.slice(35, 54))); } - set Intelligence(v) { - return this._data.setUint8(26, v, true); - } - get Wisdom() { - return this._data.getUint8(27, true); - } - set Wisdom(v) { - return this._data.setUint8(27, v, true); - } - get Charisma() { - return this._data.getUint8(28, true); - } - set Charisma(v) { - return this._data.setUint8(28, v, true); - } - get Faith() { - return this._data.getUint8(29, true); - } - set Faith(v) { - return this._data.setUint8(29, v, true); - } - get Artisan() { - return this._data.getUint8(30, true); - } - set Artisan(v) { - return this._data.setUint8(30, v, true); - } - get Metalworking() { - return this._data.getUint8(31, true); - } - set Metalworking(v) { - return this._data.setUint8(31, v, true); - } - get Alchemy() { - return this._data.getUint8(32, true); - } - set Alchemy(v) { - return this._data.setUint8(32, v, true); - } - get Engineering() { - return this._data.getUint8(33, true); - } - set Engineering(v) { - return this._data.setUint8(33, v, true); - } - get Culinary() { - return this._data.getUint8(34, true); - } - set Culinary(v) { - return this._data.setUint8(34, v, true); - } - get Ranged() { - return this._data.getUint8(35, true); - } - set Ranged(v) { - return this._data.setUint8(35, v, true); - } - get Melee() { - return this._data.getUint8(36, true); - } - set Melee(v) { - return this._data.setUint8(36, v, true); - } - get Acrobatics() { - return this._data.getUint8(37, true); - } - set Acrobatics(v) { - return this._data.setUint8(37, v, true); - } - get Prestidigitation() { - return this._data.getUint8(38, true); - } - set Prestidigitation(v) { - return this._data.setUint8(38, v, true); - } - get Language() { - return this._data.getUint8(39, true); - } - set Language(v) { - return this._data.setUint8(39, v, true); - } - get Medicine() { - return this._data.getUint8(40, true); - } - set Medicine(v) { - return this._data.setUint8(40, v, true); - } - get Thaumatology() { - return this._data.getUint8(41, true); - } - set Thaumatology(v) { - return this._data.setUint8(41, v, true); - } - get Theology() { - return this._data.getUint8(42, true); - } - set Theology(v) { - return this._data.setUint8(42, v, true); - } - get Fishing() { - return this._data.getUint8(43, true); - } - set Fishing(v) { - return this._data.setUint8(43, v, true); - } - get Mining() { - return this._data.getUint8(44, true); - } - set Mining(v) { - return this._data.setUint8(44, v, true); - } - get Survival() { - return this._data.getUint8(45, true); - } - set Survival(v) { - return this._data.setUint8(45, v, true); - } - get Gardening() { - return this._data.getUint8(46, true); - } - set Gardening(v) { - return this._data.setUint8(46, v, true); - } - get History() { - return this._data.getUint8(47, true); - } - set History(v) { - return this._data.setUint8(47, v, true); - } - get Perception() { - return this._data.getUint8(48, true); - } - set Perception(v) { - return this._data.setUint8(48, v, true); - } - get Luck() { - return this._data.getUint8(49, true); - } - set Luck(v) { - return this._data.setUint8(49, v, true); - } - get Stealth() { - return this._data.getUint8(50, true); - } - set Stealth(v) { - return this._data.setUint8(50, v, true); - } - get Attractiveness() { - return this._data.getUint8(51, true); - } - set Attractiveness(v) { - return this._data.setUint8(51, v, true); - } - get Affluence() { - return this._data.getUint8(52, true); - } - set Affluence(v) { - return this._data.setUint8(52, v, true); - } - get Notoriety() { - return this._data.getUint8(53, true); - } - set Notoriety(v) { - return this._data.setUint8(53, v, true); + set Skills(v) { + this._data.set(v.bytes(), 35); } + sql_insert(Name, Stats, HiddenStats, Skills) { + return `INSERT INTO Entity (Name, Stats, HiddenStats, Skills) VALUES (${Name}, ${Stats}, ${HiddenStats}, ${Skills}) RETURNING id;` + } get bytes() { return new Uint8Array(this._ptr); } diff --git a/server/components/HiddenStats.js b/server/components/HiddenStats.js new file mode 100644 index 0000000..16a35aa --- /dev/null +++ b/server/components/HiddenStats.js @@ -0,0 +1,49 @@ +class HiddenStats { + get Luck() { + return this._data.getUint8(0, true); + } + set Luck(v) { + return this._data.setUint8(0, v, true); + } + get Stealth() { + return this._data.getUint8(1, true); + } + set Stealth(v) { + return this._data.setUint8(1, v, true); + } + get Attractiveness() { + return this._data.getUint8(2, true); + } + set Attractiveness(v) { + return this._data.setUint8(2, v, true); + } + get Affluence() { + return this._data.getUint8(3, true); + } + set Affluence(v) { + return this._data.setUint8(3, v, true); + } + get Notoriety() { + return this._data.getUint8(4, true); + } + set Notoriety(v) { + return this._data.setUint8(4, v, true); + } + sql_insert(Luck, Stealth, Attractiveness, Affluence, Notoriety) { + return `INSERT INTO HiddenStats (Luck, Stealth, Attractiveness, Affluence, Notoriety) VALUES (${Luck}, ${Stealth}, ${Attractiveness}, ${Affluence}, ${Notoriety}) RETURNING id;` + } + get bytes() { + return new Uint8Array(this._ptr); + } + constructor(init = {}, ptr = undefined) { + this._size = 5; + this._ptr = ptr.buffer || new ArrayBuffer(this._size); + this._data = new DataView(this._ptr); + + for (const key of Object.keys(init)) { + this[key] = init[key]; + } + } +} + +export default HiddenStats \ No newline at end of file diff --git a/server/components/Skills.js b/server/components/Skills.js new file mode 100644 index 0000000..e640160 --- /dev/null +++ b/server/components/Skills.js @@ -0,0 +1,133 @@ +class Skills { + get Artisan() { + return this._data.getUint8(0, true); + } + set Artisan(v) { + return this._data.setUint8(0, v, true); + } + get Metalworking() { + return this._data.getUint8(1, true); + } + set Metalworking(v) { + return this._data.setUint8(1, v, true); + } + get Alchemy() { + return this._data.getUint8(2, true); + } + set Alchemy(v) { + return this._data.setUint8(2, v, true); + } + get Engineering() { + return this._data.getUint8(3, true); + } + set Engineering(v) { + return this._data.setUint8(3, v, true); + } + get Culinary() { + return this._data.getUint8(4, true); + } + set Culinary(v) { + return this._data.setUint8(4, v, true); + } + get Ranged() { + return this._data.getUint8(5, true); + } + set Ranged(v) { + return this._data.setUint8(5, v, true); + } + get Melee() { + return this._data.getUint8(6, true); + } + set Melee(v) { + return this._data.setUint8(6, v, true); + } + get Acrobatics() { + return this._data.getUint8(7, true); + } + set Acrobatics(v) { + return this._data.setUint8(7, v, true); + } + get Prestidigitation() { + return this._data.getUint8(8, true); + } + set Prestidigitation(v) { + return this._data.setUint8(8, v, true); + } + get Language() { + return this._data.getUint8(9, true); + } + set Language(v) { + return this._data.setUint8(9, v, true); + } + get Medicine() { + return this._data.getUint8(10, true); + } + set Medicine(v) { + return this._data.setUint8(10, v, true); + } + get Thaumatology() { + return this._data.getUint8(11, true); + } + set Thaumatology(v) { + return this._data.setUint8(11, v, true); + } + get Theology() { + return this._data.getUint8(12, true); + } + set Theology(v) { + return this._data.setUint8(12, v, true); + } + get Fishing() { + return this._data.getUint8(13, true); + } + set Fishing(v) { + return this._data.setUint8(13, v, true); + } + get Mining() { + return this._data.getUint8(14, true); + } + set Mining(v) { + return this._data.setUint8(14, v, true); + } + get Survival() { + return this._data.getUint8(15, true); + } + set Survival(v) { + return this._data.setUint8(15, v, true); + } + get Gardening() { + return this._data.getUint8(16, true); + } + set Gardening(v) { + return this._data.setUint8(16, v, true); + } + get History() { + return this._data.getUint8(17, true); + } + set History(v) { + return this._data.setUint8(17, v, true); + } + get Perception() { + return this._data.getUint8(18, true); + } + set Perception(v) { + return this._data.setUint8(18, v, true); + } + sql_insert(Artisan, Metalworking, Alchemy, Engineering, Culinary, Ranged, Melee, Acrobatics, Prestidigitation, Language, Medicine, Thaumatology, Theology, Fishing, Mining, Survival, Gardening, History, Perception) { + return `INSERT INTO Skills (Artisan, Metalworking, Alchemy, Engineering, Culinary, Ranged, Melee, Acrobatics, Prestidigitation, Language, Medicine, Thaumatology, Theology, Fishing, Mining, Survival, Gardening, History, Perception) VALUES (${Artisan}, ${Metalworking}, ${Alchemy}, ${Engineering}, ${Culinary}, ${Ranged}, ${Melee}, ${Acrobatics}, ${Prestidigitation}, ${Language}, ${Medicine}, ${Thaumatology}, ${Theology}, ${Fishing}, ${Mining}, ${Survival}, ${Gardening}, ${History}, ${Perception}) RETURNING id;` + } + get bytes() { + return new Uint8Array(this._ptr); + } + constructor(init = {}, ptr = undefined) { + this._size = 19; + this._ptr = ptr.buffer || new ArrayBuffer(this._size); + this._data = new DataView(this._ptr); + + for (const key of Object.keys(init)) { + this[key] = init[key]; + } + } +} + +export default Skills \ No newline at end of file diff --git a/server/components/Stats.js b/server/components/Stats.js new file mode 100644 index 0000000..4bd61c0 --- /dev/null +++ b/server/components/Stats.js @@ -0,0 +1,55 @@ +class Stats { + get Strength() { + return this._data.getUint8(0, true); + } + set Strength(v) { + return this._data.setUint8(0, v, true); + } + get Endurance() { + return this._data.getUint8(1, true); + } + set Endurance(v) { + return this._data.setUint8(1, v, true); + } + get Intelligence() { + return this._data.getUint8(2, true); + } + set Intelligence(v) { + return this._data.setUint8(2, v, true); + } + get Wisdom() { + return this._data.getUint8(3, true); + } + set Wisdom(v) { + return this._data.setUint8(3, v, true); + } + get Charisma() { + return this._data.getUint8(4, true); + } + set Charisma(v) { + return this._data.setUint8(4, v, true); + } + get Faith() { + return this._data.getUint8(5, true); + } + set Faith(v) { + return this._data.setUint8(5, v, true); + } + sql_insert(Strength, Endurance, Intelligence, Wisdom, Charisma, Faith) { + return `INSERT INTO Stats (Strength, Endurance, Intelligence, Wisdom, Charisma, Faith) VALUES (${Strength}, ${Endurance}, ${Intelligence}, ${Wisdom}, ${Charisma}, ${Faith}) RETURNING id;` + } + get bytes() { + return new Uint8Array(this._ptr); + } + constructor(init = {}, ptr = undefined) { + this._size = 6; + this._ptr = ptr.buffer || new ArrayBuffer(this._size); + this._data = new DataView(this._ptr); + + for (const key of Object.keys(init)) { + this[key] = init[key]; + } + } +} + +export default Stats \ No newline at end of file diff --git a/server/schema.json b/server/schema.json index b9bd039..7eba345 100644 --- a/server/schema.json +++ b/server/schema.json @@ -1,10 +1,5 @@ { - "Entity": { - "Name": { - "type": "string", - "kind": "string", - "size": "24" - }, + "Stats": { "Strength": { "type": "u8", "kind": "scalar" @@ -28,7 +23,31 @@ "Faith": { "type": "u8", "kind": "scalar" + } + }, + "HiddenStats": { + "Luck": { + "type": "u8", + "kind": "scalar" }, + "Stealth": { + "type": "u8", + "kind": "scalar" + }, + "Attractiveness": { + "type": "u8", + "kind": "scalar" + }, + "Affluence": { + "type": "u8", + "kind": "scalar" + }, + "Notoriety": { + "type": "u8", + "kind": "scalar" + } + }, + "Skills": { "Artisan": { "type": "u8", "kind": "scalar" @@ -104,26 +123,25 @@ "Perception": { "type": "u8", "kind": "scalar" + } + }, + "Entity": { + "Name": { + "type": "string", + "kind": "string", + "size": "24" }, - "Luck": { - "type": "u8", - "kind": "scalar" + "Stats": { + "type": "Stats", + "kind": "struct" }, - "Stealth": { - "type": "u8", - "kind": "scalar" + "HiddenStats": { + "type": "HiddenStats", + "kind": "struct" }, - "Attractiveness": { - "type": "u8", - "kind": "scalar" - }, - "Affluence": { - "type": "u8", - "kind": "scalar" - }, - "Notoriety": { - "type": "u8", - "kind": "scalar" + "Skills": { + "type": "Skills", + "kind": "struct" } } } diff --git a/server/sql/types.sql b/server/sql/types.sql index 8ac415b..77716e8 100644 --- a/server/sql/types.sql +++ b/server/sql/types.sql @@ -1,2 +1,11 @@ -CREATE TABLE Entity (entity_id INTEGER PRIMARY KEY AUTOINCREMENT, string TEXT, Strength INTEGER, Endurance INTEGER, Intelligence INTEGER, Wisdom INTEGER, Charisma INTEGER, Faith INTEGER, Artisan INTEGER, Metalworking INTEGER, Alchemy INTEGER, Engineering INTEGER, Culinary INTEGER, Ranged INTEGER, Melee INTEGER, Acrobatics INTEGER, Prestidigitation INTEGER, Language INTEGER, Medicine INTEGER, Thaumatology INTEGER, Theology INTEGER, Fishing INTEGER, Mining INTEGER, Survival INTEGER, Gardening INTEGER, History INTEGER, Perception INTEGER, Luck INTEGER, Stealth INTEGER, Attractiveness INTEGER, Affluence INTEGER, Notoriety INTEGER); +CREATE TABLE Stats (id INTEGER PRIMARY KEY AUTOINCREMENT, Strength INTEGER, Endurance INTEGER, Intelligence INTEGER, Wisdom INTEGER, Charisma INTEGER, Faith INTEGER); + +CREATE TABLE HiddenStats (id INTEGER PRIMARY KEY AUTOINCREMENT, Luck INTEGER, Stealth INTEGER, Attractiveness INTEGER, Affluence INTEGER, Notoriety INTEGER); + +CREATE TABLE Skills (id INTEGER PRIMARY KEY AUTOINCREMENT, Artisan INTEGER, Metalworking INTEGER, Alchemy INTEGER, Engineering INTEGER, Culinary INTEGER, Ranged INTEGER, Melee INTEGER, Acrobatics INTEGER, Prestidigitation INTEGER, Language INTEGER, Medicine INTEGER, Thaumatology INTEGER, Theology INTEGER, Fishing INTEGER, Mining INTEGER, Survival INTEGER, Gardening INTEGER, History INTEGER, Perception INTEGER); + +CREATE TABLE Entity (id INTEGER PRIMARY KEY AUTOINCREMENT, Name TEXT, stats_id INTEGER, hiddenstats_id INTEGER, skills_id INTEGER +, FOREIGN KEY(stats_id) REFERENCES Stats(id) +, FOREIGN KEY(hiddenstats_id) REFERENCES HiddenStats(id) +, FOREIGN KEY(skills_id) REFERENCES Skills(id));