Add API endpoint for updating basic character info.

This commit is contained in:
jeff 2021-01-10 13:56:44 +00:00
parent c42f13af52
commit ea4723cbe5
8 changed files with 500 additions and 300 deletions

View File

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

View File

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

View File

@ -5,6 +5,12 @@ import * as jspb from "google-protobuf";
import * as cofd_pb from "./cofd_pb";
export class UpdateBasicInfoRequest extends jspb.Message {
getOwner(): string;
setOwner(value: string): void;
getCharacterId(): number;
setCharacterId(value: number): void;
getName(): string;
setName(value: string): void;
@ -32,6 +38,8 @@ export class UpdateBasicInfoRequest extends jspb.Message {
export namespace UpdateBasicInfoRequest {
export type AsObject = {
owner: string,
characterId: number,
name: string,
gender: string,
concept: string,

View File

@ -224,11 +224,13 @@ proto.models.proto.cofd.api.UpdateBasicInfoRequest.prototype.toObject = function
*/
proto.models.proto.cofd.api.UpdateBasicInfoRequest.toObject = function(includeInstance, msg) {
var f, obj = {
name: jspb.Message.getFieldWithDefault(msg, 1, ""),
gender: jspb.Message.getFieldWithDefault(msg, 2, ""),
concept: jspb.Message.getFieldWithDefault(msg, 3, ""),
chronicle: jspb.Message.getFieldWithDefault(msg, 4, ""),
age: jspb.Message.getFieldWithDefault(msg, 5, 0)
owner: jspb.Message.getFieldWithDefault(msg, 1, ""),
characterId: jspb.Message.getFieldWithDefault(msg, 2, 0),
name: jspb.Message.getFieldWithDefault(msg, 3, ""),
gender: jspb.Message.getFieldWithDefault(msg, 4, ""),
concept: jspb.Message.getFieldWithDefault(msg, 5, ""),
chronicle: jspb.Message.getFieldWithDefault(msg, 6, ""),
age: jspb.Message.getFieldWithDefault(msg, 7, 0)
};
if (includeInstance) {
@ -267,21 +269,29 @@ proto.models.proto.cofd.api.UpdateBasicInfoRequest.deserializeBinaryFromReader =
switch (field) {
case 1:
var value = /** @type {string} */ (reader.readString());
msg.setName(value);
msg.setOwner(value);
break;
case 2:
var value = /** @type {string} */ (reader.readString());
msg.setGender(value);
var value = /** @type {number} */ (reader.readInt32());
msg.setCharacterId(value);
break;
case 3:
var value = /** @type {string} */ (reader.readString());
msg.setConcept(value);
msg.setName(value);
break;
case 4:
var value = /** @type {string} */ (reader.readString());
msg.setChronicle(value);
msg.setGender(value);
break;
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());
msg.setAge(value);
break;
@ -314,38 +324,52 @@ proto.models.proto.cofd.api.UpdateBasicInfoRequest.prototype.serializeBinary = f
*/
proto.models.proto.cofd.api.UpdateBasicInfoRequest.serializeBinaryToWriter = function(message, writer) {
var f = undefined;
f = message.getName();
f = message.getOwner();
if (f.length > 0) {
writer.writeString(
1,
f
);
}
f = message.getGender();
if (f.length > 0) {
writer.writeString(
f = message.getCharacterId();
if (f !== 0) {
writer.writeInt32(
2,
f
);
}
f = message.getConcept();
f = message.getName();
if (f.length > 0) {
writer.writeString(
3,
f
);
}
f = message.getChronicle();
f = message.getGender();
if (f.length > 0) {
writer.writeString(
4,
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();
if (f !== 0) {
writer.writeInt32(
5,
7,
f
);
}
@ -353,10 +377,10 @@ proto.models.proto.cofd.api.UpdateBasicInfoRequest.serializeBinaryToWriter = fun
/**
* optional string name = 1;
* optional string owner = 1;
* @return {string}
*/
proto.models.proto.cofd.api.UpdateBasicInfoRequest.prototype.getName = function() {
proto.models.proto.cofd.api.UpdateBasicInfoRequest.prototype.getOwner = function() {
return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 1, ""));
};
@ -365,34 +389,34 @@ proto.models.proto.cofd.api.UpdateBasicInfoRequest.prototype.getName = function(
* @param {string} value
* @return {!proto.models.proto.cofd.api.UpdateBasicInfoRequest} returns this
*/
proto.models.proto.cofd.api.UpdateBasicInfoRequest.prototype.setName = function(value) {
proto.models.proto.cofd.api.UpdateBasicInfoRequest.prototype.setOwner = function(value) {
return jspb.Message.setProto3StringField(this, 1, value);
};
/**
* optional string gender = 2;
* @return {string}
* optional int32 character_id = 2;
* @return {number}
*/
proto.models.proto.cofd.api.UpdateBasicInfoRequest.prototype.getGender = function() {
return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 2, ""));
proto.models.proto.cofd.api.UpdateBasicInfoRequest.prototype.getCharacterId = function() {
return /** @type {number} */ (jspb.Message.getFieldWithDefault(this, 2, 0));
};
/**
* @param {string} value
* @param {number} 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);
proto.models.proto.cofd.api.UpdateBasicInfoRequest.prototype.setCharacterId = function(value) {
return jspb.Message.setProto3IntField(this, 2, value);
};
/**
* optional string concept = 3;
* optional string name = 3;
* @return {string}
*/
proto.models.proto.cofd.api.UpdateBasicInfoRequest.prototype.getConcept = function() {
proto.models.proto.cofd.api.UpdateBasicInfoRequest.prototype.getName = function() {
return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 3, ""));
};
@ -401,16 +425,16 @@ proto.models.proto.cofd.api.UpdateBasicInfoRequest.prototype.getConcept = functi
* @param {string} value
* @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);
};
/**
* optional string chronicle = 4;
* optional string gender = 4;
* @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, ""));
};
@ -419,17 +443,53 @@ proto.models.proto.cofd.api.UpdateBasicInfoRequest.prototype.getChronicle = func
* @param {string} value
* @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);
};
/**
* 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}
*/
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 +498,7 @@ proto.models.proto.cofd.api.UpdateBasicInfoRequest.prototype.getAge = function()
* @return {!proto.models.proto.cofd.api.UpdateBasicInfoRequest} returns this
*/
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;
setName(value: string): void;
getGender(): string;
setGender(value: string): void;
getConcept(): string;
setConcept(value: string): void;
getAge(): number;
setAge(value: number): void;
getPlayer(): string;
setPlayer(value: string): void;
getCampaign(): string;
setCampaign(value: string): void;
getChronicle(): string;
setChronicle(value: string): void;
getDescription(): string;
setDescription(value: string): void;
@ -175,8 +184,11 @@ export class CofdSheet extends jspb.Message {
export namespace CofdSheet {
export type AsObject = {
name: string,
gender: string,
concept: string,
age: number,
player: string,
campaign: string,
chronicle: string,
description: string,
strength: number,
dexterity: number,
@ -353,9 +365,9 @@ export namespace CofdSheet {
export enum SystemFieldsCase {
SYSTEM_FIELDS_NOT_SET = 0,
CORE = 28,
MAGE = 29,
CHANGELING = 30,
CORE = 30,
MAGE = 31,
CHANGELING = 32,
}
}

File diff suppressed because it is too large Load Diff

View File

@ -13,6 +13,16 @@ tonic::include_proto!("models.proto.cofd");
pub mod api {
//include!(concat!(env!("OUT_DIR"), "/models.proto.cofd.api.rs"));
tonic::include_proto!("models.proto.cofd.api");
/// 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

View File

@ -37,9 +37,22 @@ 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())
}
#[post("/rpc/cofd/update_basic_info", data = "<info>")]
pub(super) fn update_basic_info<'a>(info: Proto<UpdateBasicInfoRequest>) -> &'a str {
"lol"
#[post("/rpc/cofd/update_basic_info", data = "<req>")]
pub(super) async fn update_basic_info<'a>(
req: Proto<UpdateBasicInfoRequest>,
conn: TenebrousDbConn<'_>,
logged_in_user: Option<&User>,
) -> Result<Proto<ApiResult>, Error> {
let mut character = load_character(&conn, logged_in_user, &req.owner, req.character_id).await?;
let mut sheet: CofdSheet = character.try_deserialize()?;
sheet.name = req.name.clone();
sheet.gender = req.gender.clone();
sheet.concept = req.concept.clone();
character.update_data(&sheet)?;
conn.update_character_sheet(&character).await?;
Ok(Proto(ApiResult::success()))
}
#[post("/rpc/cofd/update_attribute_value", data = "<req>")]