commit 4d7f2970c1530494e075abcd3906a8b12e376efc Author: ExeVirus Date: Fri Jul 16 12:32:43 2021 -0400 Version 1.0 diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..245bf8b --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2021 Dallas DeBruin + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..748008a --- /dev/null +++ b/README.md @@ -0,0 +1,20 @@ +# Formspec Editor +## REALTIME formspec viewer/editor "game" for minetest + +![formspec editor preview](preview.png) + +## Getting Started + +The file *formspec.spec* in your: + +```minetest_folder/games/formspec_editor/mods/formspec_edit``` + +contains a formspec you can edit and see updates of in real time. +Simply add the game to MT, load up a level of *Formspec Editor*, and +you will be greeted with the *formspec.spec* formspec. + +- To make edits, open the file (formspec.spec) in your editor of choice and make changes as you see fit. When you hit save, the formspec will auto-update. Best when used side by side. +- To exit just hit or use a button_exit[] button. Both send the +fields.quit message. +- You can test with images if you want, adding a "textures" folder to the +formspec_edit gamemod folder, otherwise images will default to random colors. diff --git a/game.conf b/game.conf new file mode 100644 index 0000000..cb7f0e3 --- /dev/null +++ b/game.conf @@ -0,0 +1,4 @@ +name = Formspec_Editor +author = Just_Visiting +description = An in-game formspec editor, just edit formspec.spec +allowed_mapgens = singlenode \ No newline at end of file diff --git a/menu/background.png b/menu/background.png new file mode 100644 index 0000000..a7ffe37 Binary files /dev/null and b/menu/background.png differ diff --git a/menu/header.png b/menu/header.png new file mode 100644 index 0000000..15b741e Binary files /dev/null and b/menu/header.png differ diff --git a/menu/icon.png b/menu/icon.png new file mode 100644 index 0000000..14b73d0 Binary files /dev/null and b/menu/icon.png differ diff --git a/minetest.conf b/minetest.conf new file mode 100644 index 0000000..702b954 --- /dev/null +++ b/minetest.conf @@ -0,0 +1 @@ +movement_gravity = 0 \ No newline at end of file diff --git a/mods/formspec_edit/formspec.spec b/mods/formspec_edit/formspec.spec new file mode 100644 index 0000000..c4fda34 --- /dev/null +++ b/mods/formspec_edit/formspec.spec @@ -0,0 +1,5 @@ +formspec_version[4] +size[8,4] +position[0.5,0.5] +label[0.375,0.5;Edit me in realtime!] +button[2,1.0;4,0.5;test;This is a button] \ No newline at end of file diff --git a/mods/formspec_edit/init.lua b/mods/formspec_edit/init.lua new file mode 100644 index 0000000..484acd5 --- /dev/null +++ b/mods/formspec_edit/init.lua @@ -0,0 +1,119 @@ +--------------------------------- +---------Formspec Editor--------- +--------------------------------- +-----------By ExeVirus----------- + +--Fix builtin +minetest.register_alias("mapgen_stone", "air") +minetest.register_alias("mapgen_water_source", "air") + +--Variables +local modpath = minetest.get_modpath("formspec_edit") +local insecure_env = minetest.request_insecure_environment() +local auto_update_time = 0.2 --seconds +local error_formspec = [[ +formspec_version[4] +size[8,2] +position[0.5,0.5] +label[0.375,0.5;Error:formspec.spec is either ] +label[0.375,1;non-existent,or empty] +]] + +--function declarations +local update_formspec = nil +local load_formspec = nil +local auto_update = nil +local turn_off_hud = nil + +--Registrations + +----------------------------------- +--on_joinplayer() +----------------------------------- +minetest.register_on_joinplayer( +function(player_ref,_) + auto_update(player_ref:get_player_name()) + turn_off_hud(player_ref) + set_sky(player_ref) +end +) +----------------------------------- +--on_player_receive_fields() +----------------------------------- +minetest.register_on_player_receive_fields( +function(player_ref, _, fields) + if(fields.quit) then + minetest.request_shutdown() + end + update_formspec(player_ref:get_player_name()) +end +) + +--function definitions + +----------------------------------- +--auto_update() +----------------------------------- +auto_update = function(player_name) + update_formspec(player_name) + minetest.after(auto_update_time,auto_update,player_name) +end + +----------------------------------- +--update_formspec() +----------------------------------- +update_formspec = function(player_name) + minetest.after(0.1, + function(player_name) + minetest.show_formspec(player_name, "fs", load_formspec()) + end, + player_name) +end + +----------------------------------- +--load_formspec() +----------------------------------- +load_formspec = function() + local io = insecure_env.io + local file = io.open(modpath .. "/formspec.spec", "rb") + if file == nil then + return error_formspec + else + local content = file:read("*all") + file:close() + if content == nil then + return error_formspec + else + return content + end + end +end + +----------------------------------- +--turn_off_hud() +----------------------------------- +turn_off_hud = function(player_ref) + local flags = { + hotbar = false, + healthbar = false, + crosshair = false, + wielditem = false, + breathbar = false, + minimap = false, + minimap_radar = false, + } + player_ref:hud_set_flags(flags) +end + +----------------------------------- +--set_sky() +----------------------------------- +set_sky = function(player_ref) + local sky = { + base_color = "#AAF", + type = "plain", + clouds = false, + } + player_ref:set_sky(sky) + player_ref:override_day_night_ratio(0) +end \ No newline at end of file diff --git a/mods/formspec_edit/mod.conf b/mods/formspec_edit/mod.conf new file mode 100644 index 0000000..c9809cc --- /dev/null +++ b/mods/formspec_edit/mod.conf @@ -0,0 +1,3 @@ +name = formspec_edit +description = Provides realtime formspec viewing while editing live +title = Formspec Editor \ No newline at end of file diff --git a/preview.png b/preview.png new file mode 100644 index 0000000..bdb838f Binary files /dev/null and b/preview.png differ