Merge pull request #2 from AFCMS/globalstep

Some improvements from AFCMS, mostly options
master
ExeVirus 2021-07-20 17:03:10 -04:00 committed by GitHub
commit a51b7eb994
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 254 additions and 95 deletions

9
.editorconfig Executable file
View File

@ -0,0 +1,9 @@
[*]
end_of_line = lf
[*.{lua,spec}]
charset = utf8
indent_size = 4
indent_style = tab
insert_final_newline = true
trim_trailing_whitespace = true

2
.gitattributes vendored Normal file
View File

@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto

25
.github/workflows/main.yml vendored Normal file
View File

@ -0,0 +1,25 @@
name: luacheck
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
workflow_dispatch:
jobs:
main:
runs-on: ubuntu-latest
steps:
# Checks-out your repository under $GITHUB_WORKSPACE
- uses: actions/checkout@v2
- name: luacheck
uses: nebularg/actions-luacheck@v1.1.0
#with:
#files: # optional, default is .
#path: # optional, default is ${{ github.workspace }}
#args: # optional
#config: # optional
#annotate: # optional, default is none

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
.mods/formspec_edit/formspec.spec

47
.luacheckrc Normal file
View File

@ -0,0 +1,47 @@
max_line_length = false
read_globals = {
"DIR_DELIM", "INIT",
"minetest", "core",
"dump", "dump2",
"Raycast",
"Settings",
"PseudoRandom",
"PerlinNoise",
"VoxelManip",
"SecureRandom",
"VoxelArea",
"PerlinNoiseMap",
"PcgRandom",
"ItemStack",
"AreaStore",
"vector",
table = {
fields = {
"copy",
"indexof",
"insert_all",
"key_value_swap",
"shuffle",
}
},
string = {
fields = {
"split",
"trim",
}
},
math = {
fields = {
"hypot",
"sign",
"factorial"
}
},
}

View File

@ -5,17 +5,21 @@
## Getting Started
This mod needs access to an insecure environment in order to work.
Add `formspec_edit` to `secure.trusted_mods` in your `minetest.conf` file.
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, add ```formspec_edit``` to your ```secure.trusted_mods``` settings,
load up a level of *Formspec Editor*, and you will be greeted with the *formspec.spec* formspec.
contains a formspec you can edit and see updates of in real time. (You can also specify a file location with the `formspec_editor.file_path` setting.)
Simply add the game to MT, load up a level of *Formspec Editor*, and you will be greeted with the 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 make edits, open the file 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 <escape> 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.
- You can show the formspec with builtin, minetest_game or mineclone2 styling (see the `formspec_editor.style` setting)
- You can change the refresh rate by changing the `formspec_editor.update_time` setting

View File

@ -9,111 +9,165 @@ 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
if not insecure_env then
error("[formspec_editor] Cannot access insecure environment!")
end
local io = insecure_env.io
local update_time = tonumber(minetest.settings:get("formspec_editor.update_time")) or 0.2
--Load provided file if present
local filepath = minetest.settings:get("formspec_editor.file_path")
if not filepath or filepath == "" then
filepath = modpath .. "/formspec.spec"
end
--Get styling presets
local styling = minetest.settings:get("formspec_editor.style")
if not styling or styling == "" then
styling = "builtin"
end
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
--Crash if not singleplayer
--TODO: hide the 'Host server' checkbox in main menu then possible
if not minetest.is_singleplayer() then
error("[formspec_editor] This game doesn't work in multiplayer!")
end
--function definitions
-----------------------------------
--load_formspec()
-----------------------------------
local function load_formspec()
local file = io.open(filepath, "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
-----------------------------------
--update_formspec()
-----------------------------------
local function update_formspec(player_name)
minetest.after(0.1, function(name)
minetest.show_formspec(name, "fs", load_formspec())
end, player_name)
end
-----------------------------------
--apply_styling()
-----------------------------------
local function apply_styling(player_ref)
local prepend = ""
if styling == "minetest_game" then
------------------------------------------------
---------------Minetest Game code---------------
------------------------------------------------
prepend = [[
bgcolor[#080808BB;true]
listcolors[#00000069;#5A5A5A;#141318;#30434C;#FFF]
]]
local name = player_ref:get_player_name()
local info = minetest.get_player_information(name)
if info.formspec_version > 1 then
prepend = prepend .. "background9[5,5;1,1;mtg_gui_formbg.png;true;10]"
else
prepend = prepend .. "background[5,5;1,1;mtg_gui_formbg.png;true]"
end
elseif styling == "mineclone2" then
------------------------------------------------
---------------MineClone2 code------------------
------------------------------------------------
--Sadly, this code doesn't support inventory slot styling (texture based)
prepend = "listcolors[#9990;#FFF7;#FFF0;#000;#FFF]"..
"style_type[image_button;border=false;bgimg=mcl_inventory_button9.png;bgimg_pressed=mcl_inventory_button9_pressed.png;bgimg_middle=2,2]"..
"style_type[button;border=false;bgimg=mcl_inventory_button9.png;bgimg_pressed=mcl_inventory_button9_pressed.png;bgimg_middle=2,2]"..
"style_type[field;textcolor=#323232]"..
"style_type[label;textcolor=#323232]"..
"style_type[textarea;textcolor=#323232]"..
"style_type[checkbox;textcolor=#323232]"..
"bgcolor[#00000000]"..
"background9[1,1;1,1;mcl_base_textures_background9.png;true;7]"
end
player_ref:set_formspec_prepend(prepend)
end
-----------------------------------
--turn_off_hud()
-----------------------------------
local function turn_off_hud(player_ref)
player_ref:hud_set_flags({
hotbar = false,
healthbar = false,
crosshair = false,
wielditem = false,
breathbar = false,
minimap = false,
minimap_radar = false,
})
end
-----------------------------------
--set_sky()
-----------------------------------
local function set_sky(player_ref)
player_ref:set_sky({
base_color = "#AAF",
type = "plain",
clouds = false,
})
player_ref:set_stars({visible = false})
player_ref:set_sun({visible = false})
player_ref:set_moon({visible = false})
player_ref:override_day_night_ratio(0)
end
--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
)
minetest.register_on_joinplayer(function(player_ref,_)
apply_styling(player_ref)
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
)
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
local time = 0
minetest.register_globalstep(function(dtime)
time = time + dtime
if time >= update_time then
local player = minetest.get_connected_players()[1] --The game isn't supposed to work in multiplayer
if player then
update_formspec(player:get_player_name())
end
time = 0
end
end)

View File

@ -0,0 +1,9 @@
These textures are copied from Minetest Game and MineClone2 projects
# Minetest Game (CC BY-SA 3.0)
mtg_gui_formbg.png
# MineClone2 (CC BY-SA 3.0)
mcl_inventory_button9.png
mcl_inventory_button9_pressed.png
mcl_base_textures_background9.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 171 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 86 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 86 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 886 B

8
settingtypes.txt Normal file
View File

@ -0,0 +1,8 @@
# Formspec update time (in seconds)
formspec_editor.update_time (Update time) float 0.2
# Path of the formspec file
formspec_editor.file_path (File path) filepath
# Style type
formspec_editor.style (Formspec style) enum builtin builtin,minetest_game,mineclone2