Skip to content
Open
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
14 changes: 12 additions & 2 deletions backend/mod.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
from pathlib import Path
import shutil
import tkinter
from tkinter import filedialog
import zipfile
from dacite import from_dict
Expand Down Expand Up @@ -114,8 +115,12 @@ def rename_mod(name, new_name, new_description):

@eel.expose
def import_mod():
path = filedialog.askopenfilename(defaultextension='.gearthon', filetypes=[('Gearthon Mods', '*.gearthon')])

root = tkinter.Tk()
root.focus_force()
root.overrideredirect(True)
root.geometry('0x0+0+0')
path = filedialog.askopenfilename(defaultextension='.gearthon', filetypes=[('Gearthon Mods', '*.gearthon')], title='Import Mod')
root.destroy()
with zipfile.ZipFile(path) as zip:
first_dir = zip.filelist[0].filename
from backend.appdata import appdata
Expand All @@ -128,7 +133,12 @@ def import_mod():

@eel.expose
def export_mod(name):
root = tkinter.Tk()
root.focus_force()
root.overrideredirect(True)
root.geometry('0x0+0+0')
path = filedialog.askdirectory()
root.destroy()
from backend.appdata import appdata
mod_path = Path(f'{appdata.mods_folder()}/{name}')
shutil.make_archive(f'{path}/{name}.gearthon', 'zip', root_dir=mod_path.parent, base_dir=f'./{name}')
Expand Down
4 changes: 3 additions & 1 deletion classes/Part.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from classes.JoystickTweakable import JoystickTweakable
from classes.Link import Link
from classes.StringTweakable import StringTweakable

from classes.Vector3 import Vector3

@dataclass
class Part:
Expand Down Expand Up @@ -39,6 +39,8 @@ class Part:
is_paintable: bool = field(default=False, metadata={'label': 'Paintable'})
is_swappable_material: bool = field(default=False, metadata={'label': 'Swappable Material'})
mesh_collider: bool = field(default=False, metadata={'label': '(EXPERIMENTAL) Use Mesh Collider'})
custom_collider: bool = field(default=False, metadata={'label': '(EXPERIMENTAL) Custom Collider'})
custom_collider_position: Vector3 = field(default_factory=lambda: Vector3(0, 0, 0), metadata={'label': 'Custom Collider Position'})
script: str = field(default='', metadata={'label': 'Script', 'hidden': True})
int_tweakables: List[IntTweakable] = field(default_factory=list, metadata={'hidden': True})
string_tweakables: List[StringTweakable] = field(default_factory=list, metadata={'hidden': True})
Expand Down
80 changes: 77 additions & 3 deletions web/editor.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div x-data="{mod: null, show_controls: false}" x-init="async () => { mod = await eel.get_mod()(); }">
<div x-show="!mod" class="h-100" x-load="loading.html"></div>
<div x-data="{mod: null, show_axis: true, show_controls: false, show_grid: true, show_wireframe: false}" x-init="async () => { mod = await eel.get_mod()();}">
<div x-show="!mo" class="h-100" x-load="loading.html"></div>
<div x-show="mod">
<div class="d-flex h-100" x-data="editor">
<div class="w-25 p-2 border-end">
Expand Down Expand Up @@ -152,7 +152,32 @@ <h3 class="text-center">Settings</h3>
</ul>
<ul class="navbar-nav ms-auto">
<li class="nav-item d-flex" x-data="{ open_file_browser: function() { $refs.filebrowser.click(); }}">
<button class="btn me-2" :class="{'btn-outline-primary': show_controls, 'btn-outline-danger': !show_controls}" x-on:click="show_controls = !show_controls" x-text="show_controls ? 'Hide Controls' : 'Show Controls'">Show Controls</button>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" data-bs-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Options</a>
<div class="dropdown-menu ps-2 " style="top:115%; left: -70px;">
<h6 class="dropdown-header">Options</h6>
<div class="form-check">
<!-- TODO: Add persistance logic here -->
<input class="form-check-input" type="checkbox" x-on:change="show_wireframe = !show_wireframe; showWireframe(show_wireframe);" id="showWireframeCheckBox">
<label class="form-check-label" for="showWireframeCheckBox">Show Wireframe</label>
</div>
<div class="form-check">
<!-- TODO: Add persistance logic here -->
<input class="form-check-input" type="checkbox" x-on:change="show_controls = !show_controls" id="showControlsCheckBox">
<label class="form-check-label" for="showControlsCheckBox">Show Controls</label>
</div>
<div class="form-check">
<!-- TODO: Add persistance logic here -->
<input class="form-check-input" type="checkbox" checked="checked" x-on:change="show_grid = !show_grid; showGrid(show_grid);" id="showGridCheckBox">
<label class="form-check-label" for="showGridCheckBox">Show Grid</label>
</div>
<div class="form-check">
<!-- TODO: Add persistance logic here -->
<input class="form-check-input" type="checkbox" checked="checked" x-on:change="show_axis = !show_axis; showAxis(show_axis);" id="showAxisCheckBox">
<label class="form-check-label" for="showAxisCheckBox">Show Axis</label>
</div>
</div>
</li>
</ul>
</div>
Expand Down Expand Up @@ -694,13 +719,16 @@ <h3 class="text-center">Tweakables</h3>
this.DeselectAttachment();
this.DeselectLink();
if (this.mode == "View") {
showGrid(true);
}

if (this.mode == "Tweakables") {
showGrid(true);
}

if (this.mode == "Attachments") {
setTransparency(0.2);
showGrid(false);
} else {
setTransparency(1);
}
Expand Down Expand Up @@ -967,6 +995,9 @@ <h3 class="text-center">Tweakables</h3>
container = document.getElementById('3js');
WIDTH = container.offsetWidth;
HEIGHT = container.offsetHeight;
line = null;
gridHelper = null;
axisHelper = null;

scene = new THREE.Scene();
camera = new THREE.PerspectiveCamera(60, WIDTH/HEIGHT, 0.01, 100);
Expand All @@ -978,6 +1009,9 @@ <h3 class="text-center">Tweakables</h3>
renderer.setSize(WIDTH, HEIGHT);
container.appendChild(renderer.domElement);

showGrid( true );
showAxis( true );

// Add some lights
var light = new THREE.HemisphereLight(0xffffff, 0x444444, 1.0);
light.position.set(0, 1, 0);
Expand Down Expand Up @@ -1027,6 +1061,46 @@ <h3 class="text-center">Tweakables</h3>
scene.add(loaded_obj);
}

function showWireframe( boolean ) {
if ( loaded_obj ) {
if (!line && boolean ) {
wireframe = new THREE.WireframeGeometry(loaded_obj.geometry);
line = new THREE.LineSegments(wireframe);
line.material.depthTest = true;
line.material.color = new THREE.Color(0xffa500);
line.material.opacity = 0.9;
line.material.transparent = true;
scene.add(line);
} else if (line && !boolean ) {
console.log('Deleting Wireframe');
scene.remove(line);
line = null;
}
}
}

function showGrid( boolean ) {
if ( !gridHelper && boolean ) {
gridHelper = new THREE.GridHelper( 4.5, 45 );
scene.add(gridHelper);
} else if ( gridHelper && !boolean ) {
scene.remove(gridHelper);
gridHelper = null;
} else {
console.log('no gridHelper');
}
}

function showAxis( boolean ) {
if ( !axisHelper && boolean ) {
axisHelper = new THREE.AxesHelper( 2.25 );
scene.add(axisHelper);
} else if ( axisHelper && !boolean ) {
scene.remove(axisHelper);
axisHelper = null;
}
}

function setTransparency(transparency) {
// Iterate through the children of the loaded object
loaded_obj.traverse(function(child) {
Expand Down