Move Orientation into sensors directory, attempt to fix 'NaN' in slope input

This commit is contained in:
Pieter Vander Vennet 2023-12-18 01:58:58 +01:00
parent 82409984dc
commit e9268bfc49
6 changed files with 30 additions and 6 deletions

View file

@ -1,4 +1,4 @@
import { Stores, UIEventSource } from "../UIEventSource"
import { UIEventSource, Stores } from "../Logic/UIEventSource"
/**
* Exports the device orientation as UIEventSources and detects 'shakes'

View file

@ -1,5 +1,4 @@
<script lang="ts">
import Crosshair from "../../assets/svg/Crosshair.svelte"
import Location_refused from "../../assets/svg/Location_refused.svelte"
import { Store } from "../../Logic/UIEventSource.js"
import type { GeolocationPermissionState } from "../../Logic/State/GeoLocationState.js"

View file

@ -1,5 +1,5 @@
<script lang="ts">
import { Orientation } from "../../Logic/Web/Orientation"
import { Orientation } from "../../Sensors/Orientation"
const o = Orientation.singleton
let alpha = o.alpha

View file

@ -2,7 +2,7 @@
import { ImmutableStore, UIEventSource } from "../../../Logic/UIEventSource"
import Translations from "../../i18n/Translations"
import Tr from "../../Base/Tr.svelte"
import { Orientation } from "../../../Logic/Web/Orientation"
import { Orientation } from "../../../Sensors/Orientation"
import type { Feature } from "geojson"
import { GeoOperations } from "../../../Logic/GeoOperations"
import If from "../../Base/If.svelte"

View file

@ -1,4 +1,3 @@
import NatValidator from "./NatValidator"
import FloatValidator from "./FloatValidator"
export default class SlopeValidator extends FloatValidator {
@ -9,10 +8,36 @@ export default class SlopeValidator extends FloatValidator {
"The accompanying input element uses the gyroscope and the compass to determine the correct incline. The sign of the incline will be set automatically. The bearing of the way is compared to the bearing of the compass, as such, the device knows if it is measuring in the forward or backward direction."
)
}
isValid(str: string): boolean {
if (str.endsWith("%") || str.endsWith("°")) {
str = str.substring(0, str.length - 1)
}
return super.isValid(str)
}
/**
*
* const v = new SlopeValidator()
* v.reformat("5%") // => "5%"
* v.reformat("5 %") // => "5%"
* v.reformat(" 5 %") // => "5%"
* v.reformat(" 5.0 %") // => "5%"
* v.reformat(" 5.0 % ") // => "5%"
* v.reformat(" -5.0 % ") // => "-5%"
* v.reformat("5") // => "5"
* v.reformat("5°") // => "5°"
*
*
*
*/
reformat(str: string): string {
str = str.trim()
let lastChar = ""
if (str.endsWith("%") || str.endsWith("°")) {
lastChar = str.substring(str.length - 1)
str = str.substring(0, str.length - 1)
}
return super.reformat(str) + lastChar
}
}

View file

@ -63,7 +63,7 @@
import Favourites from "./Favourites/Favourites.svelte"
import ImageOperations from "./Image/ImageOperations.svelte"
import VisualFeedbackPanel from "./BigComponents/VisualFeedbackPanel.svelte"
import { Orientation } from "../Logic/Web/Orientation"
import { Orientation } from "../Sensors/Orientation"
import GeolocationControl from "./BigComponents/GeolocationControl.svelte"
import Compass_arrow from "../assets/svg/Compass_arrow.svelte"