add new planets

This commit is contained in:
koehr 2022-01-06 15:23:35 +01:00
parent 7b3fdb07bf
commit 8d6c98e58d
4 changed files with 26 additions and 4 deletions

View file

@ -15,9 +15,9 @@ The application is working but certain features are missing or unpolished:
✅ Interactive value change (drag'n'drop / scroll) ✅ Interactive value change (drag'n'drop / scroll)
✅ Objects can be removed ✅ Objects can be removed
✅ Last removed object (planet) can be restored ✅ Last removed object (planet) can be restored
❌ add new objects ✅ add new planets and satellites
❌ astroid belts
❌ randomly generate star system ❌ randomly generate star system
❌ astroid belts
❌ Export graphic via print or PDF ❌ Export graphic via print or PDF
❌ Export data ❌ Export data

View file

@ -1,7 +1,7 @@
{ {
"name": "starsy", "name": "starsy",
"description": "Random Star System Generator", "description": "Random Star System Generator",
"version": "0.4.5", "version": "0.4.6",
"scripts": { "scripts": {
"dev": "vite", "dev": "vite",
"build": "vite build", "build": "vite build",

View file

@ -29,7 +29,7 @@
<li><strong>ONLY THE LAST</strong> removed planet can be restored.</li> <li><strong>ONLY THE LAST</strong> removed planet can be restored.</li>
</Tips> </Tips>
<SystemSettings v-model:designation="star.designation" v-model:radius="star.radius" /> <SystemSettings v-model:designation="star.designation" v-model:radius="star.radius" />
<ObjectList v-bind="{ objects, deletedObject, editObject, deleteObject, restoreDeleted }" /> <ObjectList v-bind="{ objects, deletedObject, addObject, editObject, deleteObject, restoreDeleted }" />
</section> </section>
</template> </template>
@ -43,6 +43,7 @@ import Tips from './components/Tips.vue'
import SystemSettings from './components/SystemSettings.vue' import SystemSettings from './components/SystemSettings.vue'
import ObjectList from './components/ObjectList.vue' import ObjectList from './components/ObjectList.vue'
import ObjectSettings from './components/ObjectSettings.vue' import ObjectSettings from './components/ObjectSettings.vue'
import { MAX_DISTANCE_PLANET } from './constants'
const star = reactive({ const star = reactive({
designation: 'Sol', designation: 'Sol',
@ -56,6 +57,25 @@ const themes = ['default', 'retro', 'inverse', 'paper']
const selectedObject = ref(null) const selectedObject = ref(null)
const deletedObject = ref(null) // { index: Number, object: Object } const deletedObject = ref(null) // { index: Number, object: Object }
function addObject() {
const amount = objects.length
let distance = 100
if (amount) {
const lastObject = objects[amount - 1]
distance = Math.min(MAX_DISTANCE_PLANET, lastObject.distance + 2*lastObject.radius + 10)
}
objects.push({
type: 'planet',
name: `${star.designation}-${amount + 1}`,
radius: 1,
distance,
satellites: [],
rings: 0,
})
}
function editObject (object) { function editObject (object) {
if (object) { if (object) {
document.documentElement.scrollTop = 0 document.documentElement.scrollTop = 0

View file

@ -20,6 +20,7 @@
RESTORE DELETED OBJECT RESTORE DELETED OBJECT
</button> </button>
</tr> </tr>
<button class="add" @click="addObject">&nbsp;</button>
</table> </table>
</template> </template>
@ -29,6 +30,7 @@ import { computed } from 'vue'
const props = defineProps({ const props = defineProps({
objects: Array, objects: Array,
deletedObject: [Object, null], deletedObject: [Object, null],
addObject: Function,
editObject: Function, editObject: Function,
deleteObject: Function, deleteObject: Function,
restoreDeleted: Function, restoreDeleted: Function,