Skip to content

Commit

Permalink
General changes
Browse files Browse the repository at this point in the history
  • Loading branch information
plasma4 committed Aug 30, 2024
1 parent ad1b939 commit 4cef9f5
Show file tree
Hide file tree
Showing 5 changed files with 152 additions and 18 deletions.
Binary file modified Magix/magix2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions MagixData.js

Large diffs are not rendered by default.

146 changes: 140 additions & 6 deletions magix-wiki.html
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@
color: white;
}

#modCreator>button {
background-color: white;
color: #585858;
}

input,
select {
border-radius: 5px;
Expand All @@ -127,6 +132,14 @@
white-space: pre;
}

textarea {
resize: none;
color: white;
background-color: #8884;
border: solid 1px black;
border-radius: 10px;
}

.nopre {
white-space: normal;
}
Expand Down Expand Up @@ -253,18 +266,55 @@ <h1>Explore Magix data</h1>
<br>
<label for="a"><input type="checkbox" id="a"> Use the elf race instead of the human race</label>
<button>Export all civ JSON</button><button>Export JSON for this category</button>
<br>
<button>Show mod creator</button>
<hr>
<span id="modCreator" style="display:none">
To select an item you want to modify, click on it. Then, you'll be able to mess with it!
Click on the button below to make a new item of the type you selected at the top.
<br>
<button>Create a new tech</button>
<button>Update data</button>
<br>
<span id="inputs"></span>
<hr>
<textarea rows="20" cols="100" disabled
placeholder="The automatically generated script will output here. Note that the comment at the start provides important metadata so that you can import it back in to here (make sure to keep it somewhere safe)! Copy that comment when you're importing a script in."></textarea>
<br>
<textarea placeholder="Import script data here..."></textarea>
<br>
<button>Import script</button>
<hr>
</span>
<div></div>

<script>
"use strict"
var modCreator = 0
document.getElementsByTagName("script")[0].remove()
document.getElementsByTagName("button")[0].addEventListener("click", function () {
exportJSON(false)
})
document.getElementsByTagName("button")[1].addEventListener("click", function () {
exportJSON(true)
})
document.getElementsByTagName("button")[2].addEventListener("click", function () {
if (modCreator === 0) {
document.getElementsByTagName("textarea")[0].value = ""
}
modCreator = !modCreator
if (modCreator) {
document.getElementById("modCreator").removeAttribute("style")
document.getElementsByTagName("button")[2].textContent = "Hide mod creator"
} else {
document.getElementById("modCreator").style.display = "none"
document.getElementsByTagName("button")[2].textContent = "Show mod creator"
}
})
document.getElementsByTagName("button")[3].addEventListener("click", createNewThing)
document.getElementsByTagName("button")[4].addEventListener("click", updateThing)
document.getElementsByTagName("button")[5].addEventListener("click", importScript)
var isModding = true
var input = document.getElementsByTagName("input")[0]
var select = document.getElementsByTagName("select")[0]
var selectDebug = document.getElementsByTagName("select")[1]
Expand All @@ -289,6 +339,8 @@ <h1>Explore Magix data</h1>
var itemCategory = obj[category]
var inputValue = input.value.trim()
var val = selectDebug.selectedIndex - 1
var categorySingular = category === "policies" ? "policy" : category.slice(0, category.length - 1)
document.getElementsByTagName("button")[3].textContent = newData[category] ? "Create a new " + categorySingular : (categorySingular === "achievement" ? "You are unable to create an " : "You are unable to create a ") + categorySingular + " with the mod creator."
if (val > 0) {
var itemsToSearch = val === 1 ? ["name", "displayName", "visible", "icon", "civ", "special", "names", "goods", "res", "mult", "image", "ocean", "score", "desc", "hidden", "category", "startWith", "colorGood", "colorBad", "fractional", "turnToByContext", "meta", "getIcon", "partOf", "subRes", "wonder", "wideIcon", "threexthreeIcon", "cost", "costPerStep", "steps", "messageOnStart", "finalStepCost", "finalStepDesc", "use", "req", "modes", "gizmos", "limitPer", "upkeep", "startMode", "tutorialMesg", "chance", "id"] : ["name", "displayName", "type", "tier", "visible", "icon", "civ", "special", "plural", "names", "goods", "res", "mult", "image", "ocean", "score", "desc", "hidden", "category", "startWith", "colorGood", "colorBad", "fractional", "turnToByContext", "meta", "tick", "getDisplayAmount", "getIcon", "partOf", "subRes", "wonder", "wideIcon", "threexthreeIcon", "cost", "costPerStep", "steps", "messageOnStart", "finalStepCost", "finalStepDesc", "use", "req", "modes", "gizmos", "limitPer", "upkeep", "startMode", "effectsOff", "effects", "tutorialMesg", "chance", "id", "mod", "precededBy", "leadsTo"]
var text = []
Expand All @@ -308,7 +360,6 @@ <h1>Explore Magix data</h1>
} else {
inputValue = itemCategory
}
var categorySingular = category.slice(0, category.length - 1)
for (var i = 0; i < inputValue.length; i++) {
var search = inputValue[i]
if (val == 3) {
Expand Down Expand Up @@ -441,7 +492,7 @@ <h1>Explore Magix data</h1>
}
if (t.threexthreeIcon) {
var icon = getIcon(t.threexthreeIcon, true, civ2)
text += '<div class="triple noclick" style="background-image:' + icon[0] + ';background-position:' + icon[1] + '"></div><br>'
text += '<div class="triple noclick" style="background-image:' + icon[0] + ';background-position:' + icon[1] + '"></div><br><br><br><br><br><br>'
}

if (t.icon.length > 3) {
Expand Down Expand Up @@ -512,7 +563,7 @@ <h1>Explore Magix data</h1>
}
c = t.startWith
if (c) {
text += "<br>Tech is avaliable at the start: yes"
text += "<br>Is avaliable at the start: yes"
}
c = t.skip || (t.req && (t.req.tribalism === false))
if (c) {
Expand Down Expand Up @@ -584,8 +635,8 @@ <h1>Explore Magix data</h1>
for (var m = 0; m < modeLen; m++) {
var key = modeKeys[m]
var mode = t.modes[key]
var icon = getIcon(mode.icon, true, civ2)
text += "<li><strong>" + mode.name + '</strong><ul><li>Internal ID: <span class="mono">' + key + "</span></li><li>Uses: " + parseRes(objc, mode.use) + "</li><li>Requires: " + parseReq(objc, mode.req) + "</li><li>Description: " + parseDesc(mode.desc) + '</li><li>Icon: <div class="icon noclick" style="background-image:' + icon[0] + ';background-position:' + icon[1] + '"></div></li></ul></li>'
var icon = mode.icon ? getIcon(mode.icon, true, civ2) : null
text += "<li><strong>" + mode.name + '</strong><ul><li>Internal ID: <span class="mono">' + key + "</span></li><li>Uses: " + parseRes(objc, mode.use) + "</li><li>Requires: " + parseReq(objc, mode.req) + "</li><li>Description: " + parseDesc(mode.desc) + '</li><li>Icon: ' + (icon ? '<div class="icon noclick" style="background-image:' + icon[0] + ';background-position:' + icon[1] + '"></div>' : 'none') + '</li></ul></li>'
}
text += "</ul>"
}
Expand Down Expand Up @@ -652,6 +703,10 @@ <h1>Explore Magix data</h1>
if (max) {
info += " with its gathering capped at " + max
}
var every = effect.every
if (every && every !== 1) {
info += " every " + every + " ticks"
}
if (info) result.push(info)
}
return result
Expand Down Expand Up @@ -885,7 +940,7 @@ <h1>Explore Magix data</h1>
bgP.push((-bit[0] * 24 * iconScale) + 'px ' + (-bit[1] * 24 * iconScale) + 'px');
bit = [];
if (typeof icon[i] == 'string') {
bg.push('url(' + (civ2 ? civ2Object : civ1Object).sheets[icon[i]].replaceAll("https://file\.garden/.+?/", "Magix//") + ')');
bg.push('url(' + (civ2 ? civ2Object : civ1Object).sheets[icon[i]].replaceAll("https://file\.garden/.+?/", "Magix/") + ')');
}
else {
bg.push('url(img/iconSheet.png?v=1)');
Expand Down Expand Up @@ -918,6 +973,85 @@ <h1>Explore Magix data</h1>
URL.revokeObjectURL(link.href)
}

var inputsToUse = {
achievements: ["name", "displayName", "desc", "tier", "visible", "icon", "civ", "special", "plural"],
lands: ["name", "displayName", "desc", "names", "goods", "icon", "image", "ocean", "score"],
goods: ["name", "displayName", "desc", "res", "icon", "mult"],
resources: ["name", "displayName", "hidden", "desc", "category", "startWith", "colorGood", "colorBad", "icon", "fractional", "turnToByContext", "meta"],
units: ["name", "displayName", "desc", "wonder", "icon", "wideIcon", "threexthreeIcon", "cost", "costPerStep", "steps", "type", "messageOnStart", "finalStepCost", "finalStepDesc", "use", "req", "category", "modes", "gizmos", "limitPer", "upkeep"],
policies: ["name", "displayName", "desc", "icon", "startMode", "req", "modes", "category"],
techs: ["name", "displayName", "desc", "icon", "type", "cost", "category", "startWith", "tier", "chance", "req", "tutorialMesg"],
traits: ["name", "displayName", "desc", "icon", "type", "cost", "category", "startWith", "tier", "chance", "req"]
}
var newData = { techs: [], units: [], resources: [], traits: [] }
var selectedID = -1
var selectedType = null
function createNewThing() {
var c = select.value
var category = newData[select.value]
if (category != null) {
var categorySingular = c.slice(0, c.length - 1)
var len = category.length
category.push({ name: "new " + categorySingular, displayName: "New " + categorySingular, icon: [0, 0], cost: {}, req: {} })
selectedID = len
selectedType = c
var inputs = inputsToUse[c]
var result = ""
for (var i = 0; i < inputs.length; i++) {
result += '<input placeholder="' + inputs[i] + '">'
}
document.getElementsByTagName("span")[2].innerHTML = result
generateScript()
}
}

function updateThing() {
var tech = newData[selectedType][selectedID]
var inputs = document.getElementsByTagName("span")[2].children
for (var i = 0; i < inputs.length; i++) {
var val = inputs[i].value.trim()
if (val.length !== 0) {
tech[inputsToUse[i]] = val
}
}
generateScript()
}

function generateScript() {
var script = ""
var things = newData.techs
for (var i = 0; i < things.length; i++) {
script += "\r\nnew G.Tech(" + JSON.stringify(things[i]) + ")"
}
var things = newData.units
for (var i = 0; i < things.length; i++) {
script += "\r\nnew G.Unit(" + JSON.stringify(things[i]) + ")"
}
var things = newData.resources
for (var i = 0; i < things.length; i++) {
script += "\r\nnew G.Res(" + JSON.stringify(things[i]) + ")"
}
var things = newData.traits
for (var i = 0; i < things.length; i++) {
script += "\r\nnew G.Trait(" + JSON.stringify(things[i]) + ")"
}
document.getElementsByTagName("textarea")[0].value = "// " + JSON.stringify(newData) + "\r\n" + script
}

function importScript() {
var value = document.getElementsByTagName("textarea")[1].value
var enter1 = value.indexOf("\r")
var enter2 = value.indexOf("\n")
if (enter1 !== -1 || enter2 !== -1) {
value = value.slice(0, enter1 === -1 ? enter2 : enter1).trim()
} else {
value = value.trim()
}
value = JSON.parse(value.slice(0, 2) === "//" ? value.slice(2) : value)
console.warn("Tried to import:", value)
}


changeFunc()
</script>
</body>
Expand Down
Loading

0 comments on commit 4cef9f5

Please sign in to comment.