Reimplement attribute updtaes
This commit is contained in:
parent
63571d9711
commit
8f1ddf89dd
|
@ -9,7 +9,7 @@ pub(crate) fn routes() -> Vec<rocket::Route> {
|
||||||
routes![
|
routes![
|
||||||
cofd::update_basic_info,
|
cofd::update_basic_info,
|
||||||
cofd::update_attributes,
|
cofd::update_attributes,
|
||||||
cofd::update_attribute,
|
cofd::update_attribute_value,
|
||||||
cofd::update_skills,
|
cofd::update_skills,
|
||||||
cofd::update_skill_value,
|
cofd::update_skill_value,
|
||||||
cofd::add_condition,
|
cofd::add_condition,
|
||||||
|
@ -94,8 +94,8 @@ mod cofd {
|
||||||
"lol"
|
"lol"
|
||||||
}
|
}
|
||||||
|
|
||||||
#[post("/rpc/cofd/update_attribute", data = "<req>")]
|
#[post("/rpc/cofd/update_attribute_value", data = "<req>")]
|
||||||
pub(super) async fn update_attribute<'a>(
|
pub(super) async fn update_attribute_value<'a>(
|
||||||
req: Proto<UpdateAttributeRequest>,
|
req: Proto<UpdateAttributeRequest>,
|
||||||
conn: TenebrousDbConn<'_>,
|
conn: TenebrousDbConn<'_>,
|
||||||
logged_in_user: Option<&User>,
|
logged_in_user: Option<&User>,
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
import { UpdateSkillValueRequest } from "../_proto/cofd_api_pb";
|
import * as jspb from "google-protobuf";
|
||||||
|
import { 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' };
|
||||||
|
|
||||||
export async function updateSkillValue(params: UpdateSkillValueRequest) {
|
async function makeRequest<T extends jspb.Message>(uri: string, params: T) {
|
||||||
let resp = await fetch('/api/rpc/cofd/update_skill_value', {
|
let resp = await fetch(uri, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: { ...PROTOBUF_CONTENT_TYPE },
|
headers: { ...PROTOBUF_CONTENT_TYPE },
|
||||||
body: params.serializeBinary()
|
body: params.serializeBinary()
|
||||||
|
@ -13,3 +14,11 @@ export async function updateSkillValue(params: UpdateSkillValueRequest) {
|
||||||
console.log("err is", err.text());
|
console.log("err is", err.text());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function updateSkillValue(params: UpdateSkillValueRequest) {
|
||||||
|
await makeRequest('/api/rpc/cofd/update_skill_value', params);
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function updateAttributeValue(params: UpdateAttributeRequest) {
|
||||||
|
await makeRequest('/api/rpc/cofd/update_attribute_value', params);
|
||||||
|
}
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
import { UpdateSkillValueRequest } from "../../_proto/cofd_api_pb";
|
import { UpdateSkillValueRequest, UpdateAttributeRequest } from "../../_proto/cofd_api_pb";
|
||||||
import * as api from "../api";
|
import * as api from "../api";
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
|
type Option<T> = T | null | undefined;
|
||||||
//TODO start refactoring these into a separate script, and make API calls
|
//TODO start refactoring these into a separate script, and make API calls
|
||||||
//take all necessary info (e.g. username and character ID, plus other stuff)
|
//take all necessary info (e.g. username and character ID, plus other stuff)
|
||||||
//as object params.
|
//as object params.
|
||||||
|
@ -9,36 +10,37 @@ import * as api from "../api";
|
||||||
|
|
||||||
const [, , USERNAME, CHARACTER_ID] = window.location.pathname.split('/');
|
const [, , USERNAME, CHARACTER_ID] = window.location.pathname.split('/');
|
||||||
|
|
||||||
//const api = makeAPI(root);
|
|
||||||
//console.log("api is", api);
|
|
||||||
|
|
||||||
function setupAttributes() {
|
function setupAttributes() {
|
||||||
// const attributeInputs = document.querySelectorAll('#skills input[type="number"]');
|
const attributeInputs = document.querySelectorAll('#attributes input[type="number"]');
|
||||||
|
|
||||||
// async function skillValueHandler(event: Event) {
|
async function attributeHandler(event: Event) {
|
||||||
// const input = event.target as HTMLInputElement;
|
const input = event.target as Option<HTMLInputElement>;
|
||||||
// console.log("updating attr");
|
if (!input) return;
|
||||||
// const attribute = input.id;
|
|
||||||
// const newValue = parseInt(input.value);
|
|
||||||
// const params = new UpdateSkillValueRequest();
|
|
||||||
// params.setCharacterUsername(USERNAME);
|
|
||||||
// params.setCharacterId(parseInt(CHARACTER_ID));
|
|
||||||
// params.setSkillName(attribute);
|
|
||||||
// params.setSkillValue(newValue);
|
|
||||||
// await api.updateSkillValue(params);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// Array.from(attributeInputs).forEach(input => {
|
console.log("updating attr");
|
||||||
// input.addEventListener('change', skillValueHandler);
|
const attribute = input.id;
|
||||||
// });
|
const newValue = parseInt(input.value);
|
||||||
|
const params = new UpdateAttributeRequest();
|
||||||
|
params.setCharacterUsername(USERNAME);
|
||||||
|
params.setCharacterId(parseInt(CHARACTER_ID));
|
||||||
|
params.setAttributeName(attribute);
|
||||||
|
params.setAttributeValue(newValue);
|
||||||
|
await api.updateAttributeValue(params);
|
||||||
|
}
|
||||||
|
|
||||||
|
Array.from(attributeInputs).forEach(input => {
|
||||||
|
input.addEventListener('change', attributeHandler);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function setupSkills() {
|
function setupSkills() {
|
||||||
const skillInputs = document.querySelectorAll('#skills input[type="number"]');
|
const skillInputs = document.querySelectorAll('#skills input[type="number"]');
|
||||||
|
|
||||||
async function skillValueHandler(event: Event) {
|
async function skillValueHandler(event: Event) {
|
||||||
const input = event.target as HTMLInputElement;
|
const input = event.target as Option<HTMLInputElement>;
|
||||||
console.log("updating attr");
|
if (!input) return;
|
||||||
|
|
||||||
|
console.log("updating skill");
|
||||||
const attribute = input.id;
|
const attribute = input.id;
|
||||||
const newValue = parseInt(input.value);
|
const newValue = parseInt(input.value);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue