Skip to content

Commit

Permalink
resolves #22 by adding in checkmarks for multi-select fields, and als…
Browse files Browse the repository at this point in the history
…o adds in option for fields to be oriented horizontally or vertically. introduces concept of "column updating" that can convert a column to a new default (by adding missing fields) if necessary.
  • Loading branch information
kkukshtel committed Oct 16, 2020
1 parent b126329 commit b66bf97
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 41 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ Columns define the fields of a sheet that a line can have data for. Columns can
| Bool | ![Bool Icon](./images/icons/newBool.png) | True / False boolean value. | ```true``` or ```false``` | ```true``` |
| Image | ![Image Icon](./images/icons/newImage.png) | Path to an image relative to the location of the Depot file (displayed in the sheet) | String relative path to the image | ```""``` |
| Single Select | ![Single Select Icon](./images/icons/newEnum.png) | Exclusive choice between a set number of choices | String value | ```""``` |
| Multi Select | ![Multi Select Icon](./images/icons/newMulti.png) | Several choices between a set number of choices | Array of selected values as string | ```""``` |
| Multi Select | ![Multi Select Icon](./images/icons/newMulti.png) | Several choices between a set number of choices | Array of selected values as strings | ```[]``` |
| Line Reference | ![Line Reference Icon](./images/icons/newLineLink.png) | A reference to a line in a sheet in the current Depot file | String GUID of selected line | ```""``` |
| Sheet Reference | ![Sheet Reference Icon](./images/icons/newSheetLink.png) | A reference to a sheet in the current Depot file | String GUID of selected sheet | ```""``` |
| List | ![List Icon](./images/icons/newList.png) | An array of structured data | Array of structured values | ```[]``` |
Expand Down
44 changes: 22 additions & 22 deletions examples/example.dpo
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,7 @@
"Spawns": [
{
"guid": "b59c1a91-3127-4577-96cc-64cbc0faf207",
"id": "0",
"Creature": "9742fc00-3d8a-49bf-826e-1e085a594ad0",
"id": "Dragon",
"SpawnChance": 0.1,
"Drops": [
{
Expand All @@ -210,12 +209,12 @@
"Item": "2f90039f-4a9d-4164-a3aa-0ca1c3e2843b",
"Chance": 60
}
]
],
"Data": "9742fc00-3d8a-49bf-826e-1e085a594ad0"
},
{
"guid": "bb4dc09b-0b69-4130-9f37-aebf149f539f",
"id": "1",
"Creature": "8ab58bf6-52d0-403f-863e-5e3d9150b307",
"id": "Bear",
"SpawnChance": 0.6,
"Drops": [
{
Expand All @@ -224,12 +223,12 @@
"Item": "9f8ed548-24e0-4ba2-8af9-b36a503a4532",
"Chance": 38
}
]
],
"Data": "8ab58bf6-52d0-403f-863e-5e3d9150b307"
},
{
"guid": "7903c624-9acc-4684-a90e-1e078216dd1e",
"id": "2",
"Creature": "d1892cc6-561d-4421-8412-ce2e12b695c0",
"id": "Lion",
"Drops": [
{
"guid": "c7ecad9a-9f9c-41ee-bd69-962257bf9c1b",
Expand All @@ -238,7 +237,8 @@
"Chance": 49
}
],
"SpawnChance": 0.2
"SpawnChance": 0.2,
"Data": "d1892cc6-561d-4421-8412-ce2e12b695c0"
}
]
},
Expand All @@ -248,8 +248,7 @@
"Spawns": [
{
"guid": "62517f0d-3278-4790-a396-b1ab94794031",
"id": "0",
"Creature": "effe33cf-aa70-4147-a0a3-c4c94636bd9a",
"id": "Shark",
"SpawnChance": 0.9,
"Drops": [
{
Expand All @@ -258,12 +257,12 @@
"Item": "ad56ccdf-caad-4c52-8db8-fde59913e42c",
"Chance": 29
}
]
],
"Data": "effe33cf-aa70-4147-a0a3-c4c94636bd9a"
},
{
"guid": "48c0da60-914f-4465-aeb1-99fe5ed93755",
"id": "1",
"Creature": "69b0dd0d-ac65-4398-aef5-81b291f722a6",
"id": "Raven",
"SpawnChance": -2,
"Drops": [
{
Expand All @@ -272,7 +271,8 @@
"Item": "ad56ccdf-caad-4c52-8db8-fde59913e42c",
"Chance": 8
}
]
],
"Data": "69b0dd0d-ac65-4398-aef5-81b291f722a6"
}
]
},
Expand All @@ -282,8 +282,7 @@
"Spawns": [
{
"guid": "58260fbb-65b5-4339-bc78-e51d236531b8",
"id": "0",
"Creature": "9742fc00-3d8a-49bf-826e-1e085a594ad0",
"id": "Dragon",
"SpawnChance": 0.6,
"Drops": [
{
Expand All @@ -304,12 +303,12 @@
"Item": "ad56ccdf-caad-4c52-8db8-fde59913e42c",
"Chance": 89
}
]
],
"Data": "9742fc00-3d8a-49bf-826e-1e085a594ad0"
},
{
"guid": "8c4c5dfe-e765-4eb4-b72b-ae7b30277988",
"id": "1",
"Creature": "69b0dd0d-ac65-4398-aef5-81b291f722a6",
"id": "Raven",
"SpawnChance": 0.9,
"Drops": [
{
Expand All @@ -318,7 +317,8 @@
"Item": "2f90039f-4a9d-4164-a3aa-0ca1c3e2843b",
"Chance": 5
}
]
],
"Data": "69b0dd0d-ac65-4398-aef5-81b291f722a6"
}
]
}
Expand Down Expand Up @@ -415,7 +415,7 @@
{
"typeStr": "lineReference",
"guid": "3f35cb3f-0501-4dee-a678-e368b1d0fd75",
"name": "Creature",
"name": "Data",
"description": "new line reference field",
"sheet": "a0c417ca-b70d-47f2-8335-da97a81744eb",
"defaultValue": "",
Expand Down
43 changes: 35 additions & 8 deletions src/svelte/Depot/Depot.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -370,10 +370,7 @@ function handleConfigUpdate(event) {
}
});
data.sheets.splice(selectedSheet,1);
if(selectedSheet >= data.sheets.length)
{
focusSheet(selectedSheet - 1 < 0 ? 0 : selectedSheet - 1);
}
focusSheet(0);
//delete any references to this and set to ""
data.sheets.forEach(sheet => {
var sheetRefColumns = sheet.columns.filter(column => column.typeStr === "sheetReference");
Expand Down Expand Up @@ -448,6 +445,36 @@ function handleConfigUpdate(event) {
case "close":
editorConfig = {"active":false};
break;
case "upgradeColumnData":
//this updates a column with a new config
let sheetIndex = data.sheets.findIndex(sheet => sheet.guid === editorConfig.sheetGUID);
var index = data.sheets[sheetIndex].columns.findIndex(x => x.name === editorConfig.originalData.name); //old name, dont use a new name we may have input into editordata
//find discrepancies
let targetColumn = data.sheets[sheetIndex].columns[index];
Object.keys(defaults[editorData.typeStr]).forEach(key => {
if(key !== "configurable") {
if (!(key in targetColumn)){
targetColumn[key] = defaults[editorData.typeStr][key];
}
} else {
Object.keys(defaults[editorData.typeStr]["configurable"]).forEach(configKey => {
if (!(configKey in targetColumn["configurable"])){
targetColumn["configurable"][configKey] = defaults[editorData.typeStr]["configurable"][configKey];
}
});
}
});
sheetsUpdated();
handleTableAction({"detail":{
"type" : "editorUpdate",
"data" : {
"active" : true,
"operation" : "edit",
"editType" : editorConfig.originalData.name,
"sheetGUID" : editorConfig.sheetGUID
}
}});
break;
default:
editorConfig = {"active":false};
break;
Expand Down Expand Up @@ -478,21 +505,21 @@ function handleTableAction(event) {
switch (event.detail.type) {
case "editorUpdate":
editorConfig = event.detail.data;
editorConfig["bannedNames"] = getBannedNames(event.detail.data.sheetGUID,editorConfig);
editorConfig["bannedNames"] = getBannedNames(editorConfig.sheetGUID,editorConfig);
editorConfig["depotInfo"] = depotFileInfo;
switch (event.detail.data.operation) {
switch (editorConfig.operation) {
case "new":
editorData = JSON.parse(JSON.stringify(defaults[editorConfig.editType]));
editorData["guid"] = uuidv4(); //assign columns and sheets guids
if(event.detail.data.editType === "lineReference")
if(editorConfig.editType === "lineReference")
{
//not sure why enum value not setting to default in the configurator, so set a default here
let defSheet = data.sheets.find(s => s.hidden !== true).guid; //get first unhidden sheet
editorData["sheet"] = defSheet;
}
break;
case "edit":
switch (event.detail.data.editType) {
switch (editorConfig.editType) {
case "sheet":
editorConfig["originalData"] = JSON.parse(JSON.stringify(data.sheets[sheetIndex]));
editorData = JSON.parse(JSON.stringify(data.sheets[sheetIndex]));
Expand Down
36 changes: 36 additions & 0 deletions src/svelte/Depot/DepotConfigurator.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ function saveBlob() {
function deleteBlob() {
configUpdate("delete");
}
function upgradeColumn() {
configUpdate("upgradeColumnData");
}
let validName = true;
// $: disabled = !validName;
Expand Down Expand Up @@ -81,9 +84,39 @@ $: {
}
}
let needsColumnUpdate = false;
$: {
if(config.operation === "edit" && config.editType !== "sheet") {
needsColumnUpdate = false;
Object.keys(defaults[data.typeStr]).forEach(key => {
if(key !== "configurable") {
if (!(key in data)){
needsColumnUpdate = true;
return;
}
} else {
Object.keys(defaults[data.typeStr]["configurable"]).forEach(configKey => {
if (!(configKey in data["configurable"])){
needsColumnUpdate = true;
return;
}
});
}
});
} else {
needsColumnUpdate = false;
}
}
</script>
{#if config.active}
<p>{configTitle}</p>
{#if needsColumnUpdate}
Depot has been updated since you first created this column. Click below to update this column to the latest version.<br>
Note that any unsaved changes on this column will be reverted upon column update.<br>
<button on:click={upgradeColumn}>Update Column</button>
<br>
{/if}
<table>
<tr>
<td>Field</td>
Expand Down Expand Up @@ -114,6 +147,9 @@ $: {
<div><MultipleField bind:data={data[fieldName]}/></div> -->
{:else if configuration[fieldName] === "int" || configuration[fieldName] === "float"}
<div><NumberField bind:data={data[fieldName]}/></div>

{:else if configuration[fieldName] === "enum"}
<div><EnumField allowEmpty={false} bind:data={data[fieldName]} options={configuration["enum@"+fieldName].options}/></div>

<!-- column and line select assume a sheet field in the editing object -->
{:else if configuration[fieldName].split("@")[0] === "lineSelect"}
Expand Down
2 changes: 1 addition & 1 deletion src/svelte/Depot/DepotSheet.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ function validateID(event,line) {
<div title="Selected value with GUID {line[column.name]} not in selected sheet. Select proper sheet in column settings">ERROR</div>
{/if}
{:else if column.typeStr === "multiple"}
<MultipleField sheetGUID={sheetData.guid} bind:data={line[column.name]} options={sheetData.columns.find(x => x.name === column.name).options.split(', ')} on:message/>
<MultipleField sheetGUID={sheetData.guid} bind:data={line[column.name]} options={sheetData.columns.find(x => x.name === column.name).options.split(', ')} displayType={"displayType" in column ? column.displayType : "vertical"} on:message/>
{:else if column.typeStr === "int" || column.typeStr === "float"}
<NumberField sheetGUID={sheetData.guid} bind:data={line[column.name]} on:message/>
{:else if column.typeStr === "list"}
Expand Down
7 changes: 6 additions & 1 deletion src/svelte/Depot/depotDefaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,16 @@ export let defaults = {
"options" : "",
"defaultValue" : "",
"iconName" : "newMulti",
"displayType" : "vertical",
"configurable" : {
"name" : "text",
"description" : "text",
"defaultValue" : "text",
"options" : "text"
"options" : "text",
"displayType" : "enum",
"enum@displayType" : {
"options" : ["vertical","horizontal"]
}
}
},
"sheetReference" : {
Expand Down
19 changes: 11 additions & 8 deletions src/svelte/Fields/MultipleField.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
export let data;
export let sheetGUID;
export let options;
export let displayType = "vertical";
const dispatch = createEventDispatcher();
function fieldUpdated() {
dispatch('message', {
Expand All @@ -13,12 +14,14 @@
}
});
}
</script>
<!-- svelte-ignore a11y-no-onchange -->
<select multiple bind:value={data} on:change={fieldUpdated}>
{#each options as option}
<option value={option}>
{option}
</option>
{/each}
</select>
{#each options as option}
<label>
<input type=checkbox bind:group={data} value={option} on:change={fieldUpdated}>
{option}
</label>
{#if displayType == "vertical"}
<br>
{/if}
{/each}

0 comments on commit b66bf97

Please sign in to comment.