Compare commits

...

4 Commits

Author SHA1 Message Date
jeff 5ea5d627bb Implement rest of basic info editing. 2021-01-10 20:45:15 +00:00
jeff ae6d5bcfa3 Implement updating basic info for character name. 2021-01-10 20:45:15 +00:00
jeff ffe4f9298c Create "character identifier" type for use in all API requests.
Will replace the character_username and character_id values in all
relevant requests.
2021-01-10 20:45:15 +00:00
jeff ea4723cbe5 Add API endpoint for updating basic character info. 2021-01-10 13:56:44 +00:00
13 changed files with 862 additions and 342 deletions

View File

@ -57,43 +57,47 @@ message CofdSheet {
} }
string name = 1; string name = 1;
string player = 2; string gender = 2;
string campaign = 3; string concept = 3;
string description = 4; int32 age = 4;
int32 strength = 6; string player = 5;
int32 dexterity = 7; string chronicle = 6;
int32 stamina = 8; string description = 7;
int32 intelligence = 9; int32 strength = 8;
int32 wits = 10; int32 dexterity = 9;
int32 resolve = 11; int32 stamina = 10;
int32 presence = 12; int32 intelligence = 11;
int32 manipulation = 13; int32 wits = 12;
int32 composure = 14; int32 resolve = 13;
map<string, Skill> physical_skills = 16; int32 presence = 14;
map<string, Skill> mental_skills = 17; int32 manipulation = 15;
map<string, Skill> social_skills = 18; int32 composure = 16;
repeated Merit merits = 15; map<string, Skill> physical_skills = 17;
repeated Condition conditions = 19; map<string, Skill> mental_skills = 18;
map<string, Skill> social_skills = 19;
int32 size = 20; repeated Merit merits = 20;
int32 health = 21; repeated Condition conditions = 21;
int32 willpower = 22;
int32 experience_points = 23;
int32 beats = 24;
repeated Item items = 25; int32 size = 22;
repeated Attack attacks = 26; int32 health = 23;
int32 willpower = 24;
int32 experience_points = 25;
int32 beats = 26;
map<string, string> other_data = 27; repeated Item items = 27;
repeated Attack attacks = 28;
map<string, string> other_data = 29;
oneof system_fields { oneof system_fields {
CoreFields core = 28; CoreFields core = 30;
MageFields mage = 29; MageFields mage = 31;
ChangelingFields changeling = 30; ChangelingFields changeling = 32;
} }
} }

View File

@ -3,15 +3,25 @@ import "cofd.proto";
package models.proto.cofd.api; package models.proto.cofd.api;
message CharacterIdentifier {
string owner = 1;
int32 character_id = 2;
}
//Update basic information about a Chronicles of Darkness (or //Update basic information about a Chronicles of Darkness (or
//derivative system) character sheet. This is a straight overwrite of //derivative system) character sheet. This is a straight overwrite of
//all basic information on the sheet. //all basic information on the sheet.
message UpdateBasicInfoRequest { message UpdateBasicInfoRequest {
string name = 1; CharacterIdentifier id = 1;
string gender = 2; reserved 2;
string concept = 3; // string owner = 1;
string chronicle = 4; // int32 character_id = 2;
int32 age = 5;
string name = 3;
string gender = 4;
string concept = 5;
string chronicle = 6;
int32 age = 7;
} }
//Generic "did something succeed or not" response. //Generic "did something succeed or not" response.

View File

@ -39,6 +39,8 @@ pub(crate) trait Dao {
async fn insert_character(&self, new_character: NewCharacter<'_>) -> sqlx::Result<()>; async fn insert_character(&self, new_character: NewCharacter<'_>) -> sqlx::Result<()>;
async fn update_character<'a>(&self, character: &'a Character) -> sqlx::Result<()>;
async fn update_character_sheet<'a>(&self, character: &'a Character) -> sqlx::Result<()>; async fn update_character_sheet<'a>(&self, character: &'a Character) -> sqlx::Result<()>;
} }
@ -124,6 +126,25 @@ impl Dao for SqlitePool {
Ok(()) Ok(())
} }
async fn update_character<'a>(&self, character: &'a Character) -> sqlx::Result<()> {
sqlx::query(
"UPDATE characters
set user_id = ?, viewable = ?, character_name = ?,
data_type = ?, data_version = ?, data = ? where id = ?",
)
.bind(character.user_id)
.bind(character.viewable)
.bind(&character.character_name)
.bind(character.data_type)
.bind(character.data_version)
.bind(&character.data)
.bind(character.id)
.execute(self)
.await?;
Ok(())
}
async fn update_character_sheet<'a>(&self, character: &'a Character) -> sqlx::Result<()> { async fn update_character_sheet<'a>(&self, character: &'a Character) -> sqlx::Result<()> {
sqlx::query("UPDATE characters set data = ? where id = ?") sqlx::query("UPDATE characters set data = ? where id = ?")
.bind(&character.data) .bind(&character.data)

View File

@ -4,7 +4,36 @@
import * as jspb from "google-protobuf"; import * as jspb from "google-protobuf";
import * as cofd_pb from "./cofd_pb"; import * as cofd_pb from "./cofd_pb";
export class CharacterIdentifier extends jspb.Message {
getOwner(): string;
setOwner(value: string): void;
getCharacterId(): number;
setCharacterId(value: number): void;
serializeBinary(): Uint8Array;
toObject(includeInstance?: boolean): CharacterIdentifier.AsObject;
static toObject(includeInstance: boolean, msg: CharacterIdentifier): CharacterIdentifier.AsObject;
static extensions: {[key: number]: jspb.ExtensionFieldInfo<jspb.Message>};
static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo<jspb.Message>};
static serializeBinaryToWriter(message: CharacterIdentifier, writer: jspb.BinaryWriter): void;
static deserializeBinary(bytes: Uint8Array): CharacterIdentifier;
static deserializeBinaryFromReader(message: CharacterIdentifier, reader: jspb.BinaryReader): CharacterIdentifier;
}
export namespace CharacterIdentifier {
export type AsObject = {
owner: string,
characterId: number,
}
}
export class UpdateBasicInfoRequest extends jspb.Message { export class UpdateBasicInfoRequest extends jspb.Message {
hasId(): boolean;
clearId(): void;
getId(): CharacterIdentifier | undefined;
setId(value?: CharacterIdentifier): void;
getName(): string; getName(): string;
setName(value: string): void; setName(value: string): void;
@ -32,6 +61,7 @@ export class UpdateBasicInfoRequest extends jspb.Message {
export namespace UpdateBasicInfoRequest { export namespace UpdateBasicInfoRequest {
export type AsObject = { export type AsObject = {
id?: CharacterIdentifier.AsObject,
name: string, name: string,
gender: string, gender: string,
concept: string, concept: string,

View File

@ -18,12 +18,34 @@ var cofd_pb = require('./cofd_pb.js');
goog.object.extend(proto, cofd_pb); goog.object.extend(proto, cofd_pb);
goog.exportSymbol('proto.models.proto.cofd.api.AddConditionRequest', null, global); goog.exportSymbol('proto.models.proto.cofd.api.AddConditionRequest', null, global);
goog.exportSymbol('proto.models.proto.cofd.api.ApiResult', null, global); goog.exportSymbol('proto.models.proto.cofd.api.ApiResult', null, global);
goog.exportSymbol('proto.models.proto.cofd.api.CharacterIdentifier', null, global);
goog.exportSymbol('proto.models.proto.cofd.api.RemoveConditionRequest', null, global); goog.exportSymbol('proto.models.proto.cofd.api.RemoveConditionRequest', null, global);
goog.exportSymbol('proto.models.proto.cofd.api.UpdateAttributeRequest', null, global); goog.exportSymbol('proto.models.proto.cofd.api.UpdateAttributeRequest', null, global);
goog.exportSymbol('proto.models.proto.cofd.api.UpdateBasicInfoRequest', null, global); goog.exportSymbol('proto.models.proto.cofd.api.UpdateBasicInfoRequest', null, global);
goog.exportSymbol('proto.models.proto.cofd.api.UpdateSkillRequest', null, global); goog.exportSymbol('proto.models.proto.cofd.api.UpdateSkillRequest', null, global);
goog.exportSymbol('proto.models.proto.cofd.api.UpdateSkillSpecializationsRequest', null, global); goog.exportSymbol('proto.models.proto.cofd.api.UpdateSkillSpecializationsRequest', null, global);
goog.exportSymbol('proto.models.proto.cofd.api.UpdateSkillValueRequest', null, global); goog.exportSymbol('proto.models.proto.cofd.api.UpdateSkillValueRequest', null, global);
/**
* Generated by JsPbCodeGenerator.
* @param {Array=} opt_data Optional initial data array, typically from a
* server response, or constructed directly in Javascript. The array is used
* in place and becomes part of the constructed object. It is not cloned.
* If no data is provided, the constructed object will be empty, but still
* valid.
* @extends {jspb.Message}
* @constructor
*/
proto.models.proto.cofd.api.CharacterIdentifier = function(opt_data) {
jspb.Message.initialize(this, opt_data, 0, -1, null, null);
};
goog.inherits(proto.models.proto.cofd.api.CharacterIdentifier, jspb.Message);
if (goog.DEBUG && !COMPILED) {
/**
* @public
* @override
*/
proto.models.proto.cofd.api.CharacterIdentifier.displayName = 'proto.models.proto.cofd.api.CharacterIdentifier';
}
/** /**
* Generated by JsPbCodeGenerator. * Generated by JsPbCodeGenerator.
* @param {Array=} opt_data Optional initial data array, typically from a * @param {Array=} opt_data Optional initial data array, typically from a
@ -195,6 +217,166 @@ if (goog.DEBUG && !COMPILED) {
if (jspb.Message.GENERATE_TO_OBJECT) {
/**
* Creates an object representation of this proto.
* Field names that are reserved in JavaScript and will be renamed to pb_name.
* Optional fields that are not set will be set to undefined.
* To access a reserved field use, foo.pb_<name>, eg, foo.pb_default.
* For the list of reserved names please see:
* net/proto2/compiler/js/internal/generator.cc#kKeyword.
* @param {boolean=} opt_includeInstance Deprecated. whether to include the
* JSPB instance for transitional soy proto support:
* http://goto/soy-param-migration
* @return {!Object}
*/
proto.models.proto.cofd.api.CharacterIdentifier.prototype.toObject = function(opt_includeInstance) {
return proto.models.proto.cofd.api.CharacterIdentifier.toObject(opt_includeInstance, this);
};
/**
* Static version of the {@see toObject} method.
* @param {boolean|undefined} includeInstance Deprecated. Whether to include
* the JSPB instance for transitional soy proto support:
* http://goto/soy-param-migration
* @param {!proto.models.proto.cofd.api.CharacterIdentifier} msg The msg instance to transform.
* @return {!Object}
* @suppress {unusedLocalVariables} f is only used for nested messages
*/
proto.models.proto.cofd.api.CharacterIdentifier.toObject = function(includeInstance, msg) {
var f, obj = {
owner: jspb.Message.getFieldWithDefault(msg, 1, ""),
characterId: jspb.Message.getFieldWithDefault(msg, 2, 0)
};
if (includeInstance) {
obj.$jspbMessageInstance = msg;
}
return obj;
};
}
/**
* Deserializes binary data (in protobuf wire format).
* @param {jspb.ByteSource} bytes The bytes to deserialize.
* @return {!proto.models.proto.cofd.api.CharacterIdentifier}
*/
proto.models.proto.cofd.api.CharacterIdentifier.deserializeBinary = function(bytes) {
var reader = new jspb.BinaryReader(bytes);
var msg = new proto.models.proto.cofd.api.CharacterIdentifier;
return proto.models.proto.cofd.api.CharacterIdentifier.deserializeBinaryFromReader(msg, reader);
};
/**
* Deserializes binary data (in protobuf wire format) from the
* given reader into the given message object.
* @param {!proto.models.proto.cofd.api.CharacterIdentifier} msg The message object to deserialize into.
* @param {!jspb.BinaryReader} reader The BinaryReader to use.
* @return {!proto.models.proto.cofd.api.CharacterIdentifier}
*/
proto.models.proto.cofd.api.CharacterIdentifier.deserializeBinaryFromReader = function(msg, reader) {
while (reader.nextField()) {
if (reader.isEndGroup()) {
break;
}
var field = reader.getFieldNumber();
switch (field) {
case 1:
var value = /** @type {string} */ (reader.readString());
msg.setOwner(value);
break;
case 2:
var value = /** @type {number} */ (reader.readInt32());
msg.setCharacterId(value);
break;
default:
reader.skipField();
break;
}
}
return msg;
};
/**
* Serializes the message to binary data (in protobuf wire format).
* @return {!Uint8Array}
*/
proto.models.proto.cofd.api.CharacterIdentifier.prototype.serializeBinary = function() {
var writer = new jspb.BinaryWriter();
proto.models.proto.cofd.api.CharacterIdentifier.serializeBinaryToWriter(this, writer);
return writer.getResultBuffer();
};
/**
* Serializes the given message to binary data (in protobuf wire
* format), writing to the given BinaryWriter.
* @param {!proto.models.proto.cofd.api.CharacterIdentifier} message
* @param {!jspb.BinaryWriter} writer
* @suppress {unusedLocalVariables} f is only used for nested messages
*/
proto.models.proto.cofd.api.CharacterIdentifier.serializeBinaryToWriter = function(message, writer) {
var f = undefined;
f = message.getOwner();
if (f.length > 0) {
writer.writeString(
1,
f
);
}
f = message.getCharacterId();
if (f !== 0) {
writer.writeInt32(
2,
f
);
}
};
/**
* optional string owner = 1;
* @return {string}
*/
proto.models.proto.cofd.api.CharacterIdentifier.prototype.getOwner = function() {
return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 1, ""));
};
/**
* @param {string} value
* @return {!proto.models.proto.cofd.api.CharacterIdentifier} returns this
*/
proto.models.proto.cofd.api.CharacterIdentifier.prototype.setOwner = function(value) {
return jspb.Message.setProto3StringField(this, 1, value);
};
/**
* optional int32 character_id = 2;
* @return {number}
*/
proto.models.proto.cofd.api.CharacterIdentifier.prototype.getCharacterId = function() {
return /** @type {number} */ (jspb.Message.getFieldWithDefault(this, 2, 0));
};
/**
* @param {number} value
* @return {!proto.models.proto.cofd.api.CharacterIdentifier} returns this
*/
proto.models.proto.cofd.api.CharacterIdentifier.prototype.setCharacterId = function(value) {
return jspb.Message.setProto3IntField(this, 2, value);
};
if (jspb.Message.GENERATE_TO_OBJECT) { if (jspb.Message.GENERATE_TO_OBJECT) {
/** /**
* Creates an object representation of this proto. * Creates an object representation of this proto.
@ -224,11 +406,12 @@ proto.models.proto.cofd.api.UpdateBasicInfoRequest.prototype.toObject = function
*/ */
proto.models.proto.cofd.api.UpdateBasicInfoRequest.toObject = function(includeInstance, msg) { proto.models.proto.cofd.api.UpdateBasicInfoRequest.toObject = function(includeInstance, msg) {
var f, obj = { var f, obj = {
name: jspb.Message.getFieldWithDefault(msg, 1, ""), id: (f = msg.getId()) && proto.models.proto.cofd.api.CharacterIdentifier.toObject(includeInstance, f),
gender: jspb.Message.getFieldWithDefault(msg, 2, ""), name: jspb.Message.getFieldWithDefault(msg, 3, ""),
concept: jspb.Message.getFieldWithDefault(msg, 3, ""), gender: jspb.Message.getFieldWithDefault(msg, 4, ""),
chronicle: jspb.Message.getFieldWithDefault(msg, 4, ""), concept: jspb.Message.getFieldWithDefault(msg, 5, ""),
age: jspb.Message.getFieldWithDefault(msg, 5, 0) chronicle: jspb.Message.getFieldWithDefault(msg, 6, ""),
age: jspb.Message.getFieldWithDefault(msg, 7, 0)
}; };
if (includeInstance) { if (includeInstance) {
@ -266,22 +449,27 @@ proto.models.proto.cofd.api.UpdateBasicInfoRequest.deserializeBinaryFromReader =
var field = reader.getFieldNumber(); var field = reader.getFieldNumber();
switch (field) { switch (field) {
case 1: case 1:
var value = /** @type {string} */ (reader.readString()); var value = new proto.models.proto.cofd.api.CharacterIdentifier;
msg.setName(value); reader.readMessage(value,proto.models.proto.cofd.api.CharacterIdentifier.deserializeBinaryFromReader);
break; msg.setId(value);
case 2:
var value = /** @type {string} */ (reader.readString());
msg.setGender(value);
break; break;
case 3: case 3:
var value = /** @type {string} */ (reader.readString()); var value = /** @type {string} */ (reader.readString());
msg.setConcept(value); msg.setName(value);
break; break;
case 4: case 4:
var value = /** @type {string} */ (reader.readString()); var value = /** @type {string} */ (reader.readString());
msg.setChronicle(value); msg.setGender(value);
break; break;
case 5: case 5:
var value = /** @type {string} */ (reader.readString());
msg.setConcept(value);
break;
case 6:
var value = /** @type {string} */ (reader.readString());
msg.setChronicle(value);
break;
case 7:
var value = /** @type {number} */ (reader.readInt32()); var value = /** @type {number} */ (reader.readInt32());
msg.setAge(value); msg.setAge(value);
break; break;
@ -314,38 +502,46 @@ proto.models.proto.cofd.api.UpdateBasicInfoRequest.prototype.serializeBinary = f
*/ */
proto.models.proto.cofd.api.UpdateBasicInfoRequest.serializeBinaryToWriter = function(message, writer) { proto.models.proto.cofd.api.UpdateBasicInfoRequest.serializeBinaryToWriter = function(message, writer) {
var f = undefined; var f = undefined;
f = message.getName(); f = message.getId();
if (f.length > 0) { if (f != null) {
writer.writeString( writer.writeMessage(
1, 1,
f f,
proto.models.proto.cofd.api.CharacterIdentifier.serializeBinaryToWriter
); );
} }
f = message.getGender(); f = message.getName();
if (f.length > 0) {
writer.writeString(
2,
f
);
}
f = message.getConcept();
if (f.length > 0) { if (f.length > 0) {
writer.writeString( writer.writeString(
3, 3,
f f
); );
} }
f = message.getChronicle(); f = message.getGender();
if (f.length > 0) { if (f.length > 0) {
writer.writeString( writer.writeString(
4, 4,
f f
); );
} }
f = message.getConcept();
if (f.length > 0) {
writer.writeString(
5,
f
);
}
f = message.getChronicle();
if (f.length > 0) {
writer.writeString(
6,
f
);
}
f = message.getAge(); f = message.getAge();
if (f !== 0) { if (f !== 0) {
writer.writeInt32( writer.writeInt32(
5, 7,
f f
); );
} }
@ -353,46 +549,47 @@ proto.models.proto.cofd.api.UpdateBasicInfoRequest.serializeBinaryToWriter = fun
/** /**
* optional string name = 1; * optional CharacterIdentifier id = 1;
* @return {?proto.models.proto.cofd.api.CharacterIdentifier}
*/
proto.models.proto.cofd.api.UpdateBasicInfoRequest.prototype.getId = function() {
return /** @type{?proto.models.proto.cofd.api.CharacterIdentifier} */ (
jspb.Message.getWrapperField(this, proto.models.proto.cofd.api.CharacterIdentifier, 1));
};
/**
* @param {?proto.models.proto.cofd.api.CharacterIdentifier|undefined} value
* @return {!proto.models.proto.cofd.api.UpdateBasicInfoRequest} returns this
*/
proto.models.proto.cofd.api.UpdateBasicInfoRequest.prototype.setId = function(value) {
return jspb.Message.setWrapperField(this, 1, value);
};
/**
* Clears the message field making it undefined.
* @return {!proto.models.proto.cofd.api.UpdateBasicInfoRequest} returns this
*/
proto.models.proto.cofd.api.UpdateBasicInfoRequest.prototype.clearId = function() {
return this.setId(undefined);
};
/**
* Returns whether this field is set.
* @return {boolean}
*/
proto.models.proto.cofd.api.UpdateBasicInfoRequest.prototype.hasId = function() {
return jspb.Message.getField(this, 1) != null;
};
/**
* optional string name = 3;
* @return {string} * @return {string}
*/ */
proto.models.proto.cofd.api.UpdateBasicInfoRequest.prototype.getName = function() { proto.models.proto.cofd.api.UpdateBasicInfoRequest.prototype.getName = function() {
return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 1, ""));
};
/**
* @param {string} value
* @return {!proto.models.proto.cofd.api.UpdateBasicInfoRequest} returns this
*/
proto.models.proto.cofd.api.UpdateBasicInfoRequest.prototype.setName = function(value) {
return jspb.Message.setProto3StringField(this, 1, value);
};
/**
* optional string gender = 2;
* @return {string}
*/
proto.models.proto.cofd.api.UpdateBasicInfoRequest.prototype.getGender = function() {
return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 2, ""));
};
/**
* @param {string} value
* @return {!proto.models.proto.cofd.api.UpdateBasicInfoRequest} returns this
*/
proto.models.proto.cofd.api.UpdateBasicInfoRequest.prototype.setGender = function(value) {
return jspb.Message.setProto3StringField(this, 2, value);
};
/**
* optional string concept = 3;
* @return {string}
*/
proto.models.proto.cofd.api.UpdateBasicInfoRequest.prototype.getConcept = function() {
return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 3, "")); return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 3, ""));
}; };
@ -401,16 +598,16 @@ proto.models.proto.cofd.api.UpdateBasicInfoRequest.prototype.getConcept = functi
* @param {string} value * @param {string} value
* @return {!proto.models.proto.cofd.api.UpdateBasicInfoRequest} returns this * @return {!proto.models.proto.cofd.api.UpdateBasicInfoRequest} returns this
*/ */
proto.models.proto.cofd.api.UpdateBasicInfoRequest.prototype.setConcept = function(value) { proto.models.proto.cofd.api.UpdateBasicInfoRequest.prototype.setName = function(value) {
return jspb.Message.setProto3StringField(this, 3, value); return jspb.Message.setProto3StringField(this, 3, value);
}; };
/** /**
* optional string chronicle = 4; * optional string gender = 4;
* @return {string} * @return {string}
*/ */
proto.models.proto.cofd.api.UpdateBasicInfoRequest.prototype.getChronicle = function() { proto.models.proto.cofd.api.UpdateBasicInfoRequest.prototype.getGender = function() {
return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 4, "")); return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 4, ""));
}; };
@ -419,17 +616,53 @@ proto.models.proto.cofd.api.UpdateBasicInfoRequest.prototype.getChronicle = func
* @param {string} value * @param {string} value
* @return {!proto.models.proto.cofd.api.UpdateBasicInfoRequest} returns this * @return {!proto.models.proto.cofd.api.UpdateBasicInfoRequest} returns this
*/ */
proto.models.proto.cofd.api.UpdateBasicInfoRequest.prototype.setChronicle = function(value) { proto.models.proto.cofd.api.UpdateBasicInfoRequest.prototype.setGender = function(value) {
return jspb.Message.setProto3StringField(this, 4, value); return jspb.Message.setProto3StringField(this, 4, value);
}; };
/** /**
* optional int32 age = 5; * optional string concept = 5;
* @return {string}
*/
proto.models.proto.cofd.api.UpdateBasicInfoRequest.prototype.getConcept = function() {
return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 5, ""));
};
/**
* @param {string} value
* @return {!proto.models.proto.cofd.api.UpdateBasicInfoRequest} returns this
*/
proto.models.proto.cofd.api.UpdateBasicInfoRequest.prototype.setConcept = function(value) {
return jspb.Message.setProto3StringField(this, 5, value);
};
/**
* optional string chronicle = 6;
* @return {string}
*/
proto.models.proto.cofd.api.UpdateBasicInfoRequest.prototype.getChronicle = function() {
return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 6, ""));
};
/**
* @param {string} value
* @return {!proto.models.proto.cofd.api.UpdateBasicInfoRequest} returns this
*/
proto.models.proto.cofd.api.UpdateBasicInfoRequest.prototype.setChronicle = function(value) {
return jspb.Message.setProto3StringField(this, 6, value);
};
/**
* optional int32 age = 7;
* @return {number} * @return {number}
*/ */
proto.models.proto.cofd.api.UpdateBasicInfoRequest.prototype.getAge = function() { proto.models.proto.cofd.api.UpdateBasicInfoRequest.prototype.getAge = function() {
return /** @type {number} */ (jspb.Message.getFieldWithDefault(this, 5, 0)); return /** @type {number} */ (jspb.Message.getFieldWithDefault(this, 7, 0));
}; };
@ -438,7 +671,7 @@ proto.models.proto.cofd.api.UpdateBasicInfoRequest.prototype.getAge = function()
* @return {!proto.models.proto.cofd.api.UpdateBasicInfoRequest} returns this * @return {!proto.models.proto.cofd.api.UpdateBasicInfoRequest} returns this
*/ */
proto.models.proto.cofd.api.UpdateBasicInfoRequest.prototype.setAge = function(value) { proto.models.proto.cofd.api.UpdateBasicInfoRequest.prototype.setAge = function(value) {
return jspb.Message.setProto3IntField(this, 5, value); return jspb.Message.setProto3IntField(this, 7, value);
}; };

View File

@ -67,11 +67,20 @@ export class CofdSheet extends jspb.Message {
getName(): string; getName(): string;
setName(value: string): void; setName(value: string): void;
getGender(): string;
setGender(value: string): void;
getConcept(): string;
setConcept(value: string): void;
getAge(): number;
setAge(value: number): void;
getPlayer(): string; getPlayer(): string;
setPlayer(value: string): void; setPlayer(value: string): void;
getCampaign(): string; getChronicle(): string;
setCampaign(value: string): void; setChronicle(value: string): void;
getDescription(): string; getDescription(): string;
setDescription(value: string): void; setDescription(value: string): void;
@ -175,8 +184,11 @@ export class CofdSheet extends jspb.Message {
export namespace CofdSheet { export namespace CofdSheet {
export type AsObject = { export type AsObject = {
name: string, name: string,
gender: string,
concept: string,
age: number,
player: string, player: string,
campaign: string, chronicle: string,
description: string, description: string,
strength: number, strength: number,
dexterity: number, dexterity: number,
@ -353,9 +365,9 @@ export namespace CofdSheet {
export enum SystemFieldsCase { export enum SystemFieldsCase {
SYSTEM_FIELDS_NOT_SET = 0, SYSTEM_FIELDS_NOT_SET = 0,
CORE = 28, CORE = 30,
MAGE = 29, MAGE = 31,
CHANGELING = 30, CHANGELING = 32,
} }
} }

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,5 @@
import * as jspb from "google-protobuf"; import * as jspb from "google-protobuf";
import { ApiResult, UpdateAttributeRequest, UpdateSkillValueRequest } from "../_proto/cofd_api_pb"; import { ApiResult, UpdateBasicInfoRequest, UpdateAttributeRequest, UpdateSkillValueRequest } from "../_proto/cofd_api_pb";
const PROTOBUF_CONTENT_TYPE = { 'Content-Type': 'application/x-protobuf' }; const PROTOBUF_CONTENT_TYPE = { 'Content-Type': 'application/x-protobuf' };
@ -7,7 +7,6 @@ function staticImplements<T>() {
return <U extends T>(constructor: U) => { constructor }; return <U extends T>(constructor: U) => { constructor };
} }
async function makeRequest<T extends jspb.Message>(uri: string, params: T): Promise<Uint8Array> { async function makeRequest<T extends jspb.Message>(uri: string, params: T): Promise<Uint8Array> {
let resp = await fetch(uri, { let resp = await fetch(uri, {
method: 'POST', method: 'POST',
@ -28,3 +27,8 @@ export async function updateAttributeValue(params: UpdateAttributeRequest): Prom
let data = await makeRequest('/api/rpc/cofd/update_attribute_value', params); let data = await makeRequest('/api/rpc/cofd/update_attribute_value', params);
return ApiResult.deserializeBinary(data); return ApiResult.deserializeBinary(data);
} }
export async function updateBasicInfo(params: UpdateBasicInfoRequest): Promise<ApiResult> {
let data = await makeRequest('/api/rpc/cofd/update_basic_info', params);
return ApiResult.deserializeBinary(data);
}

View File

@ -1,4 +1,4 @@
import { UpdateSkillValueRequest, UpdateAttributeRequest } from "../../_proto/cofd_api_pb"; import { CharacterIdentifier, UpdateBasicInfoRequest, UpdateSkillValueRequest, UpdateAttributeRequest } from "../../_proto/cofd_api_pb";
import * as api from "../api"; import * as api from "../api";
// This is the scripting for the edit character page, which submits // This is the scripting for the edit character page, which submits
@ -10,6 +10,19 @@ import * as api from "../api";
const [, , USERNAME, CHARACTER_ID] = window.location.pathname.split('/'); const [, , USERNAME, CHARACTER_ID] = window.location.pathname.split('/');
function characterId(): CharacterIdentifier {
const id = new CharacterIdentifier();
id.setCharacterId(parseInt(CHARACTER_ID));
id.setOwner(USERNAME);
return id;
}
const getTextValue = (selector: string) =>
document.querySelector<HTMLInputElement>(selector)?.value ?? "";
const getIntValue = (selector: string) =>
parseInt(document.querySelector<HTMLInputElement>(selector)?.value ?? "0")
function setupAttributes() { function setupAttributes() {
const attributeInputs = document.querySelectorAll('#attributes input[type="number"]'); const attributeInputs = document.querySelectorAll('#attributes input[type="number"]');
@ -52,7 +65,6 @@ import * as api from "../api";
params.setSkillValue(newValue); params.setSkillValue(newValue);
let resp = await api.updateSkillValue(params); let resp = await api.updateSkillValue(params);
console.log("got a response back", resp); console.log("got a response back", resp);
} }
@ -61,8 +73,32 @@ import * as api from "../api";
}); });
} }
function setupBasicInfo() {
async function updateInfo() {
const params = new UpdateBasicInfoRequest();
params.setId(characterId());
params.setName(getTextValue("#characterName"));
params.setAge(getIntValue("#age"));
params.setConcept(getTextValue("#concept"));
params.setChronicle(getTextValue("#chronicle"));
params.setGender(getTextValue("#gender"));
let resp = await api.updateBasicInfo(params);
console.log("got a response back", resp);
}
const inputs = document.querySelectorAll("#basicInfo input");
inputs.forEach(input => {
console.log('got an input', input);
input.addEventListener('blur', updateInfo);
});
}
setupAttributes(); setupAttributes();
setupSkills(); setupSkills();
setupBasicInfo();
})().catch(e => { })().catch(e => {
alert(e); alert(e);
}); });

View File

@ -89,8 +89,34 @@
<h1>Core Sheet</h1> <h1>Core Sheet</h1>
<div> <div>
<h1>Name: <input type="text" value="{{name}}" /></h1> <div id="basicInfo">
<p>System: {{data_type}}</p> <h1>
<label for="characterName">Name:</label>
<input type="text" id="characterName" name="characterName" value="{{name}}" />
</h1>
<div>System: {{data_type}}</div>
<div>
<label for="gender">Gender:</label>
<input type="text" id="gender" name="gender" value="{{sheet.gender}}" />
</div>
<div>
<label for="age">Age:</label>
<input type="number" id="age" name="age" min="0" value="{{sheet.age}}" />
</div>
<div>
<label for="concept">Concept:</label>
<input type="text" id="concept" name="concept" value="{{sheet.concept}}" />
</div>
<div>
<label for="chronicle">Chronicle:</label>
<input type="text" id="chronicle" name="chronicle" value="{{sheet.chronicle}}" />
</div>
</div>
<div id="attributes"> <div id="attributes">
<div class="attributes-section" id="mentalAttributes"> <div class="attributes-section" id="mentalAttributes">
{{ macros::attribute(name="Intelligence", value=sheet.intelligence) }} {{ macros::attribute(name="Intelligence", value=sheet.intelligence) }}

View File

@ -7,7 +7,7 @@ use rocket::response::status;
use rocket::response::{self, Responder, Response}; use rocket::response::{self, Responder, Response};
use std::default::Default; use std::default::Default;
use std::io::Cursor; use std::io::Cursor;
use std::ops::Deref; use std::ops::{Deref, DerefMut};
pub mod cofd; pub mod cofd;
@ -79,3 +79,12 @@ where
&self.0 &self.0
} }
} }
impl<T> DerefMut for Proto<T>
where
T: prost::Message + Default,
{
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}

View File

@ -13,6 +13,31 @@ tonic::include_proto!("models.proto.cofd");
pub mod api { pub mod api {
//include!(concat!(env!("OUT_DIR"), "/models.proto.cofd.api.rs")); //include!(concat!(env!("OUT_DIR"), "/models.proto.cofd.api.rs"));
tonic::include_proto!("models.proto.cofd.api"); tonic::include_proto!("models.proto.cofd.api");
/// Trait to extract CharacterIdentifier while avoiding clone. The
/// character identifier is extracted out of the Option, leaving
/// None in its place.
pub trait DefaultCharacterIdentifier {
/// Extract the CharacterIdentifier from the containing type,
/// leaving behind a default value.
fn or_default(&mut self) -> CharacterIdentifier;
}
impl DefaultCharacterIdentifier for Option<CharacterIdentifier> {
fn or_default(&mut self) -> CharacterIdentifier {
self.take().unwrap_or_default()
}
}
/// Helpers for the ApiResult class.
impl ApiResult {
pub fn success() -> Self {
ApiResult {
success: true,
error: "".to_string(),
}
}
}
} }
/// Default mental skill names for a regular Chronicles of Darkness /// Default mental skill names for a regular Chronicles of Darkness

View File

@ -2,6 +2,7 @@ use super::load_character;
use crate::db::{Dao, TenebrousDbConn}; use crate::db::{Dao, TenebrousDbConn};
use crate::errors::Error; use crate::errors::Error;
use crate::models::characters::Character; use crate::models::characters::Character;
use crate::models::proto::cofd::api::DefaultCharacterIdentifier;
use crate::models::proto::cofd::cofd_sheet::Skill; use crate::models::proto::cofd::cofd_sheet::Skill;
use crate::models::proto::cofd::*; use crate::models::proto::cofd::*;
use crate::models::proto::{cofd::api::*, cofd::*, Proto}; use crate::models::proto::{cofd::api::*, cofd::*, Proto};
@ -37,9 +38,28 @@ fn find_skill<'a>(sheet: &'a mut CofdSheet, skill_name: &'a str) -> Option<&'a m
find_skill_entry(sheet, skill_name).map(|entry| entry.into_mut()) find_skill_entry(sheet, skill_name).map(|entry| entry.into_mut())
} }
#[post("/rpc/cofd/update_basic_info", data = "<info>")] #[post("/rpc/cofd/update_basic_info", data = "<req>")]
pub(super) fn update_basic_info<'a>(info: Proto<UpdateBasicInfoRequest>) -> &'a str { pub(super) async fn update_basic_info<'a>(
"lol" mut req: Proto<UpdateBasicInfoRequest>,
conn: TenebrousDbConn<'_>,
logged_in_user: Option<&User>,
) -> Result<Proto<ApiResult>, Error> {
let id = req.id.or_default();
let mut character = load_character(&conn, logged_in_user, &id.owner, id.character_id).await?;
let mut sheet: CofdSheet = character.try_deserialize()?;
println!("name will now be {}", req.name);
character.character_name = req.name.clone(); //Should probably remove name from the sheet?
sheet.name = req.name.clone();
sheet.gender = req.gender.clone();
sheet.concept = req.concept.clone();
sheet.chronicle = req.chronicle.clone();
sheet.age = req.age;
character.update_data(&sheet)?;
conn.update_character(&character).await?;
println!("Updated basic info");
Ok(Proto(ApiResult::success()))
} }
#[post("/rpc/cofd/update_attribute_value", data = "<req>")] #[post("/rpc/cofd/update_attribute_value", data = "<req>")]