Skip to content
This repository has been archived by the owner on Aug 4, 2024. It is now read-only.

0.6.2 #30

Merged
merged 5 commits into from
Aug 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,24 @@
<script src="/src/Main.tsx" type="module" defer></script>
<%- reactDevTools -%> <%- reduxDevToolsPatch -%>
<style>
body {
margin: 0;
}
main {
width: 100vw;
height: 100vh;
}
div.center-items {
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
}
.nh-spinner {
animation: spin 1s linear infinite;
max-width: inherit;
max-height: inherit;
width: 250px;
height: 250px;
}

@keyframes spin {
from {
transform: rotateY(0deg) scale(0.3);
Expand All @@ -25,14 +37,16 @@
</style>
</head>
<body>
<div id="root">
<div style="height: 100vh; display: flex; align-items: center; justify-content: center">
<main id="root">
<div class="center-items">
<img
alt="Loading..."
class="nh-spinner"
width="84"
height="84"
src="src/Common/Images/spinner_image.png"
/>
</div>
</div>
</main>
</body>
</html>
2 changes: 1 addition & 1 deletion src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"relaunch": true
},
"shell": {
"open": ".*?"
"open": ".+"
},
"window": {
"all": true
Expand Down
2 changes: 1 addition & 1 deletion src/Common/Spinner/CenteredSpinner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Spinner from "./Spinner";

function CenteredSpinner() {
return (
<div className={"h-100 w-100 d-flex justify-content-center align-items-center"}>
<div className="center-items">
<Spinner />
</div>
);
Expand Down
21 changes: 14 additions & 7 deletions src/Common/Utils.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
export function camelToTitleCase(s: string) {
return !s || s.indexOf(" ") >= 0
? s
: (s.charAt(0).toUpperCase() + s.substring(1))
.split(/(?<=[a-z])(?=[A-Z])|(?<=[A-Z])(?=[A-Z][a-z])/g)
.map((x: string) => x.replace(/(\d+)/g, "$1 "))
.join(" ");
export function camelToTitleCase(str: string) {
const result = str
.replace(/(_)+/g, " ")
.replace(/([a-z])([A-Z][a-z])/g, "$1 $2")
.replace(/([A-Z][a-z])([A-Z])/g, "$1 $2")
.replace(/([a-z])([A-Z]+[a-z])/g, "$1 $2")
.replace(/([A-Z]+)([A-Z][a-z][a-z])/g, "$1 $2")
.replace(/([a-z]+)([A-Z0-9]+)/g, "$1 $2")
.replace(/([A-Z]+)([A-Z][a-rt-z][a-z]*)/g, "$1 $2")
.replace(/([0-9])([A-Z][a-z]+)/g, "$1 $2")
.replace(/([A-Z]{2,})([0-9]{2,})/g, "$1 $2")
.replace(/([0-9]{2,})([A-Z]{2,})/g, "$1 $2")
.trim();
return result.charAt(0).toUpperCase() + result.slice(1);
}

export function prettyErrorMessage(message: string) {
Expand Down
18 changes: 10 additions & 8 deletions src/MainWindow/MainWindow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ function MainWindow(props: { testStore?: EnhancedStore<RootState> }) {
});
}, []);

if (schemaStore === null) {
return <></>;
}

return (
<Provider store={store}>
<ProjectContext.Provider value={project}>
Expand All @@ -48,16 +52,14 @@ function MainWindow(props: { testStore?: EnhancedStore<RootState> }) {
</Row>
<Row className="flex-grow-1 border-top lt-border overflow-hidden">
<Col className="d-flex flex-column border-end lt-border">
{project.path !== "" && (
<ProjectView
projectPath={project!.path}
header={project!.name}
headerPath={`${project!.path}${sep}subtitle.png`}
/>
)}
<ProjectView
projectPath={project!.path}
header={project!.name}
headerPath={`${project!.path}${sep}subtitle.png`}
/>
</Col>
<Col className="p-0 h-100 d-flex flex-column" xs={8}>
{schemaStore && <EditorFrame schemaStore={schemaStore} />}
<EditorFrame schemaStore={schemaStore} />
</Col>
</Row>
</Container>
Expand Down
1 change: 0 additions & 1 deletion src/MainWindow/Panels/ProjectView/ProjectView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ function ProjectView(props: ProjectViewProps) {

useEffect(() => {
if (status === "idle") {
console.debug("Loading project", props.projectPath);
dispatch(loadProject(props.projectPath));
}
}, [status, dispatch]);
Expand Down
4 changes: 3 additions & 1 deletion src/MainWindow/Store/FileUtils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,9 @@ const inspectorRootDirectories = ["planets", "systems", "translations"];
export const usesInspector = (file: ProjectFile | OpenFile): boolean => {
const rootDir = getRootDirectory(file.relativePath);
return (
(rootDir !== null && inspectorRootDirectories.includes(rootDir.toLowerCase())) ||
(file.extension === "json" &&
rootDir !== null &&
inspectorRootDirectories.includes(rootDir.toLowerCase())) ||
file.name === "addon-manifest.json" ||
file.name === "manifest.json"
);
Expand Down
8 changes: 5 additions & 3 deletions src/MainWindow/Validation/GenericRules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ import { JSONPath } from "jsonpath-plus";
import { tauriCommands } from "../../Common/TauriCommands";
import { ValidationContext, ValidationError, ValidationRule } from "./Validator";

type JSONPathResult = { value: number; path: string }[];

export const fileMustExistRule = <T extends object>(
propPath: string,
folders: "allow" | "disallow" | "force" = "disallow"
): ValidationRule<T> => ({
perform: async (config: T, context: ValidationContext) => {
const hits = JSONPath<{ value: string; path: string }[]>({
const hits = JSONPath<JSONPathResult>({
path: propPath,
json: config,
resultType: "all"
Expand Down Expand Up @@ -48,12 +50,12 @@ export const fileMustExistRule = <T extends object>(
export const minMaxRule = <T extends object>(minPath: string, maxPath: string) => {
return {
perform: async (config: T) => {
const minHits = JSONPath<{ value: number; path: string }[]>({
const minHits = JSONPath<JSONPathResult>({
path: minPath,
json: config,
resultType: "all"
});
const maxHits = JSONPath<{ value: number; path: string }[]>({
const maxHits = JSONPath<JSONPathResult>({
path: maxPath,
json: config,
resultType: "all"
Expand Down
2 changes: 1 addition & 1 deletion src/MainWindow/Validation/PlanetValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const minMaxRules = minMaxPaths.map(([minPath, maxPath]) => minMaxRule<Planet>(m

const quantumGroupRule = {
perform: async (config: Planet) => {
if (config.Props.details === undefined) {
if (config.Props?.details === undefined) {
return { valid: true, errors: [] };
}
const ids = (config.Props.quantumGroups ?? []).map((group) => group.id);
Expand Down
14 changes: 14 additions & 0 deletions src/MainWindow/Validation/SystemValidator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { fileMustExistRule } from "./GenericRules";

const filePaths = [
"$.Skybox.rightPath",
"$.Skybox.leftPath",
"$.Skybox.topPath",
"$.Skybox.bottomPath",
"$.Skybox.frontPath",
"$.Skybox.backPath"
];

const fileRules = filePaths.map((filePath) => fileMustExistRule<Record<string, never>>(filePath));

export default fileRules;
4 changes: 4 additions & 0 deletions src/MainWindow/Validation/Validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { getFileName, getRootDirectory } from "../Store/FileUtils";
import { OpenFile } from "../Store/OpenFilesSlice";
import manifestRules from "./ManifestValidator";
import planetRules from "./PlanetValidator";
import systemRules from "./SystemValidator";

export type ValidationResult = {
valid: boolean;
Expand Down Expand Up @@ -31,6 +32,9 @@ const determineValidationRules = (configPath: string): ValidationRule<any>[] =>
if (rootDir === "planets") {
return planetRules;
}
if (rootDir === "systems") {
return systemRules;
}
return [];
};

Expand Down
10 changes: 9 additions & 1 deletion src/Wrapper.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { dialog } from "@tauri-apps/api";
import { Event, listen } from "@tauri-apps/api/event";
import React, { useEffect } from "react";
import { useHotkeys } from "react-hotkeys-hook";
Expand Down Expand Up @@ -32,7 +33,14 @@ function Wrapper() {
});

useEffect(() => {
SettingsManager.get().then(setSettings);
SettingsManager.get()
.then(setSettings)
.catch((e) => {
dialog.message(`Error loading settings: ${e}`, {
type: "error",
title: "Error"
});
});
}, []);

if (settings === null) {
Expand Down
3 changes: 3 additions & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ export default defineConfig({
})
],
envPrefix: "NODE_",
// Im going gorbo mode
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
test: {
setupFiles: ["./test/Setup.ts"],
environment: "jsdom",
Expand Down