2021-01-05 19:32:03 +00:00
|
|
|
import { UpdateSkillValueRequest, UpdateAttributeRequest } from "../../_proto/cofd_api_pb";
|
2021-01-04 22:36:21 +00:00
|
|
|
import * as api from "../api";
|
|
|
|
|
|
|
|
(async () => {
|
2021-01-05 19:32:03 +00:00
|
|
|
type Option<T> = T | null | undefined;
|
2021-01-04 22:36:21 +00:00
|
|
|
//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)
|
|
|
|
//as object params.
|
|
|
|
//const root = await protobuf.load("/protos/cofd_api.proto");
|
|
|
|
|
|
|
|
const [, , USERNAME, CHARACTER_ID] = window.location.pathname.split('/');
|
|
|
|
|
|
|
|
function setupAttributes() {
|
2021-01-05 19:32:03 +00:00
|
|
|
const attributeInputs = document.querySelectorAll('#attributes input[type="number"]');
|
|
|
|
|
|
|
|
async function attributeHandler(event: Event) {
|
|
|
|
const input = event.target as Option<HTMLInputElement>;
|
|
|
|
if (!input) return;
|
|
|
|
|
|
|
|
console.log("updating attr");
|
|
|
|
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);
|
|
|
|
});
|
2021-01-04 22:36:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function setupSkills() {
|
|
|
|
const skillInputs = document.querySelectorAll('#skills input[type="number"]');
|
|
|
|
|
|
|
|
async function skillValueHandler(event: Event) {
|
2021-01-05 19:32:03 +00:00
|
|
|
const input = event.target as Option<HTMLInputElement>;
|
|
|
|
if (!input) return;
|
|
|
|
|
|
|
|
console.log("updating skill");
|
2021-01-04 22:36:21 +00:00
|
|
|
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(skillInputs).forEach(input => {
|
|
|
|
input.addEventListener('change', skillValueHandler);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
setupAttributes();
|
|
|
|
setupSkills();
|
|
|
|
})().catch(e => {
|
|
|
|
alert(e);
|
|
|
|
});
|