From b3253922df63188ab6859f9c880baf554a5ac9a9 Mon Sep 17 00:00:00 2001 From: projectmoon Date: Tue, 5 Jan 2021 21:25:26 +0000 Subject: [PATCH] Clean up files and remove things that no longer need to exist. --- .../characters/new_character.html.tera | 2 - .../scripts/_proto/cofd_api_pb_service.d.ts | 61 ----------------- static/scripts/_proto/cofd_api_pb_service.js | 59 ---------------- static/scripts/api.js | 68 ------------------- static/scripts/characters/edit.js | 48 ------------- static/scripts/characters/new-character.js | 17 ----- static/scripts/src/blah.ts | 8 --- static/scripts/src/index.ts | 26 ------- static/scripts/webpack.config.js | 4 +- 9 files changed, 1 insertion(+), 292 deletions(-) delete mode 100644 static/scripts/api.js delete mode 100644 static/scripts/characters/edit.js delete mode 100644 static/scripts/characters/new-character.js delete mode 100644 static/scripts/src/blah.ts delete mode 100644 static/scripts/src/index.ts diff --git a/src/templates/characters/new_character.html.tera b/src/templates/characters/new_character.html.tera index 7ee6b8f..e5ba3c3 100644 --- a/src/templates/characters/new_character.html.tera +++ b/src/templates/characters/new_character.html.tera @@ -1,8 +1,6 @@ {% extends "base" %} {% block content %} - -
New character page. diff --git a/static/scripts/_proto/cofd_api_pb_service.d.ts b/static/scripts/_proto/cofd_api_pb_service.d.ts index 69b3838..34a251d 100644 --- a/static/scripts/_proto/cofd_api_pb_service.d.ts +++ b/static/scripts/_proto/cofd_api_pb_service.d.ts @@ -1,64 +1,3 @@ // package: models.proto.cofd.api // file: cofd_api.proto -import * as cofd_api_pb from "./cofd_api_pb"; -import * as cofd_pb from "./cofd_pb"; -import {grpc} from "@improbable-eng/grpc-web"; - -type CofdApiUpdateSkillValue = { - readonly methodName: string; - readonly service: typeof CofdApi; - readonly requestStream: false; - readonly responseStream: false; - readonly requestType: typeof cofd_api_pb.UpdateSkillValueRequest; - readonly responseType: typeof cofd_pb.CofdSheet.Skill; -}; - -export class CofdApi { - static readonly serviceName: string; - static readonly UpdateSkillValue: CofdApiUpdateSkillValue; -} - -export type ServiceError = { message: string, code: number; metadata: grpc.Metadata } -export type Status = { details: string, code: number; metadata: grpc.Metadata } - -interface UnaryResponse { - cancel(): void; -} -interface ResponseStream { - cancel(): void; - on(type: 'data', handler: (message: T) => void): ResponseStream; - on(type: 'end', handler: (status?: Status) => void): ResponseStream; - on(type: 'status', handler: (status: Status) => void): ResponseStream; -} -interface RequestStream { - write(message: T): RequestStream; - end(): void; - cancel(): void; - on(type: 'end', handler: (status?: Status) => void): RequestStream; - on(type: 'status', handler: (status: Status) => void): RequestStream; -} -interface BidirectionalStream { - write(message: ReqT): BidirectionalStream; - end(): void; - cancel(): void; - on(type: 'data', handler: (message: ResT) => void): BidirectionalStream; - on(type: 'end', handler: (status?: Status) => void): BidirectionalStream; - on(type: 'status', handler: (status: Status) => void): BidirectionalStream; -} - -export class CofdApiClient { - readonly serviceHost: string; - - constructor(serviceHost: string, options?: grpc.RpcOptions); - updateSkillValue( - requestMessage: cofd_api_pb.UpdateSkillValueRequest, - metadata: grpc.Metadata, - callback: (error: ServiceError|null, responseMessage: cofd_pb.CofdSheet.Skill|null) => void - ): UnaryResponse; - updateSkillValue( - requestMessage: cofd_api_pb.UpdateSkillValueRequest, - callback: (error: ServiceError|null, responseMessage: cofd_pb.CofdSheet.Skill|null) => void - ): UnaryResponse; -} - diff --git a/static/scripts/_proto/cofd_api_pb_service.js b/static/scripts/_proto/cofd_api_pb_service.js index 0daad8c..34a251d 100644 --- a/static/scripts/_proto/cofd_api_pb_service.js +++ b/static/scripts/_proto/cofd_api_pb_service.js @@ -1,62 +1,3 @@ // package: models.proto.cofd.api // file: cofd_api.proto -var cofd_api_pb = require("./cofd_api_pb"); -var cofd_pb = require("./cofd_pb"); -var grpc = require("@improbable-eng/grpc-web").grpc; - -var CofdApi = (function () { - function CofdApi() {} - CofdApi.serviceName = "models.proto.cofd.api.CofdApi"; - return CofdApi; -}()); - -CofdApi.UpdateSkillValue = { - methodName: "UpdateSkillValue", - service: CofdApi, - requestStream: false, - responseStream: false, - requestType: cofd_api_pb.UpdateSkillValueRequest, - responseType: cofd_pb.CofdSheet.Skill -}; - -exports.CofdApi = CofdApi; - -function CofdApiClient(serviceHost, options) { - this.serviceHost = serviceHost; - this.options = options || {}; -} - -CofdApiClient.prototype.updateSkillValue = function updateSkillValue(requestMessage, metadata, callback) { - if (arguments.length === 2) { - callback = arguments[1]; - } - var client = grpc.unary(CofdApi.UpdateSkillValue, { - request: requestMessage, - host: this.serviceHost, - metadata: metadata, - transport: this.options.transport, - debug: this.options.debug, - onEnd: function (response) { - if (callback) { - if (response.status !== grpc.Code.OK) { - var err = new Error(response.statusMessage); - err.code = response.status; - err.metadata = response.trailers; - callback(err, null); - } else { - callback(null, response.message); - } - } - } - }); - return { - cancel: function () { - callback = null; - client.close(); - } - }; -}; - -exports.CofdApiClient = CofdApiClient; - diff --git a/static/scripts/api.js b/static/scripts/api.js deleted file mode 100644 index 825e0a5..0000000 --- a/static/scripts/api.js +++ /dev/null @@ -1,68 +0,0 @@ -function makeAPI(root) { - //Protobuf types - const UpdateAttributeRequestType = 'models.proto.cofd.api.UpdateAttributeRequest'; - const UpdateAttributeRequest = root.lookupType(UpdateAttributeRequestType); - - const UpdateSkillValueRequestType = 'models.proto.cofd.api.UpdateSkillValueRequest'; - const UpdateSkillValueRequest = root.lookupType(UpdateSkillValueRequestType); - - //TODO rpc-ify - const SkillSpecializationUpdateType = 'models.proto.cofd.api.SkillSpecializationsUpdate'; - const SkillSpecializationsUpdate = root.lookupType(SkillSpecializationUpdateType); - - const protobufContentType = (messageType) => - ({ 'Content-Type': 'application/x-protobuf; messageType="' + messageType + '"' }); - - function verifyAndCreate(protobufType, payload) { - let err = protobufType.verify(payload); - if (err) throw err; - return protobufType.create(payload); - } - - async function updateAttribute(params) { - const { username, characterID, attribute, newValue } = params; - - let req = verifyAndCreate(UpdateAttributeRequest, { - characterUsername: username, - characterId: parseInt(characterID), - attributeName: attribute, - attributeValue: parseInt(newValue) - }); - - let resp = await fetch('/api/rpc/cofd/update_attribute', { - method: 'POST', - headers: { ... protobufContentType(UpdateAttributeRequestType) }, - body: UpdateAttributeRequest.encode(req).finish() - }).then(async resp => { - console.log("resp is", await resp.text()); - }).catch(async err => { - console.log("err is", err.text()); - }); - } - - async function updateSkillValue(params) { - const { username, characterID, skillName, newValue } = params; - - let req = verifyAndCreate(UpdateSkillValueRequest, { - characterUsername: username, - characterId: parseInt(characterID), - skillName: skillName, - skillValue: parseInt(newValue) - }); - - let resp = await fetch('/api/rpc/cofd/update_skill_value', { - method: 'POST', - headers: { ... protobufContentType(UpdateSkillValueRequestType) }, - body: UpdateSkillValueRequest.encode(req).finish() - }).then(async resp => { - console.log("resp is", await resp.text()); - }).catch(async err => { - console.log("err is", err.text()); - }); - } - - return { - updateAttribute, - updateSkillValue - }; -} diff --git a/static/scripts/characters/edit.js b/static/scripts/characters/edit.js deleted file mode 100644 index bb97d83..0000000 --- a/static/scripts/characters/edit.js +++ /dev/null @@ -1,48 +0,0 @@ -(async () => { - //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('/'); - - //const api = makeAPI(root); - //console.log("api is", api); - - function setupAttributes() { - const attributeInputs = document.querySelectorAll('#attributes input[type="number"]'); - - async function attributeHandler(event) { - console.log("updating attr"); - const attribute = event.target.id; - const newValue = parseInt(event.target.value); - const params = { username: USERNAME, characterID: CHARACTER_ID, attribute, newValue }; - await api.updateAttribute(params); - } - - Array.from(attributeInputs).forEach(input => { - input.addEventListener('change', attributeHandler); - }); - } - - function setupSkills() { - const attributeInputs = document.querySelectorAll('#skills input[type="number"]'); - - async function skillValueHandler(event) { - console.log("updating skill value"); - const skillName = event.target.id; - const newValue = parseInt(event.target.value); - const params = { username: USERNAME, characterID: CHARACTER_ID, skillName, newValue }; - await api.updateSkillValue(params); - } - - Array.from(attributeInputs).forEach(input => { - input.addEventListener('change', skillValueHandler); - }); - } - - setupAttributes(); - setupSkills(); -})().catch(e => { - alert(e); -}); diff --git a/static/scripts/characters/new-character.js b/static/scripts/characters/new-character.js deleted file mode 100644 index ed36c7a..0000000 --- a/static/scripts/characters/new-character.js +++ /dev/null @@ -1,17 +0,0 @@ -document.addEventListener('DOMContentLoaded', event => { - protobuf.load("/protos/cofd.proto").then(function(root) { - console.log("root is", root); - let CofdSheet = root.lookupType("models.proto.cofd.CofdSheet"); - let sheet = CofdSheet.fromObject({ name: 'lol', strength: 100 }); - let buffer = CofdSheet.encode(sheet).finish(); - - fetch('/proto-test', { - method: 'POST', - body: buffer - }).then(async resp => { - console.log("resp is", await resp.text()); - }).catch(async err => { - console.log("err is", err.text()); - }); - }); -}); diff --git a/static/scripts/src/blah.ts b/static/scripts/src/blah.ts deleted file mode 100644 index 30d12bd..0000000 --- a/static/scripts/src/blah.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { grpc } from "@improbable-eng/grpc-web"; -import { CofdApi } from "../_proto/cofd_api_pb_service"; -import { UpdateSkillValueRequest } from "../_proto/cofd_api_pb"; - -let x = new UpdateSkillValueRequest(); -x.setCharacterId(1); -x.setCharacterUsername("guy"); -console.log("hello", x); diff --git a/static/scripts/src/index.ts b/static/scripts/src/index.ts deleted file mode 100644 index 0849a05..0000000 --- a/static/scripts/src/index.ts +++ /dev/null @@ -1,26 +0,0 @@ -import * as api from "./api"; -import { grpc } from "@improbable-eng/grpc-web"; -import { CofdApi } from "../_proto/cofd_api_pb_service"; -import { UpdateSkillValueRequest } from "../_proto/cofd_api_pb"; -import { CofdSheet } from "../_proto/cofd_pb"; - -console.log(api.updateSkillValue); -let x = new UpdateSkillValueRequest(); -x.setCharacterId(1); -x.setCharacterUsername("guy"); -console.log("hello", x); - -grpc.invoke(CofdApi.UpdateSkillValue, { - request: x, - host: window.location.protocol + "//" + window.location.hostname + ":8080", - onMessage: (message: CofdSheet.Skill) => { - console.log("got skill: ", message.toObject()); - }, - onEnd: (code: grpc.Code, msg: string | undefined, trailers: grpc.Metadata) => { - if (code == grpc.Code.OK) { - console.log("all ok") - } else { - console.log("hit an error", code, msg, trailers); - } - } -}); diff --git a/static/scripts/webpack.config.js b/static/scripts/webpack.config.js index 9d7bdf8..98236b7 100644 --- a/static/scripts/webpack.config.js +++ b/static/scripts/webpack.config.js @@ -20,9 +20,7 @@ function packPage(page, chunks) { module.exports = { entry: { - index: "./src/index.ts", edit_character: "./src/characters/edit.ts", - blah: "./src/blah.ts", }, optimization: { runtimeChunk: "single", @@ -51,7 +49,7 @@ module.exports = { }, plugins: [ new CleanWebpackPlugin(), - packPage('login.html.tera', ['index']), + packPage('login.html.tera'), packPage('base.html.tera'), packPage('error.html.tera'), packPage('index.html.tera'),