Skip to content

Commit

Permalink
Add data_character_npc support + some ui improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Darxoon committed Jun 27, 2024
1 parent e8739a4 commit 5396bb1
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 23 deletions.
1 change: 1 addition & 0 deletions src/elf/dataType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export enum DataType {
Bshape,

// registries
CharacterNpc,
MapId,
ItemList,

Expand Down
95 changes: 91 additions & 4 deletions src/elf/fileTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ interface DataTypeMetadata {
displayName?: string
identifyingField?: string
dataDivision?: DataDivision | null
textVars?: {[key: string]: string}

defaultPadding?: number

childTypes?: Typedef<DataType>,

Expand Down Expand Up @@ -391,6 +394,69 @@ Used for the loading of new maps (?)`),
holdWeight: "int",
dropWeight: "int",
},
[DataType.CharacterNpc]: {
__: {
displayName: "Npc Definition",
defaultPadding: 1,
textVars: {
model: 'data_model_npc'
},
},

id: "string",
model: new Property("string", "Referencing models in 'data/model/{model}.elf.zst'"),
field_0x10: "int",
field_0x14: "int",
field_0x18: "int",
field_0x1c: "int",
// TODO: add examples of functions in the instance script file
scriptFileName: "string",
scriptNamespace: new Property("string", `
The AngelScript namespace for the common instance functions inside the Script File (see Script File Name).`),
field_0x30: "int",
field_0x34: "int",
field_0x38: "int",
field_0x3c: "int",
field_0x40: "int",
field_0x44: "int",
field_0x48: "int",
field_0x4c: "int",
field_0x50: "int",
field_0x54: "int",
field_0x58: "int",
field_0x5c: "int",
field_0x60: "string",
field_0x68: "int",
field_0x6c: "int",
landingSfx: "string",
jumpedOnSfx: "string",
hammerSfx: "string",
jumpSfx: "string",
field_0x90: "string",
field_0x98: "string",
talkSfx: "string",
field_0xa8: "int",
field_0xac: "int",
field_0xb0: "int",
field_0xb4: "int",
field_0xb8: "int",
field_0xbc: "int",
field_0xc0: "int",
field_0xc4: "int",
field_0xc8: "int",
field_0xcc: "int",
field_0xd0: "string",
field_0xd8: "string",
field_0xe0: "string",
field_0xe8: "int",
field_0xec: "int",
field_0xf0: "int",
field_0xf4: "int",
field_0xf8: "int",
field_0xfc: "int",
field_0x100: "int",
field_0x104: "int",
},
} as const satisfies {[dataType: number]: TypeDefinition}


Expand All @@ -409,6 +475,8 @@ interface FileTypeRegistry {
displayName: string
identifyingField: string
dataDivision: DataDivision
defaultPadding: number
textVars: {[key: string]: string}

// for future sub-types
childTypes?: Typedef<DataType>
Expand Down Expand Up @@ -438,7 +506,7 @@ function generateTypedefFor(dataType: DataType, typedef: TypeDefinition): FileTy
metadata = {...parent.__, ...metadata}
}

const { displayName, dataDivision, identifyingField, childTypes } = metadata
const { displayName, dataDivision, identifyingField, childTypes, defaultPadding, textVars } = metadata

let fields = new Map(Object.entries(typedef).flatMap(([fieldName, fieldType]) => {
if (fieldType instanceof Property) {
Expand All @@ -457,9 +525,25 @@ function generateTypedefFor(dataType: DataType, typedef: TypeDefinition): FileTy
let fieldMetadata: Typedef<Property> = {}

for (const [fieldName, property] of fields) {
let description = (property.description ?? defaultDescriptions[fieldName])
?.replaceAll("{type}", displayName)
?.replaceAll("{type_lowercase}", displayName?.toLowerCase())
let description = property.description ?? defaultDescriptions[fieldName]

if (description) {
if (textVars) {
let vars = {
'type': displayName,
'type_lowercase': displayName?.toLowerCase(),
...textVars,
}

for (const [key, value] of Object.entries(vars)) {
description = description.replaceAll('{' + key + '}', value)
}
} else {
description = description
.replaceAll("{type}", displayName)
.replaceAll("{type_lowercase}", displayName?.toLowerCase())
}
}

const { type, tabName, noSpaces, hidden } = property
fieldMetadata[fieldName] = new Property(type, description, { hidden, noSpaces, tabName })
Expand All @@ -477,6 +561,9 @@ function generateTypedefFor(dataType: DataType, typedef: TypeDefinition): FileTy
displayName,
identifyingField: identifyingField ?? "id",
dataDivision: dataDivision === null ? null : dataDivision ?? dataDivisions.main,
textVars: textVars ?? {},

defaultPadding: defaultPadding ?? 0,

childTypes: childTypes ?? {},

Expand Down
4 changes: 3 additions & 1 deletion src/elf/serializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,9 @@ export default function serializeElfBinary(dataType: DataType, binary: ElfBinary
stringRelocations: dataStringRelocations,
}

serializeObjects(data, dataType, binary.data.main)
let padding = FILE_TYPES[dataType].defaultPadding

serializeObjects(data, dataType, binary.data.main, { padding })

break
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@
<!-- TODO: do the same on delete button in object editors -->
<FileToolbar on:add={addObject} on:clear={deleteAll} searchIndex={index} bind:searchTerm={searchTerm} bind:searchResults={searchResults} />

<div class="listing" style="--content-height: {objects?.length * 61}px;">
<div class="listing" style="--content-height: {objects?.length * 60 + 80}px;">
{#if searchResults}
<div class="resultlabel">Showing {searchResultObjects.length} results
(out of {objects.length} objects):</div>
Expand Down
1 change: 1 addition & 0 deletions src/lib/editor/fileEditor/welcomeScreen/FileTree.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"data_Bshape",
"MapId",
"data_ItemList",
"data_character_npc",
]
const dispatch = createEventDispatcher()
Expand Down
2 changes: 2 additions & 0 deletions src/lib/modals/DataTypePrompt.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"data_Bshape": DataType.Bshape,
"MapId": DataType.MapId,
"data_ItemList": DataType.ItemList,
"data_character_npc": DataType.CharacterNpc,
}
onMount(() => {
Expand Down Expand Up @@ -69,6 +70,7 @@
<option value="Aobj">Aobj Placement (data_Aobj)</option>
<option value="Bshape">Bshape Placement (data_Bshape)</option>

<option value="CharacterNpc">NPC Registry (data_character_npc)</option>
<option value="MapId">Map Registry (MapId)</option>
<option value="ItemList">Battle Item RNG Table (ItemList)</option>
</select>
Expand Down
35 changes: 18 additions & 17 deletions src/lib/modals/FieldOptionAlert.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@
export let fieldName: string
export let title: string
let hideNulls = false
$: fieldType = FILE_TYPES[dataType].typedef[fieldName]
$: allGlobalValues = FILE_TYPES[dataType].dataDivision == null && scanAllGlobalValues()
$: hideNulls = fieldType === "string"
$: forceMaxHeight = hideNulls && objects.length * 35 + 18 * 16 >= window.visualViewport.height
$: globalFieldId = DataType[dataType] + "/" + fieldName
let notes: string
$: fieldType = FILE_TYPES[dataType].typedef[fieldName]
$: allGlobalValues = FILE_TYPES[dataType].dataDivision == null && scanAllGlobalValues()
$: if (notes) localStorage[globalFieldId + ".description"] = notes
Expand Down Expand Up @@ -97,23 +99,17 @@
<div>
{#if fieldType === "string"}
<div class="hideNullContainer">
<input type="checkbox" id="hideNull" on:change={e => {
// @ts-ignore
hideNulls = e.target.checked
}}>
<input type="checkbox" id="hideNull" bind:checked={hideNulls}>
<label for="hideNull">Hide all "null" values</label>
</div>
{/if}
{#if isNumber(fieldType)}
<div class="hideNullContainer">
<input type="checkbox" id="hideNull" on:change={e => {
// @ts-ignore
hideNulls = e.target.checked
}}>
<input type="checkbox" id="hideNull" bind:checked={hideNulls}>
<label for="hideNull">Hide all zeroes</label>
</div>
{/if}
<div class="allValues local tabbable">
<div class="allValues local tabbable" class:forceMaxHeight={forceMaxHeight}>
{#each objects as obj, i}
{#if hideNulls ? obj[fieldName] !== null && obj[fieldName] != 0 || obj[fieldName] === "" : true}
<div class="index">
Expand All @@ -133,10 +129,7 @@
<div><!-- TODO: Make this a Svelte 5 snippet in the future to reduce repetition -->
{#if fieldType === "string"}
<div class="hideNullContainer">
<input type="checkbox" name="hideNull" on:change={e => {
// @ts-ignore
hideNulls = e.target.checked
}}>
<input type="checkbox" name="hideNull" bind:checked={hideNulls}>
<label for="hideNull">Hide all "null" values</label>
</div>
{/if}
Expand All @@ -159,7 +152,7 @@
{/if}
</TabbedAlert>

<style lang="scss">
<style>
.hideNullContainer {
margin: 0 0 12px -4px;
}
Expand All @@ -172,6 +165,14 @@
overflow-y: auto;
}
.allValues.forceMaxHeight {
min-height: calc(100vh - 18rem);
/* if it has more than 1000 items, welp */
/* necessary so that the entries don't spread across the entire box height */
grid-template-rows: repeat(1000, min-content);
}
.allValues.local :nth-child(6n-1) {
background: #eaeaea;
border-radius: 3px;
Expand Down

0 comments on commit 5396bb1

Please sign in to comment.