diff --git a/LICENSE b/LICENSE.txt similarity index 99% rename from LICENSE rename to LICENSE.txt index 4db44fb..350c919 100644 --- a/LICENSE +++ b/LICENSE.txt @@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. \ No newline at end of file +SOFTWARE. diff --git a/README.md b/README.md index 3179f3f..35c0e37 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ # Strat-Roulette A roulette style game type picker for FPS games. + +[Here](http://www.sqlitetutorial.net/sqlite-import-csv/) is a website explaining how to upload `csv` into a database. diff --git a/assets/css/index.css b/assets/css/index.css new file mode 100644 index 0000000..e69de29 diff --git a/assets/data/strats.db b/assets/data/strats.db new file mode 100644 index 0000000..ffde73b Binary files /dev/null and b/assets/data/strats.db differ diff --git a/assets/modules/Fetch.js b/assets/modules/Fetch.js new file mode 100644 index 0000000..faa7ef2 --- /dev/null +++ b/assets/modules/Fetch.js @@ -0,0 +1,28 @@ +module.exports.fetchStrat = (paramID) => { + const sqlite = require('sqlite'); + let id = paramID; + let db = new sqlite.Database('../data/strats.db', (err) => { + if (err) { + console.error(err); + } + console.log("Connected to the Strats Database") + }); + + db.serialize((id) => { + db.get('SELECT * FROM Strats WHERE id === $ID_place_holder', { + $ID_place_holder: id + }, (err, rows) => { + if (err) { + console.error(err); + } + return rows; + }) + }) + + db.close((err) => { + if (err) { + console.error(err.message); + } + console.log('Disconnected from the Strats Database'); + }); +} diff --git a/assets/modules/HighestID.js b/assets/modules/HighestID.js new file mode 100644 index 0000000..0aa9df0 --- /dev/null +++ b/assets/modules/HighestID.js @@ -0,0 +1,23 @@ +module.exports.getHighestID = () => { + const sqlite = require('sqlite'); + let db = new sqlite.Database('../data/strats.db', (err) => { + if (err) { + console.error(err); + } + console.log("Connected to the Strats Database") + }); + + db.get('SELECT MAX(id) AS max_id FROM Strats', (err, row) => { + if (err) { + console.error(err); + } + return row.max_id; + }) + + db.close((err) => { + if (err) { + console.error(err); + } + console.log('Disconnected from the Strats Database'); + }); +} diff --git a/assets/modules/RandNum.js b/assets/modules/RandNum.js new file mode 100644 index 0000000..5e381a1 --- /dev/null +++ b/assets/modules/RandNum.js @@ -0,0 +1,14 @@ +generateRandNum = (min, max) => { + let randomNumber = Math.round((max - min) * Math.random() + min); + return randomNumber; +} + +testConnection = () => { + console.log("Connection confirmed: RandNum") +} + + +export { + generateRandNum, + testConnection +}; diff --git a/assets/modules/Write.js b/assets/modules/Write.js new file mode 100644 index 0000000..5d51d5f --- /dev/null +++ b/assets/modules/Write.js @@ -0,0 +1,17 @@ +write = (text) => { + $(".write-WriteTo").text(text); + console.log("Write: " + "\"" + text + "\" " + "was written on the page"); +} +testConnection = () => { + console.log("Connection confirmed: Write") +} +clear = () => { + let html = $(".write-WriteTo").html() + $(".write-WriteTo").text(""); + console.log("Write: " + "Cleared " + html) +} +export { + write, + testConnection, + clear +} diff --git a/data/strats.txt b/data/strats.txt deleted file mode 100644 index f6a31f6..0000000 --- a/data/strats.txt +++ /dev/null @@ -1,3 +0,0 @@ -Use a pistol while crouching the entire game. If dual pistols are avalible, use dual pistols. -Kill using only melee attacks and grenades (throwable weapons) -Fire your gun until there is only one round in the current clip. Start every battle this way. \ No newline at end of file diff --git a/find-strat.py b/find-strat.py deleted file mode 100644 index 5c2b867..0000000 --- a/find-strat.py +++ /dev/null @@ -1,14 +0,0 @@ -import sys -import random -import json - -filePath = "../data/strats.txt" -count = len(open(filePath).readlines( )) -lineNum = randint(1, count) -lines = [0] -with open(filePath) as strats_file: - while strats_file.readline(): - lines.append(strats_file.tell()) - strats_file.seek(lines[lineNum]) - line = strats_file.readline() -return line diff --git a/main.js b/main.js deleted file mode 100644 index 505c097..0000000 --- a/main.js +++ /dev/null @@ -1,20 +0,0 @@ -$(document).ready(function () { - import Write from "https://gist.github.com/Spaceface16518/f91d67bf0745cead14dc6f81d015e187.js"; - - function fetchPython() { - $.ajax({ - type: "POST", - url: "./modules/find-strat.py", - data: { - param: text - } - }).done(function (result) { - console.log(line); - }); - } - - function displayStrat() { - let strat = fetchPython(); - write(strat); - } -}) \ No newline at end of file diff --git a/index.html b/src/index.html similarity index 50% rename from index.html rename to src/index.html index e365a9d..1d81dc6 100644 --- a/index.html +++ b/src/index.html @@ -6,21 +6,17 @@ Strat Roulette - + - + - - +
- -
+ +
diff --git a/src/index.js b/src/index.js new file mode 100644 index 0000000..e37cea5 --- /dev/null +++ b/src/index.js @@ -0,0 +1,34 @@ +import { write, testConnection, clear } from "../assets/modules/Write.js"; +import { generateRandNum, testConnection } from "../assets/modules/RandNum.js"; +const fetch = require("./modules/Fetch.js"); +const highestID = require("./modules/HighestID.js") + +function fetchStrat() { + let highestID = highestID.getHighestID(); + let id = generateRandNum(1, highestID); + let strat = fetch.fetchStrat(id) + return strat +} + +function displayStrat(strat) { + console.log("Displaying strat: " + strat); + write(strat) +} + +function clearStrat() { + clear() +} + +$(document).ready(function(){ + $("#chooseButton").click(function(){ + console.log("Choose button clicked") + let strat = fetchStrat(); + displayStrat(strat); + }); + $("#resetButton").click(function(){ + console.log("reset button clicked"); + clearStrat(); + }); +}) + +console.log("Init") diff --git a/style.css b/style.css deleted file mode 100644 index d74910a..0000000 --- a/style.css +++ /dev/null @@ -1,11 +0,0 @@ -* { - box-sizing: border-box -} - -body {} - -#result {} - -.stand-out {} - -h1 {} \ No newline at end of file