generated from maximegris/angular-electron
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
540 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,103 @@ | ||
export function ensureMap(name: string, mapName: string) {} | ||
import * as childProcess from 'child_process'; | ||
import * as fs from 'fs-extra'; | ||
import { baseUrl } from '../helpers'; | ||
|
||
export function newMap(name: string, creator: string) {} | ||
export const fixTiledMapPaths = (map: any) => { | ||
map.tilesets.forEach((tileset: any) => { | ||
tileset.image = `../../__assets/spritesheets/${tileset.name.toLowerCase()}.png`; | ||
}); | ||
}; | ||
|
||
export function renameMap(oldName: string, newName: string) {} | ||
export function ensureMap(mapName: string, mapData: any) { | ||
const path = `${baseUrl}/resources/maps/src/content/maps/custom/${mapName}.json`; | ||
fs.writeFileSync(path, JSON.stringify(mapData)); | ||
} | ||
|
||
export function editMap(name: string) {} | ||
export function newMap(mapName: string, mapAuthor: string) { | ||
const fileName = mapName.replace(/[^a-zA-Z-]/g, ''); | ||
const templatePath = `${baseUrl}/resources/maps/src/content/maps/custom/Template.json`; | ||
const path = `${baseUrl}/resources/maps/src/content/maps/custom/${fileName}.json`; | ||
|
||
export function editMapSpawnerNames(oldName: string, newName: string) {} | ||
if (!fs.existsSync(templatePath)) { | ||
throw new Error('Template is gone.'); | ||
} | ||
|
||
if (fs.existsSync(path)) { | ||
throw new Error('Map already exists'); | ||
} | ||
|
||
const json = fs.readJSONSync(templatePath); | ||
json.properties.creator = mapAuthor; | ||
json.propertytypes.creator = 'string'; | ||
|
||
fs.writeJSONSync(path, json); | ||
|
||
editMap(fileName); | ||
|
||
return json; | ||
} | ||
|
||
export function copyMap(mapName: string) { | ||
const oldPath = `${baseUrl}/resources/maps/src/content/maps/custom/${mapName}.json`; | ||
const newPath = `${baseUrl}/resources/maps/src/content/maps/custom/${mapName} (copy).json`; | ||
|
||
if (fs.existsSync(newPath)) { | ||
throw new Error('A map by that name already exists.'); | ||
} | ||
|
||
fs.copySync(oldPath, newPath); | ||
} | ||
|
||
export function renameMap(oldName: string, newName: string) { | ||
const oldPath = `${baseUrl}/resources/maps/src/content/maps/custom/${oldName}.json`; | ||
const newPath = `${baseUrl}/resources/maps/src/content/maps/custom/${newName}.json`; | ||
|
||
if (fs.existsSync(newPath)) { | ||
throw new Error('A map by that name already exists.'); | ||
} | ||
|
||
fs.moveSync(oldPath, newPath); | ||
} | ||
|
||
export function removeMap(mapName: string) { | ||
const oldPath = `${baseUrl}/resources/maps/src/content/maps/custom/${mapName}.json`; | ||
const newPath = `${baseUrl}/resources/maps/src/content/maps/custom/${mapName}.bak.json`; | ||
|
||
fs.moveSync(oldPath, newPath, { overwrite: true }); | ||
} | ||
|
||
export function editMap(mapName: string) { | ||
if (!fs.existsSync(`${baseUrl}/resources/Tiled`)) { | ||
throw new Error('Tiled is not installed.'); | ||
} | ||
|
||
const path = `${baseUrl}/resources/maps/src/content/maps/custom/${mapName}.json`; | ||
|
||
const map = fs.readJsonSync(path); | ||
fixTiledMapPaths(map); | ||
fs.writeJsonSync(path, map); | ||
|
||
childProcess.exec(`${baseUrl}/resources/Tiled/tiled.exe "${path}"`); | ||
} | ||
|
||
export function editMapSpawnerNames(oldName: string, newName: string) { | ||
fs.readdirSync(`${baseUrl}/resources/maps/src/content/maps/custom`).forEach( | ||
(file) => { | ||
const path = `${baseUrl}/resources/maps/src/content/maps/custom/${file}`; | ||
const json = fs.readJSONSync(path); | ||
|
||
let didWrite = false; | ||
|
||
json.layers[10].objects.forEach((spawner: any) => { | ||
if (spawner.tag !== oldName) return; | ||
|
||
spawner.tag = newName; | ||
didWrite = true; | ||
}); | ||
|
||
if (didWrite) { | ||
fs.writeJSONSync(path, json); | ||
} | ||
} | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
src/app/shared/components/editor-base-table/editor-base-table.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<p>editor-base-table works!</p> |
Empty file.
38 changes: 38 additions & 0 deletions
38
src/app/shared/components/editor-base-table/editor-base-table.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { Component, inject, signal } from '@angular/core'; | ||
import { ModService } from '../../../services/mod.service'; | ||
|
||
@Component({ | ||
selector: 'app-editor-base-table', | ||
templateUrl: './editor-base-table.component.html', | ||
styleUrl: './editor-base-table.component.scss', | ||
}) | ||
export class EditorBaseTableComponent<T> { | ||
protected modService = inject(ModService); | ||
|
||
protected defaultData = () => ({} as T); | ||
|
||
public isEditing = signal<boolean>(false); | ||
public oldData = signal<T | undefined>(undefined); | ||
public editingData = signal<T>(this.defaultData()); | ||
|
||
public createNew() { | ||
this.isEditing.set(true); | ||
this.editingData.set(this.defaultData()); | ||
} | ||
|
||
public editExisting(data: T) { | ||
this.isEditing.set(true); | ||
this.oldData.set(structuredClone(data)); | ||
this.editingData.set(data); | ||
} | ||
|
||
public cancelEditing() { | ||
this.isEditing.set(false); | ||
} | ||
|
||
public saveNewData(data: T) { | ||
Check failure on line 33 in src/app/shared/components/editor-base-table/editor-base-table.component.ts GitHub Actions / build (20)
Check failure on line 33 in src/app/shared/components/editor-base-table/editor-base-table.component.ts GitHub Actions / build (20)
|
||
this.isEditing.set(false); | ||
} | ||
|
||
public deleteData(data: T) {} | ||
Check failure on line 37 in src/app/shared/components/editor-base-table/editor-base-table.component.ts GitHub Actions / build (20)
Check failure on line 37 in src/app/shared/components/editor-base-table/editor-base-table.component.ts GitHub Actions / build (20)
|
||
} |
Oops, something went wrong.