scrollwheel to change planet size
This commit is contained in:
parent
16afe24e93
commit
2f75d5bce2
4 changed files with 66 additions and 8 deletions
|
@ -9,21 +9,21 @@
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
Distance Δ:
|
Distance Δ:
|
||||||
<input type="number" min="50" max="1000"
|
<input type="number" :min="MIN_DISTANCE_PLANET" :max="MAX_DISTANCE_PLANET"
|
||||||
:value="distance"
|
:value="distance"
|
||||||
@input="update('distance', $event.target.value)"
|
@input="update('distance', $event.target.value)"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
Radius r:
|
Radius r:
|
||||||
<input type="number" min="1" max="125"
|
<input type="number" :min="MIN_SIZE_PLANET" :max="MAX_SIZE_PLANET"
|
||||||
:value="radius"
|
:value="radius"
|
||||||
@input="update('radius', $event.target.value)"
|
@input="update('radius', $event.target.value)"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
Rings:
|
Rings:
|
||||||
<input type="number" min="0" max="15"
|
<input type="number" :min="MIN_AMOUNT_RINGS" :max="MAX_AMOUNT_RINGS"
|
||||||
:value="rings"
|
:value="rings"
|
||||||
@input="update('rings', $event.target.value)"
|
@input="update('rings', $event.target.value)"
|
||||||
/>
|
/>
|
||||||
|
@ -47,6 +47,16 @@
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { ref, computed } from 'vue'
|
import { ref, computed } from 'vue'
|
||||||
|
import {
|
||||||
|
MIN_SIZE_STAR,
|
||||||
|
MAX_SIZE_STAR,
|
||||||
|
MIN_SIZE_PLANET,
|
||||||
|
MAX_SIZE_PLANET,
|
||||||
|
MIN_DISTANCE_PLANET,
|
||||||
|
MAX_DISTANCE_PLANET,
|
||||||
|
MIN_AMOUNT_RINGS,
|
||||||
|
MAX_AMOUNT_RINGS,
|
||||||
|
} from '../constants'
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
distance: Number,
|
distance: Number,
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
:id="o.name"
|
:id="o.name"
|
||||||
:style="{ transform: `translateX(${o === draggedObject ? draggingDelta : 0}px)` }"
|
:style="{ transform: `translateX(${o === draggedObject ? draggingDelta : 0}px)` }"
|
||||||
@pointerdown.left="startDragging($event, o)"
|
@pointerdown.left="startDragging($event, o)"
|
||||||
@pointerleft="stopDragging"
|
@wheel="resizeObject"
|
||||||
>
|
>
|
||||||
<g class="rings" v-for="i in o.rings">
|
<g class="rings" v-for="i in o.rings">
|
||||||
<circle :r="o.radius - 5 + 2*i" :cx="o.distance" cy="150" />
|
<circle :r="o.radius - 5 + 2*i" :cx="o.distance" cy="150" />
|
||||||
|
@ -34,6 +34,12 @@
|
||||||
<script setup>
|
<script setup>
|
||||||
import { ref, computed } from 'vue'
|
import { ref, computed } from 'vue'
|
||||||
import steepCurve from '../steep-curve'
|
import steepCurve from '../steep-curve'
|
||||||
|
import {
|
||||||
|
MIN_SIZE_PLANET,
|
||||||
|
MAX_SIZE_PLANET,
|
||||||
|
MIN_DISTANCE_PLANET,
|
||||||
|
MAX_DISTANCE_PLANET,
|
||||||
|
} from '../constants'
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
star: Object,
|
star: Object,
|
||||||
|
@ -62,8 +68,12 @@ function stopDragging (event) {
|
||||||
event.target.removeEventListener('pointerup', stopDragging)
|
event.target.removeEventListener('pointerup', stopDragging)
|
||||||
console.debug('stop draggin', draggedObject.value.name)
|
console.debug('stop draggin', draggedObject.value.name)
|
||||||
|
|
||||||
const newDistance = draggedObject.value.distance + draggingDelta.value
|
let distance = draggedObject.value.distance + draggingDelta.value
|
||||||
emit('update', { distance: newDistance })
|
|
||||||
|
if (distance < MIN_DISTANCE_PLANET) distance = MIN_DISTANCE_PLANET
|
||||||
|
if (distance > MAX_DISTANCE_PLANET) distance = MAX_DISTANCE_PLANET
|
||||||
|
|
||||||
|
emit('update', { distance })
|
||||||
|
|
||||||
dragStart = 0
|
dragStart = 0
|
||||||
draggingDelta.value = 0
|
draggingDelta.value = 0
|
||||||
|
@ -91,4 +101,18 @@ function startDragging (event, object) {
|
||||||
window.addEventListener('pointerup', stopDragging)
|
window.addEventListener('pointerup', stopDragging)
|
||||||
event.target.addEventListener('pointerup', stopDragging)
|
event.target.addEventListener('pointerup', stopDragging)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function resizeObject (event) {
|
||||||
|
if (!props.selectedObject) return
|
||||||
|
|
||||||
|
event.preventDefault()
|
||||||
|
|
||||||
|
let radius = props.selectedObject.radius
|
||||||
|
radius = Math.round(radius + event.deltaY * -0.01)
|
||||||
|
|
||||||
|
if (radius < MIN_SIZE_PLANET) radius = MIN_SIZE_PLANET
|
||||||
|
if (radius > MAX_SIZE_PLANET) radius = MAX_SIZE_PLANET
|
||||||
|
|
||||||
|
emit('update', { radius })
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -4,11 +4,19 @@
|
||||||
<menu id="system-settings">
|
<menu id="system-settings">
|
||||||
<label>
|
<label>
|
||||||
Name
|
Name
|
||||||
<input type="text" :value="designation" @input="update('designation', $event.target.value)" />
|
<input type="text"
|
||||||
|
:value="designation"
|
||||||
|
@input="update('designation', $event.target.value)"
|
||||||
|
/>
|
||||||
</label>
|
</label>
|
||||||
<label>
|
<label>
|
||||||
Star Size
|
Star Size
|
||||||
<input type="range" min="50" max="1500" :value="radius" @input="update('radius', $event.target.value)" />
|
<input type="range"
|
||||||
|
:min="MIN_SIZE_STAR"
|
||||||
|
:max="MAX_SIZE_STAR"
|
||||||
|
:value="radius"
|
||||||
|
@input="update('radius', $event.target.value)"
|
||||||
|
/>
|
||||||
({{ radius }})
|
({{ radius }})
|
||||||
</label>
|
</label>
|
||||||
</menu>
|
</menu>
|
||||||
|
@ -17,6 +25,10 @@
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { ref } from 'vue'
|
import { ref } from 'vue'
|
||||||
|
import {
|
||||||
|
MIN_SIZE_STAR,
|
||||||
|
MAX_SIZE_STAR,
|
||||||
|
} from '../constants'
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
designation: String,
|
designation: String,
|
||||||
|
|
12
src/constants.js
Normal file
12
src/constants.js
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
export const MIN_SIZE_STAR = 50
|
||||||
|
export const MAX_SIZE_STAR = 1500
|
||||||
|
|
||||||
|
export const MIN_SIZE_PLANET = 1
|
||||||
|
export const MAX_SIZE_PLANET = 125
|
||||||
|
|
||||||
|
export const MIN_AMOUNT_RINGS = 0
|
||||||
|
export const MAX_AMOUNT_RINGS = 15
|
||||||
|
|
||||||
|
export const MIN_DISTANCE_PLANET = 32
|
||||||
|
export const MAX_DISTANCE_PLANET = 999
|
||||||
|
|
Loading…
Add table
Reference in a new issue