Stock MainMenu
parent
5d4cdbd82d
commit
84cc7510ab
|
@ -1,463 +0,0 @@
|
||||||
--[[
|
|
||||||
ProFi v1.3, by Luke Perkin 2012. MIT Licence http://www.opensource.org/licenses/mit-license.php.
|
|
||||||
|
|
||||||
Example:
|
|
||||||
ProFi = require 'ProFi'
|
|
||||||
ProFi:start()
|
|
||||||
some_function()
|
|
||||||
another_function()
|
|
||||||
coroutine.resume( some_coroutine )
|
|
||||||
ProFi:stop()
|
|
||||||
ProFi:writeReport( 'MyProfilingReport.txt' )
|
|
||||||
|
|
||||||
API:
|
|
||||||
*Arguments are specified as: type/name/default.
|
|
||||||
ProFi:start( string/once/nil )
|
|
||||||
ProFi:stop()
|
|
||||||
ProFi:checkMemory( number/interval/0, string/note/'' )
|
|
||||||
ProFi:writeReport( string/filename/'ProFi.txt' )
|
|
||||||
ProFi:reset()
|
|
||||||
ProFi:setHookCount( number/hookCount/0 )
|
|
||||||
ProFi:setGetTimeMethod( function/getTimeMethod/os.clock )
|
|
||||||
ProFi:setInspect( string/methodName, number/levels/1 )
|
|
||||||
]]
|
|
||||||
|
|
||||||
-----------------------
|
|
||||||
-- Locals:
|
|
||||||
-----------------------
|
|
||||||
|
|
||||||
local ProFi = {}
|
|
||||||
local onDebugHook, sortByDurationDesc, sortByCallCount, getTime
|
|
||||||
local DEFAULT_DEBUG_HOOK_COUNT = 0
|
|
||||||
local FORMAT_HEADER_LINE = "| %-50s: %-40s: %-20s: %-12s: %-12s: %-12s|\n"
|
|
||||||
local FORMAT_OUTPUT_LINE = "| %s: %-12s: %-12s: %-12s|\n"
|
|
||||||
local FORMAT_INSPECTION_LINE = "> %s: %-12s\n"
|
|
||||||
local FORMAT_TOTALTIME_LINE = "| TOTAL TIME = %f\n"
|
|
||||||
local FORMAT_MEMORY_LINE = "| %-20s: %-16s: %-16s| %s\n"
|
|
||||||
local FORMAT_HIGH_MEMORY_LINE = "H %-20s: %-16s: %-16sH %s\n"
|
|
||||||
local FORMAT_LOW_MEMORY_LINE = "L %-20s: %-16s: %-16sL %s\n"
|
|
||||||
local FORMAT_TITLE = "%-50.50s: %-40.40s: %-20s"
|
|
||||||
local FORMAT_LINENUM = "%4i"
|
|
||||||
local FORMAT_TIME = "%04.3f"
|
|
||||||
local FORMAT_RELATIVE = "%03.2f%%"
|
|
||||||
local FORMAT_COUNT = "%7i"
|
|
||||||
local FORMAT_KBYTES = "%7i Kbytes"
|
|
||||||
local FORMAT_MBYTES = "%7.1f Mbytes"
|
|
||||||
local FORMAT_MEMORY_HEADER1 = "\n=== HIGH & LOW MEMORY USAGE ===============================\n"
|
|
||||||
local FORMAT_MEMORY_HEADER2 = "=== MEMORY USAGE ==========================================\n"
|
|
||||||
local FORMAT_BANNER = [[
|
|
||||||
###############################################################################################################
|
|
||||||
##### ProFi, a lua profiler. This profile was generated on: %s
|
|
||||||
##### ProFi is created by Luke Perkin 2012 under the MIT Licence, www.locofilm.co.uk
|
|
||||||
##### Version 1.3. Get the most recent version at this gist: https://gist.github.com/2838755
|
|
||||||
###############################################################################################################
|
|
||||||
|
|
||||||
]]
|
|
||||||
|
|
||||||
-----------------------
|
|
||||||
-- Public Methods:
|
|
||||||
-----------------------
|
|
||||||
|
|
||||||
--[[
|
|
||||||
Starts profiling any method that is called between this and ProFi:stop().
|
|
||||||
Pass the parameter 'once' to so that this methodis only run once.
|
|
||||||
Example:
|
|
||||||
ProFi:start( 'once' )
|
|
||||||
]]
|
|
||||||
function ProFi:start( param )
|
|
||||||
if param == 'once' then
|
|
||||||
if self:shouldReturn() then
|
|
||||||
return
|
|
||||||
else
|
|
||||||
self.should_run_once = true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
self.has_started = true
|
|
||||||
self.has_finished = false
|
|
||||||
self:resetReports( self.reports )
|
|
||||||
self:startHooks()
|
|
||||||
self.startTime = getTime()
|
|
||||||
end
|
|
||||||
|
|
||||||
--[[
|
|
||||||
Stops profiling.
|
|
||||||
]]
|
|
||||||
function ProFi:stop()
|
|
||||||
if self:shouldReturn() then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
self.stopTime = getTime()
|
|
||||||
self:stopHooks()
|
|
||||||
self.has_finished = true
|
|
||||||
end
|
|
||||||
|
|
||||||
function ProFi:checkMemory( interval, note )
|
|
||||||
local time = getTime()
|
|
||||||
local interval = interval or 0
|
|
||||||
if self.lastCheckMemoryTime and time < self.lastCheckMemoryTime + interval then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
self.lastCheckMemoryTime = time
|
|
||||||
local memoryReport = {
|
|
||||||
['time'] = time;
|
|
||||||
['memory'] = collectgarbage('count');
|
|
||||||
['note'] = note or '';
|
|
||||||
}
|
|
||||||
table.insert( self.memoryReports, memoryReport )
|
|
||||||
self:setHighestMemoryReport( memoryReport )
|
|
||||||
self:setLowestMemoryReport( memoryReport )
|
|
||||||
end
|
|
||||||
|
|
||||||
--[[
|
|
||||||
Writes the profile report to a file.
|
|
||||||
Param: [filename:string:optional] defaults to 'ProFi.txt' if not specified.
|
|
||||||
]]
|
|
||||||
function ProFi:writeReport( filename )
|
|
||||||
if #self.reports > 0 or #self.memoryReports > 0 then
|
|
||||||
filename = filename or 'ProFi.txt'
|
|
||||||
self:sortReportsWithSortMethod( self.reports, self.sortMethod )
|
|
||||||
self:writeReportsToFilename( filename )
|
|
||||||
print( string.format("[ProFi]\t Report written to %s", filename) )
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
--[[
|
|
||||||
Resets any profile information stored.
|
|
||||||
]]
|
|
||||||
function ProFi:reset()
|
|
||||||
self.reports = {}
|
|
||||||
self.reportsByTitle = {}
|
|
||||||
self.memoryReports = {}
|
|
||||||
self.highestMemoryReport = nil
|
|
||||||
self.lowestMemoryReport = nil
|
|
||||||
self.has_started = false
|
|
||||||
self.has_finished = false
|
|
||||||
self.should_run_once = false
|
|
||||||
self.lastCheckMemoryTime = nil
|
|
||||||
self.hookCount = self.hookCount or DEFAULT_DEBUG_HOOK_COUNT
|
|
||||||
self.sortMethod = self.sortMethod or sortByDurationDesc
|
|
||||||
self.inspect = nil
|
|
||||||
end
|
|
||||||
|
|
||||||
--[[
|
|
||||||
Set how often a hook is called.
|
|
||||||
See http://pgl.yoyo.org/luai/i/debug.sethook for information.
|
|
||||||
Param: [hookCount:number] if 0 ProFi counts every time a function is called.
|
|
||||||
if 2 ProFi counts every other 2 function calls.
|
|
||||||
]]
|
|
||||||
function ProFi:setHookCount( hookCount )
|
|
||||||
self.hookCount = hookCount
|
|
||||||
end
|
|
||||||
|
|
||||||
--[[
|
|
||||||
Set how the report is sorted when written to file.
|
|
||||||
Param: [sortType:string] either 'duration' or 'count'.
|
|
||||||
'duration' sorts by the time a method took to run.
|
|
||||||
'count' sorts by the number of times a method was called.
|
|
||||||
]]
|
|
||||||
function ProFi:setSortMethod( sortType )
|
|
||||||
if sortType == 'duration' then
|
|
||||||
self.sortMethod = sortByDurationDesc
|
|
||||||
elseif sortType == 'count' then
|
|
||||||
self.sortMethod = sortByCallCount
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
--[[
|
|
||||||
By default the getTime method is os.clock (CPU time),
|
|
||||||
If you wish to use other time methods pass it to this function.
|
|
||||||
Param: [getTimeMethod:function]
|
|
||||||
]]
|
|
||||||
function ProFi:setGetTimeMethod( getTimeMethod )
|
|
||||||
getTime = getTimeMethod
|
|
||||||
end
|
|
||||||
|
|
||||||
--[[
|
|
||||||
Allows you to inspect a specific method.
|
|
||||||
Will write to the report a list of methods that
|
|
||||||
call this method you're inspecting, you can optionally
|
|
||||||
provide a levels parameter to traceback a number of levels.
|
|
||||||
Params: [methodName:string] the name of the method you wish to inspect.
|
|
||||||
[levels:number:optional] the amount of levels you wish to traceback, defaults to 1.
|
|
||||||
]]
|
|
||||||
function ProFi:setInspect( methodName, levels )
|
|
||||||
if self.inspect then
|
|
||||||
self.inspect.methodName = methodName
|
|
||||||
self.inspect.levels = levels or 1
|
|
||||||
else
|
|
||||||
self.inspect = {
|
|
||||||
['methodName'] = methodName;
|
|
||||||
['levels'] = levels or 1;
|
|
||||||
}
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-----------------------
|
|
||||||
-- Implementations methods:
|
|
||||||
-----------------------
|
|
||||||
|
|
||||||
function ProFi:shouldReturn( )
|
|
||||||
return self.should_run_once and self.has_finished
|
|
||||||
end
|
|
||||||
|
|
||||||
function ProFi:getFuncReport( funcInfo )
|
|
||||||
local title = self:getTitleFromFuncInfo( funcInfo )
|
|
||||||
local funcReport = self.reportsByTitle[ title ]
|
|
||||||
if not funcReport then
|
|
||||||
funcReport = self:createFuncReport( funcInfo )
|
|
||||||
self.reportsByTitle[ title ] = funcReport
|
|
||||||
table.insert( self.reports, funcReport )
|
|
||||||
end
|
|
||||||
return funcReport
|
|
||||||
end
|
|
||||||
|
|
||||||
function ProFi:getTitleFromFuncInfo( funcInfo )
|
|
||||||
local name = funcInfo.name or 'anonymous'
|
|
||||||
-- TODO (freeminer): remove common path, i.e. /home/xyz/freeminer/games/default/, from the source
|
|
||||||
local source = funcInfo.source:sub(-50) or 'C_FUNC'
|
|
||||||
local linedefined = funcInfo.linedefined or 0
|
|
||||||
linedefined = string.format( FORMAT_LINENUM, linedefined )
|
|
||||||
return string.format(FORMAT_TITLE, source, name, linedefined)
|
|
||||||
end
|
|
||||||
|
|
||||||
function ProFi:createFuncReport( funcInfo )
|
|
||||||
local name = funcInfo.name or 'anonymous'
|
|
||||||
local source = funcInfo.source or 'C Func'
|
|
||||||
local linedefined = funcInfo.linedefined or 0
|
|
||||||
local funcReport = {
|
|
||||||
['title'] = self:getTitleFromFuncInfo( funcInfo );
|
|
||||||
['count'] = 0;
|
|
||||||
['timer'] = 0;
|
|
||||||
}
|
|
||||||
return funcReport
|
|
||||||
end
|
|
||||||
|
|
||||||
function ProFi:startHooks()
|
|
||||||
debug.sethook( onDebugHook, 'cr', self.hookCount )
|
|
||||||
end
|
|
||||||
|
|
||||||
function ProFi:stopHooks()
|
|
||||||
debug.sethook()
|
|
||||||
end
|
|
||||||
|
|
||||||
function ProFi:sortReportsWithSortMethod( reports, sortMethod )
|
|
||||||
if reports then
|
|
||||||
table.sort( reports, sortMethod )
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function ProFi:writeReportsToFilename( filename )
|
|
||||||
local file, err = io.open( filename, 'w' )
|
|
||||||
assert( file, err )
|
|
||||||
self:writeBannerToFile( file )
|
|
||||||
if #self.reports > 0 then
|
|
||||||
self:writeProfilingReportsToFile( self.reports, file )
|
|
||||||
end
|
|
||||||
if #self.memoryReports > 0 then
|
|
||||||
self:writeMemoryReportsToFile( self.memoryReports, file )
|
|
||||||
end
|
|
||||||
file:close()
|
|
||||||
end
|
|
||||||
|
|
||||||
function ProFi:writeProfilingReportsToFile( reports, file )
|
|
||||||
local totalTime = self.stopTime - self.startTime
|
|
||||||
local totalTimeOutput = string.format(FORMAT_TOTALTIME_LINE, totalTime)
|
|
||||||
file:write( totalTimeOutput )
|
|
||||||
local header = string.format( FORMAT_HEADER_LINE, "FILE", "FUNCTION", "LINE", "TIME", "RELATIVE", "CALLED" )
|
|
||||||
file:write( header )
|
|
||||||
for i, funcReport in ipairs( reports ) do
|
|
||||||
local timer = string.format(FORMAT_TIME, funcReport.timer)
|
|
||||||
local count = string.format(FORMAT_COUNT, funcReport.count)
|
|
||||||
local relTime = string.format(FORMAT_RELATIVE, (funcReport.timer / totalTime) * 100 )
|
|
||||||
local outputLine = string.format(FORMAT_OUTPUT_LINE, funcReport.title, timer, relTime, count )
|
|
||||||
file:write( outputLine )
|
|
||||||
if funcReport.inspections then
|
|
||||||
self:writeInpsectionsToFile( funcReport.inspections, file )
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function ProFi:writeMemoryReportsToFile( reports, file )
|
|
||||||
file:write( FORMAT_MEMORY_HEADER1 )
|
|
||||||
self:writeHighestMemoryReportToFile( file )
|
|
||||||
self:writeLowestMemoryReportToFile( file )
|
|
||||||
file:write( FORMAT_MEMORY_HEADER2 )
|
|
||||||
for i, memoryReport in ipairs( reports ) do
|
|
||||||
local outputLine = self:formatMemoryReportWithFormatter( memoryReport, FORMAT_MEMORY_LINE )
|
|
||||||
file:write( outputLine )
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function ProFi:writeHighestMemoryReportToFile( file )
|
|
||||||
local memoryReport = self.highestMemoryReport
|
|
||||||
local outputLine = self:formatMemoryReportWithFormatter( memoryReport, FORMAT_HIGH_MEMORY_LINE )
|
|
||||||
file:write( outputLine )
|
|
||||||
end
|
|
||||||
|
|
||||||
function ProFi:writeLowestMemoryReportToFile( file )
|
|
||||||
local memoryReport = self.lowestMemoryReport
|
|
||||||
local outputLine = self:formatMemoryReportWithFormatter( memoryReport, FORMAT_LOW_MEMORY_LINE )
|
|
||||||
file:write( outputLine )
|
|
||||||
end
|
|
||||||
|
|
||||||
function ProFi:formatMemoryReportWithFormatter( memoryReport, formatter )
|
|
||||||
local time = string.format(FORMAT_TIME, memoryReport.time)
|
|
||||||
local kbytes = string.format(FORMAT_KBYTES, memoryReport.memory)
|
|
||||||
local mbytes = string.format(FORMAT_MBYTES, memoryReport.memory/1024)
|
|
||||||
local outputLine = string.format(formatter, time, kbytes, mbytes, memoryReport.note)
|
|
||||||
return outputLine
|
|
||||||
end
|
|
||||||
|
|
||||||
function ProFi:writeBannerToFile( file )
|
|
||||||
local banner = string.format(FORMAT_BANNER, os.date())
|
|
||||||
file:write( banner )
|
|
||||||
end
|
|
||||||
|
|
||||||
function ProFi:writeInpsectionsToFile( inspections, file )
|
|
||||||
local inspectionsList = self:sortInspectionsIntoList( inspections )
|
|
||||||
file:write('\n==^ INSPECT ^======================================================================================================== COUNT ===\n')
|
|
||||||
for i, inspection in ipairs( inspectionsList ) do
|
|
||||||
local line = string.format(FORMAT_LINENUM, inspection.line)
|
|
||||||
local title = string.format(FORMAT_TITLE, inspection.source, inspection.name, line)
|
|
||||||
local count = string.format(FORMAT_COUNT, inspection.count)
|
|
||||||
local outputLine = string.format(FORMAT_INSPECTION_LINE, title, count )
|
|
||||||
file:write( outputLine )
|
|
||||||
end
|
|
||||||
file:write('===============================================================================================================================\n\n')
|
|
||||||
end
|
|
||||||
|
|
||||||
function ProFi:sortInspectionsIntoList( inspections )
|
|
||||||
local inspectionsList = {}
|
|
||||||
for k, inspection in pairs(inspections) do
|
|
||||||
inspectionsList[#inspectionsList+1] = inspection
|
|
||||||
end
|
|
||||||
table.sort( inspectionsList, sortByCallCount )
|
|
||||||
return inspectionsList
|
|
||||||
end
|
|
||||||
|
|
||||||
function ProFi:resetReports( reports )
|
|
||||||
for i, report in ipairs( reports ) do
|
|
||||||
report.timer = 0
|
|
||||||
report.count = 0
|
|
||||||
report.inspections = nil
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function ProFi:shouldInspect( funcInfo )
|
|
||||||
return self.inspect and self.inspect.methodName == funcInfo.name
|
|
||||||
end
|
|
||||||
|
|
||||||
function ProFi:getInspectionsFromReport( funcReport )
|
|
||||||
local inspections = funcReport.inspections
|
|
||||||
if not inspections then
|
|
||||||
inspections = {}
|
|
||||||
funcReport.inspections = inspections
|
|
||||||
end
|
|
||||||
return inspections
|
|
||||||
end
|
|
||||||
|
|
||||||
function ProFi:getInspectionWithKeyFromInspections( key, inspections )
|
|
||||||
local inspection = inspections[key]
|
|
||||||
if not inspection then
|
|
||||||
inspection = {
|
|
||||||
['count'] = 0;
|
|
||||||
}
|
|
||||||
inspections[key] = inspection
|
|
||||||
end
|
|
||||||
return inspection
|
|
||||||
end
|
|
||||||
|
|
||||||
function ProFi:doInspection( inspect, funcReport )
|
|
||||||
local inspections = self:getInspectionsFromReport( funcReport )
|
|
||||||
local levels = 5 + inspect.levels
|
|
||||||
local currentLevel = 5
|
|
||||||
while currentLevel < levels do
|
|
||||||
local funcInfo = debug.getinfo( currentLevel, 'nS' )
|
|
||||||
if funcInfo then
|
|
||||||
local source = funcInfo.short_src or '[C]'
|
|
||||||
local name = funcInfo.name or 'anonymous'
|
|
||||||
local line = funcInfo.linedefined
|
|
||||||
local key = source..name..line
|
|
||||||
local inspection = self:getInspectionWithKeyFromInspections( key, inspections )
|
|
||||||
inspection.source = source
|
|
||||||
inspection.name = name
|
|
||||||
inspection.line = line
|
|
||||||
inspection.count = inspection.count + 1
|
|
||||||
currentLevel = currentLevel + 1
|
|
||||||
else
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function ProFi:onFunctionCall( funcInfo )
|
|
||||||
local funcReport = ProFi:getFuncReport( funcInfo )
|
|
||||||
funcReport.callTime = getTime()
|
|
||||||
funcReport.count = funcReport.count + 1
|
|
||||||
if self:shouldInspect( funcInfo ) then
|
|
||||||
self:doInspection( self.inspect, funcReport )
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function ProFi:onFunctionReturn( funcInfo )
|
|
||||||
local funcReport = ProFi:getFuncReport( funcInfo )
|
|
||||||
if funcReport.callTime then
|
|
||||||
local time = getTime() - funcReport.callTime
|
|
||||||
-- handle overflow for unsigned 32-bit time
|
|
||||||
-- if for some reason `unsigned int` is 64-bit then overflows don't happen!
|
|
||||||
if time < 0 then
|
|
||||||
time = 4294967296 / 1000000 + time
|
|
||||||
end
|
|
||||||
funcReport.timer = funcReport.timer + time
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function ProFi:setHighestMemoryReport( memoryReport )
|
|
||||||
if not self.highestMemoryReport then
|
|
||||||
self.highestMemoryReport = memoryReport
|
|
||||||
else
|
|
||||||
if memoryReport.memory > self.highestMemoryReport.memory then
|
|
||||||
self.highestMemoryReport = memoryReport
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function ProFi:setLowestMemoryReport( memoryReport )
|
|
||||||
if not self.lowestMemoryReport then
|
|
||||||
self.lowestMemoryReport = memoryReport
|
|
||||||
else
|
|
||||||
if memoryReport.memory < self.lowestMemoryReport.memory then
|
|
||||||
self.lowestMemoryReport = memoryReport
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-----------------------
|
|
||||||
-- Local Functions:
|
|
||||||
-----------------------
|
|
||||||
|
|
||||||
getTime = os.clock
|
|
||||||
|
|
||||||
onDebugHook = function( hookType )
|
|
||||||
local funcInfo = debug.getinfo( 2, 'nS' )
|
|
||||||
if hookType == "call" then
|
|
||||||
ProFi:onFunctionCall( funcInfo )
|
|
||||||
elseif hookType == "return" then
|
|
||||||
ProFi:onFunctionReturn( funcInfo )
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
sortByDurationDesc = function( a, b )
|
|
||||||
return a.timer > b.timer
|
|
||||||
end
|
|
||||||
|
|
||||||
sortByCallCount = function( a, b )
|
|
||||||
return a.count > b.count
|
|
||||||
end
|
|
||||||
|
|
||||||
-----------------------
|
|
||||||
-- Return Module:
|
|
||||||
-----------------------
|
|
||||||
|
|
||||||
ProFi:reset()
|
|
||||||
return ProFi
|
|
|
@ -1,17 +1,17 @@
|
||||||
|
|
||||||
multicraft.log("info", "Initializing Asynchronous environment")
|
core.log("info", "Initializing Asynchronous environment")
|
||||||
|
|
||||||
function multicraft.job_processor(serialized_func, serialized_param)
|
function core.job_processor(serialized_func, serialized_param)
|
||||||
local func = loadstring(serialized_func)
|
local func = loadstring(serialized_func)
|
||||||
local param = multicraft.deserialize(serialized_param)
|
local param = core.deserialize(serialized_param)
|
||||||
local retval = nil
|
local retval = nil
|
||||||
|
|
||||||
if type(func) == "function" then
|
if type(func) == "function" then
|
||||||
retval = multicraft.serialize(func(param))
|
retval = core.serialize(func(param))
|
||||||
else
|
else
|
||||||
multicraft.log("error", "ASYNC WORKER: Unable to deserialize function")
|
core.log("error", "ASYNC WORKER: Unable to deserialize function")
|
||||||
end
|
end
|
||||||
|
|
||||||
return retval or multicraft.serialize(nil)
|
return retval or core.serialize(nil)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,39 +1,39 @@
|
||||||
|
|
||||||
multicraft.async_jobs = {}
|
core.async_jobs = {}
|
||||||
|
|
||||||
local function handle_job(jobid, serialized_retval)
|
local function handle_job(jobid, serialized_retval)
|
||||||
local retval = multicraft.deserialize(serialized_retval)
|
local retval = core.deserialize(serialized_retval)
|
||||||
assert(type(multicraft.async_jobs[jobid]) == "function")
|
assert(type(core.async_jobs[jobid]) == "function")
|
||||||
multicraft.async_jobs[jobid](retval)
|
core.async_jobs[jobid](retval)
|
||||||
multicraft.async_jobs[jobid] = nil
|
core.async_jobs[jobid] = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
if multicraft.register_globalstep then
|
if core.register_globalstep then
|
||||||
multicraft.register_globalstep(function(dtime)
|
core.register_globalstep(function(dtime)
|
||||||
for i, job in ipairs(multicraft.get_finished_jobs()) do
|
for i, job in ipairs(core.get_finished_jobs()) do
|
||||||
handle_job(job.jobid, job.retval)
|
handle_job(job.jobid, job.retval)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
else
|
else
|
||||||
multicraft.async_event_handler = handle_job
|
core.async_event_handler = handle_job
|
||||||
end
|
end
|
||||||
|
|
||||||
function multicraft.handle_async(func, parameter, callback)
|
function core.handle_async(func, parameter, callback)
|
||||||
-- Serialize function
|
-- Serialize function
|
||||||
local serialized_func = string.dump(func)
|
local serialized_func = string.dump(func)
|
||||||
|
|
||||||
assert(serialized_func ~= nil)
|
assert(serialized_func ~= nil)
|
||||||
|
|
||||||
-- Serialize parameters
|
-- Serialize parameters
|
||||||
local serialized_param = multicraft.serialize(parameter)
|
local serialized_param = core.serialize(parameter)
|
||||||
|
|
||||||
if serialized_param == nil then
|
if serialized_param == nil then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
local jobid = multicraft.do_async_callback(serialized_func, serialized_param)
|
local jobid = core.do_async_callback(serialized_func, serialized_param)
|
||||||
|
|
||||||
multicraft.async_jobs[jobid] = callback
|
core.async_jobs[jobid] = callback
|
||||||
|
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
--
|
--
|
||||||
--This program is free software; you can redistribute it and/or modify
|
--This program is free software; you can redistribute it and/or modify
|
||||||
--it under the terms of the GNU Lesser General Public License as published by
|
--it under the terms of the GNU Lesser General Public License as published by
|
||||||
--the Free Software Foundation; either version 3.0 of the License, or
|
--the Free Software Foundation; either version 2.1 of the License, or
|
||||||
--(at your option) any later version.
|
--(at your option) any later version.
|
||||||
--
|
--
|
||||||
--This program is distributed in the hope that it will be useful,
|
--This program is distributed in the hope that it will be useful,
|
||||||
|
|
|
@ -281,7 +281,7 @@ function cleanup_path(temppath)
|
||||||
return temppath
|
return temppath
|
||||||
end
|
end
|
||||||
|
|
||||||
function multicraft.formspec_escape(text)
|
function core.formspec_escape(text)
|
||||||
if text ~= nil then
|
if text ~= nil then
|
||||||
text = string.gsub(text,"\\","\\\\")
|
text = string.gsub(text,"\\","\\\\")
|
||||||
text = string.gsub(text,"%]","\\]")
|
text = string.gsub(text,"%]","\\]")
|
||||||
|
@ -293,7 +293,7 @@ function multicraft.formspec_escape(text)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function multicraft.splittext(text,charlimit)
|
function core.splittext(text,charlimit)
|
||||||
local retval = {}
|
local retval = {}
|
||||||
|
|
||||||
local current_idx = 1
|
local current_idx = 1
|
||||||
|
@ -354,29 +354,29 @@ if INIT == "game" then
|
||||||
local dirs1 = {9, 18, 7, 12}
|
local dirs1 = {9, 18, 7, 12}
|
||||||
local dirs2 = {20, 23, 22, 21}
|
local dirs2 = {20, 23, 22, 21}
|
||||||
|
|
||||||
function multicraft.rotate_and_place(itemstack, placer, pointed_thing,
|
function core.rotate_and_place(itemstack, placer, pointed_thing,
|
||||||
infinitestacks, orient_flags)
|
infinitestacks, orient_flags)
|
||||||
orient_flags = orient_flags or {}
|
orient_flags = orient_flags or {}
|
||||||
|
|
||||||
local unode = multicraft.get_node_or_nil(pointed_thing.under)
|
local unode = core.get_node_or_nil(pointed_thing.under)
|
||||||
if not unode then
|
if not unode then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local undef = multicraft.registered_nodes[unode.name]
|
local undef = core.registered_nodes[unode.name]
|
||||||
if undef and undef.on_rightclick then
|
if undef and undef.on_rightclick then
|
||||||
undef.on_rightclick(pointed_thing.under, unode, placer,
|
undef.on_rightclick(pointed_thing.under, unode, placer,
|
||||||
itemstack, pointed_thing)
|
itemstack, pointed_thing)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local pitch = placer:get_look_pitch()
|
local pitch = placer:get_look_pitch()
|
||||||
local fdir = multicraft.dir_to_facedir(placer:get_look_dir())
|
local fdir = core.dir_to_facedir(placer:get_look_dir())
|
||||||
local wield_name = itemstack:get_name()
|
local wield_name = itemstack:get_name()
|
||||||
|
|
||||||
local above = pointed_thing.above
|
local above = pointed_thing.above
|
||||||
local under = pointed_thing.under
|
local under = pointed_thing.under
|
||||||
local iswall = (above.y == under.y)
|
local iswall = (above.y == under.y)
|
||||||
local isceiling = not iswall and (above.y < under.y)
|
local isceiling = not iswall and (above.y < under.y)
|
||||||
local anode = multicraft.get_node_or_nil(above)
|
local anode = core.get_node_or_nil(above)
|
||||||
if not anode then
|
if not anode then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
@ -389,13 +389,13 @@ if INIT == "game" then
|
||||||
iswall = false
|
iswall = false
|
||||||
end
|
end
|
||||||
|
|
||||||
if multicraft.is_protected(pos, placer:get_player_name()) then
|
if core.is_protected(pos, placer:get_player_name()) then
|
||||||
multicraft.record_protection_violation(pos,
|
core.record_protection_violation(pos,
|
||||||
placer:get_player_name())
|
placer:get_player_name())
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local ndef = multicraft.registered_nodes[node.name]
|
local ndef = core.registered_nodes[node.name]
|
||||||
if not ndef or not ndef.buildable_to then
|
if not ndef or not ndef.buildable_to then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
@ -414,22 +414,22 @@ if INIT == "game" then
|
||||||
end
|
end
|
||||||
|
|
||||||
if iswall then
|
if iswall then
|
||||||
multicraft.set_node(pos, {name = wield_name,
|
core.set_node(pos, {name = wield_name,
|
||||||
param2 = dirs1[fdir+1]})
|
param2 = dirs1[fdir+1]})
|
||||||
elseif isceiling then
|
elseif isceiling then
|
||||||
if orient_flags.force_facedir then
|
if orient_flags.force_facedir then
|
||||||
multicraft.set_node(pos, {name = wield_name,
|
core.set_node(pos, {name = wield_name,
|
||||||
param2 = 20})
|
param2 = 20})
|
||||||
else
|
else
|
||||||
multicraft.set_node(pos, {name = wield_name,
|
core.set_node(pos, {name = wield_name,
|
||||||
param2 = dirs2[fdir+1]})
|
param2 = dirs2[fdir+1]})
|
||||||
end
|
end
|
||||||
else -- place right side up
|
else -- place right side up
|
||||||
if orient_flags.force_facedir then
|
if orient_flags.force_facedir then
|
||||||
multicraft.set_node(pos, {name = wield_name,
|
core.set_node(pos, {name = wield_name,
|
||||||
param2 = 0})
|
param2 = 0})
|
||||||
else
|
else
|
||||||
multicraft.set_node(pos, {name = wield_name,
|
core.set_node(pos, {name = wield_name,
|
||||||
param2 = fdir})
|
param2 = fdir})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -446,125 +446,17 @@ if INIT == "game" then
|
||||||
--implies infinite stacks when performing a 6d rotation.
|
--implies infinite stacks when performing a 6d rotation.
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
multicraft.rotate_node = function(itemstack, placer, pointed_thing)
|
|
||||||
multicraft.rotate_and_place(itemstack, placer, pointed_thing,
|
|
||||||
multicraft.setting_getbool("creative_mode"),
|
|
||||||
{invert_wall = placer:get_player_control().sneak})
|
|
||||||
return itemstack
|
|
||||||
end
|
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
core.rotate_node = function(itemstack, placer, pointed_thing)
|
||||||
-- Function to make a copy of an existing node definition, to be used
|
core.rotate_and_place(itemstack, placer, pointed_thing,
|
||||||
-- by mods that need to redefine some aspect of a node, but without
|
core.setting_getbool("creative_mode"),
|
||||||
-- them having to copy&paste the entire node definition.
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
function multicraft.clone_node(name)
|
|
||||||
node2={}
|
|
||||||
node=multicraft.registered_nodes[name]
|
|
||||||
for k,v in pairs(node) do
|
|
||||||
node2[k]=v
|
|
||||||
end
|
|
||||||
return node2
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
if multicraft then
|
|
||||||
local dirs1 = { 9, 18, 7, 12 }
|
|
||||||
local dirs2 = { 20, 23, 22, 21 }
|
|
||||||
|
|
||||||
function multicraft.rotate_and_place(itemstack, placer, pointed_thing, infinitestacks, orient_flags)
|
|
||||||
orient_flags = orient_flags or {}
|
|
||||||
|
|
||||||
local node = multicraft.get_node(pointed_thing.under)
|
|
||||||
if not multicraft.registered_nodes[node.name]
|
|
||||||
or not multicraft.registered_nodes[node.name].on_rightclick then
|
|
||||||
|
|
||||||
local above = pointed_thing.above
|
|
||||||
local under = pointed_thing.under
|
|
||||||
local pitch = placer:get_look_pitch()
|
|
||||||
local pname = multicraft.get_node(under).name
|
|
||||||
local node = multicraft.get_node(above)
|
|
||||||
local fdir = multicraft.dir_to_facedir(placer:get_look_dir())
|
|
||||||
local wield_name = itemstack:get_name()
|
|
||||||
local reg_node = multicraft.registered_nodes[pname]
|
|
||||||
|
|
||||||
if not reg_node or not reg_node.on_rightclick then
|
|
||||||
|
|
||||||
local iswall = (above.x ~= under.x) or (above.z ~= under.z)
|
|
||||||
local isceiling = (above.x == under.x) and (above.z == under.z)
|
|
||||||
and (pitch > 0)
|
|
||||||
local pos1 = above
|
|
||||||
|
|
||||||
if reg_node and reg_node.buildable_to then
|
|
||||||
pos1 = under
|
|
||||||
iswall = false
|
|
||||||
end
|
|
||||||
|
|
||||||
reg_node = multicraft.registered_nodes[multicraft.get_node(pos1).name]
|
|
||||||
if not reg_node or not reg_node.buildable_to then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
if orient_flags.force_floor then
|
|
||||||
iswall = false
|
|
||||||
isceiling = false
|
|
||||||
elseif orient_flags.force_ceiling then
|
|
||||||
iswall = false
|
|
||||||
isceiling = true
|
|
||||||
elseif orient_flags.force_wall then
|
|
||||||
iswall = true
|
|
||||||
isceiling = false
|
|
||||||
elseif orient_flags.invert_wall then
|
|
||||||
iswall = not iswall
|
|
||||||
end
|
|
||||||
|
|
||||||
if iswall then
|
|
||||||
multicraft.add_node(pos1, {name = wield_name, param2 = dirs1[fdir+1] })
|
|
||||||
elseif isceiling then
|
|
||||||
if orient_flags.force_facedir then
|
|
||||||
multicraft.add_node(pos1, {name = wield_name, param2 = 20 })
|
|
||||||
else
|
|
||||||
multicraft.add_node(pos1, {name = wield_name, param2 = dirs2[fdir+1] })
|
|
||||||
end
|
|
||||||
else -- place right side up
|
|
||||||
if orient_flags.force_facedir then
|
|
||||||
multicraft.add_node(pos1, {name = wield_name, param2 = 0 })
|
|
||||||
else
|
|
||||||
multicraft.add_node(pos1, {name = wield_name, param2 = fdir })
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if not infinitestacks then
|
|
||||||
itemstack:take_item()
|
|
||||||
return itemstack
|
|
||||||
end
|
|
||||||
end
|
|
||||||
else
|
|
||||||
multicraft.registered_nodes[node.name].on_rightclick(pointed_thing.under, node, placer, itemstack)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
--Wrapper for rotate_and_place() to check for sneak and assume Creative mode
|
|
||||||
--implies infinite stacks when performing a 6d rotation.
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
|
|
||||||
multicraft.rotate_node = function(itemstack, placer, pointed_thing)
|
|
||||||
multicraft.rotate_and_place(itemstack, placer, pointed_thing,
|
|
||||||
multicraft.setting_getbool("creative_mode"),
|
|
||||||
{invert_wall = placer:get_player_control().sneak})
|
{invert_wall = placer:get_player_control().sneak})
|
||||||
return itemstack
|
return itemstack
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
function multicraft.explode_table_event(evt)
|
function core.explode_table_event(evt)
|
||||||
if evt ~= nil then
|
if evt ~= nil then
|
||||||
local parts = evt:split(":")
|
local parts = evt:split(":")
|
||||||
if #parts == 3 then
|
if #parts == 3 then
|
||||||
|
@ -581,7 +473,7 @@ function multicraft.explode_table_event(evt)
|
||||||
end
|
end
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
function multicraft.explode_textlist_event(evt)
|
function core.explode_textlist_event(evt)
|
||||||
if evt ~= nil then
|
if evt ~= nil then
|
||||||
local parts = evt:split(":")
|
local parts = evt:split(":")
|
||||||
if #parts == 2 then
|
if #parts == 2 then
|
||||||
|
@ -596,8 +488,8 @@ function multicraft.explode_textlist_event(evt)
|
||||||
end
|
end
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
function multicraft.explode_scrollbar_event(evt)
|
function core.explode_scrollbar_event(evt)
|
||||||
local retval = multicraft.explode_textlist_event(evt)
|
local retval = core.explode_textlist_event(evt)
|
||||||
|
|
||||||
retval.value = retval.index
|
retval.value = retval.index
|
||||||
retval.index = nil
|
retval.index = nil
|
||||||
|
@ -606,7 +498,7 @@ function multicraft.explode_scrollbar_event(evt)
|
||||||
end
|
end
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
function multicraft.pos_to_string(pos, decimal_places)
|
function core.pos_to_string(pos, decimal_places)
|
||||||
local x = pos.x
|
local x = pos.x
|
||||||
local y = pos.y
|
local y = pos.y
|
||||||
local z = pos.z
|
local z = pos.z
|
||||||
|
@ -619,7 +511,7 @@ function multicraft.pos_to_string(pos, decimal_places)
|
||||||
end
|
end
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
function multicraft.string_to_pos(value)
|
function core.string_to_pos(value)
|
||||||
if value == nil then
|
if value == nil then
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
@ -643,9 +535,9 @@ function multicraft.string_to_pos(value)
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
assert(multicraft.string_to_pos("10.0, 5, -2").x == 10)
|
assert(core.string_to_pos("10.0, 5, -2").x == 10)
|
||||||
assert(multicraft.string_to_pos("( 10.0, 5, -2)").z == -2)
|
assert(core.string_to_pos("( 10.0, 5, -2)").z == -2)
|
||||||
assert(multicraft.string_to_pos("asd, 5, -2)") == nil)
|
assert(core.string_to_pos("asd, 5, -2)") == nil)
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
function table.copy(t, seen)
|
function table.copy(t, seen)
|
||||||
|
@ -662,7 +554,7 @@ end
|
||||||
-- mainmenu only functions
|
-- mainmenu only functions
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
if INIT == "mainmenu" then
|
if INIT == "mainmenu" then
|
||||||
function multicraft.get_game(index)
|
function core.get_game(index)
|
||||||
local games = game.get_games()
|
local games = game.get_games()
|
||||||
|
|
||||||
if index > 0 and index <= #games then
|
if index > 0 and index <= #games then
|
||||||
|
@ -673,7 +565,7 @@ if INIT == "mainmenu" then
|
||||||
end
|
end
|
||||||
|
|
||||||
function fgettext_ne(text, ...)
|
function fgettext_ne(text, ...)
|
||||||
text = multicraft.gettext(text)
|
text = core.gettext(text)
|
||||||
local arg = {n=select('#', ...), ...}
|
local arg = {n=select('#', ...), ...}
|
||||||
if arg.n >= 1 then
|
if arg.n >= 1 then
|
||||||
-- Insert positional parameters ($1, $2, ...)
|
-- Insert positional parameters ($1, $2, ...)
|
||||||
|
@ -698,6 +590,7 @@ if INIT == "mainmenu" then
|
||||||
end
|
end
|
||||||
|
|
||||||
function fgettext(text, ...)
|
function fgettext(text, ...)
|
||||||
return multicraft.formspec_escape(fgettext_ne(text, ...))
|
return core.formspec_escape(fgettext_ne(text, ...))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
-- 2. Recursively dump the value into a string.
|
-- 2. Recursively dump the value into a string.
|
||||||
-- @param x Value to serialize (nil is allowed).
|
-- @param x Value to serialize (nil is allowed).
|
||||||
-- @return load()able string containing the value.
|
-- @return load()able string containing the value.
|
||||||
function multicraft.serialize(x)
|
function core.serialize(x)
|
||||||
local local_index = 1 -- Top index of the "_" local table in the dump
|
local local_index = 1 -- Top index of the "_" local table in the dump
|
||||||
-- table->nil/1/2 set of tables seen.
|
-- table->nil/1/2 set of tables seen.
|
||||||
-- nil = not seen, 1 = seen once, 2 = seen multiple times.
|
-- nil = not seen, 1 = seen once, 2 = seen multiple times.
|
||||||
|
@ -115,11 +115,20 @@ function multicraft.serialize(x)
|
||||||
function dump_val(x)
|
function dump_val(x)
|
||||||
local tp = type(x)
|
local tp = type(x)
|
||||||
if x == nil then return "nil"
|
if x == nil then return "nil"
|
||||||
elseif tp == "number" then return string.format("%d", x)
|
|
||||||
elseif tp == "string" then return string.format("%q", x)
|
elseif tp == "string" then return string.format("%q", x)
|
||||||
elseif tp == "boolean" then return x and "true" or "false"
|
elseif tp == "boolean" then return x and "true" or "false"
|
||||||
elseif tp == "function" then
|
elseif tp == "function" then
|
||||||
return string.format("loadstring(%q)", string.dump(x))
|
return string.format("loadstring(%q)", string.dump(x))
|
||||||
|
elseif tp == "number" then
|
||||||
|
-- Serialize integers with string.format to prevent
|
||||||
|
-- scientific notation, which doesn't preserve
|
||||||
|
-- precision and breaks things like node position
|
||||||
|
-- hashes. Serialize floats normally.
|
||||||
|
if math.floor(x) == x then
|
||||||
|
return string.format("%d", x)
|
||||||
|
else
|
||||||
|
return tostring(x)
|
||||||
|
end
|
||||||
elseif tp == "table" then
|
elseif tp == "table" then
|
||||||
local vals = {}
|
local vals = {}
|
||||||
local idx_dumped = {}
|
local idx_dumped = {}
|
||||||
|
@ -177,7 +186,7 @@ local safe_env = {
|
||||||
loadstring = function() end,
|
loadstring = function() end,
|
||||||
}
|
}
|
||||||
|
|
||||||
function multicraft.deserialize(str, safe)
|
function core.deserialize(str, safe)
|
||||||
if str:byte(1) == 0x1B then
|
if str:byte(1) == 0x1B then
|
||||||
return nil, "Bytecode prohibited"
|
return nil, "Bytecode prohibited"
|
||||||
end
|
end
|
||||||
|
@ -196,14 +205,14 @@ end
|
||||||
|
|
||||||
-- Unit tests
|
-- Unit tests
|
||||||
local test_in = {cat={sound="nyan", speed=400}, dog={sound="woof"}}
|
local test_in = {cat={sound="nyan", speed=400}, dog={sound="woof"}}
|
||||||
local test_out = multicraft.deserialize(multicraft.serialize(test_in))
|
local test_out = core.deserialize(core.serialize(test_in))
|
||||||
|
|
||||||
assert(test_in.cat.sound == test_out.cat.sound)
|
assert(test_in.cat.sound == test_out.cat.sound)
|
||||||
assert(test_in.cat.speed == test_out.cat.speed)
|
assert(test_in.cat.speed == test_out.cat.speed)
|
||||||
assert(test_in.dog.sound == test_out.dog.sound)
|
assert(test_in.dog.sound == test_out.dog.sound)
|
||||||
|
|
||||||
test_in = {escape_chars="\n\r\t\v\\\"\'", non_european="θשׁ٩∂"}
|
test_in = {escape_chars="\n\r\t\v\\\"\'", non_european="θשׁ٩∂"}
|
||||||
test_out = multicraft.deserialize(multicraft.serialize(test_in))
|
test_out = core.deserialize(core.serialize(test_in))
|
||||||
assert(test_in.escape_chars == test_out.escape_chars)
|
assert(test_in.escape_chars == test_out.escape_chars)
|
||||||
assert(test_in.non_european == test_out.non_european)
|
assert(test_in.non_european == test_out.non_european)
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,11 @@
|
||||||
local WARN_INIT = false
|
local WARN_INIT = false
|
||||||
|
|
||||||
|
|
||||||
|
function core.global_exists(name)
|
||||||
|
return rawget(_G, name) ~= nil
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
local function warn(message)
|
local function warn(message)
|
||||||
print(os.date("%H:%M:%S: WARNING: ")..message)
|
print(os.date("%H:%M:%S: WARNING: ")..message)
|
||||||
end
|
end
|
||||||
|
@ -30,8 +35,8 @@ function meta:__newindex(name, value)
|
||||||
declared[name] = true
|
declared[name] = true
|
||||||
end
|
end
|
||||||
-- Ignore mod namespaces
|
-- Ignore mod namespaces
|
||||||
if WARN_INIT and (not multicraft.get_current_modname or
|
if WARN_INIT and (not core.get_current_modname or
|
||||||
name ~= multicraft.get_current_modname()) then
|
name ~= core.get_current_modname()) then
|
||||||
warn(("Global variable %q created at %s.")
|
warn(("Global variable %q created at %s.")
|
||||||
:format(name, desc))
|
:format(name, desc))
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
--
|
--
|
||||||
--self program is free software; you can redistribute it and/or modify
|
--self program is free software; you can redistribute it and/or modify
|
||||||
--it under the terms of the GNU Lesser General Public License as published by
|
--it under the terms of the GNU Lesser General Public License as published by
|
||||||
--the Free Software Foundation; either version 3.0 of the License, or
|
--the Free Software Foundation; either version 2.1 of the License, or
|
||||||
--(at your option) any later version.
|
--(at your option) any later version.
|
||||||
--
|
--
|
||||||
--self program is distributed in the hope that it will be useful,
|
--self program is distributed in the hope that it will be useful,
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
--
|
--
|
||||||
--self program is free software; you can redistribute it and/or modify
|
--self program is free software; you can redistribute it and/or modify
|
||||||
--it under the terms of the GNU Lesser General Public License as published by
|
--it under the terms of the GNU Lesser General Public License as published by
|
||||||
--the Free Software Foundation; either version 3.0 of the License, or
|
--the Free Software Foundation; either version 2.1 of the License, or
|
||||||
--(at your option) any later version.
|
--(at your option) any later version.
|
||||||
--
|
--
|
||||||
--self program is distributed in the hope that it will be useful,
|
--self program is distributed in the hope that it will be useful,
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
--
|
--
|
||||||
--self program is free software; you can redistribute it and/or modify
|
--self program is free software; you can redistribute it and/or modify
|
||||||
--it under the terms of the GNU Lesser General Public License as published by
|
--it under the terms of the GNU Lesser General Public License as published by
|
||||||
--the Free Software Foundation; either version 3.0 of the License, or
|
--the Free Software Foundation; either version 2.1 of the License, or
|
||||||
--(at your option) any later version.
|
--(at your option) any later version.
|
||||||
--
|
--
|
||||||
--self program is distributed in the hope that it will be useful,
|
--self program is distributed in the hope that it will be useful,
|
||||||
|
@ -69,7 +69,7 @@ local function get_formspec(self)
|
||||||
string.format("size[%f,%f,%s]",tsize.width,tsize.height,
|
string.format("size[%f,%f,%s]",tsize.width,tsize.height,
|
||||||
dump(self.fixed_size))
|
dump(self.fixed_size))
|
||||||
end
|
end
|
||||||
--formspec = formspec .. self:tab_header()
|
formspec = formspec .. self:tab_header()
|
||||||
formspec = formspec ..
|
formspec = formspec ..
|
||||||
self.tablist[self.last_tab_index].get_formspec(
|
self.tablist[self.last_tab_index].get_formspec(
|
||||||
self,
|
self,
|
||||||
|
@ -167,7 +167,7 @@ local function switch_to_tab(self, index)
|
||||||
self.current_tab = self.tablist[index].name
|
self.current_tab = self.tablist[index].name
|
||||||
|
|
||||||
if (self.autosave_tab) then
|
if (self.autosave_tab) then
|
||||||
multicraft.setting_set(self.name .. "_LAST",self.current_tab)
|
core.setting_set(self.name .. "_LAST",self.current_tab)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- call for tab to enter
|
-- call for tab to enter
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
--
|
--
|
||||||
--self program is free software; you can redistribute it and/or modify
|
--self program is free software; you can redistribute it and/or modify
|
||||||
--it under the terms of the GNU Lesser General Public License as published by
|
--it under the terms of the GNU Lesser General Public License as published by
|
||||||
--the Free Software Foundation; either version 3.0 of the License, or
|
--the Free Software Foundation; either version 2.1 of the License, or
|
||||||
--(at your option) any later version.
|
--(at your option) any later version.
|
||||||
--
|
--
|
||||||
--self program is distributed in the hope that it will be useful,
|
--self program is distributed in the hope that it will be useful,
|
||||||
|
@ -62,7 +62,7 @@ function ui.update()
|
||||||
if gamedata ~= nil and gamedata.errormessage ~= nil then
|
if gamedata ~= nil and gamedata.errormessage ~= nil then
|
||||||
formspec = "size[12,3.2]" ..
|
formspec = "size[12,3.2]" ..
|
||||||
"textarea[1,1;10,2;;ERROR: " ..
|
"textarea[1,1;10,2;;ERROR: " ..
|
||||||
multicraft.formspec_escape(gamedata.errormessage) ..
|
core.formspec_escape(gamedata.errormessage) ..
|
||||||
";]"..
|
";]"..
|
||||||
"button[4.5,2.5;3,0.5;btn_error_confirm;" .. fgettext("Ok") .. "]"
|
"button[4.5,2.5;3,0.5;btn_error_confirm;" .. fgettext("Ok") .. "]"
|
||||||
else
|
else
|
||||||
|
@ -101,7 +101,7 @@ function ui.update()
|
||||||
formspec = ui.childlist[ui.default]:get_formspec()
|
formspec = ui.childlist[ui.default]:get_formspec()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
multicraft.update_formspec(formspec)
|
core.update_formspec(formspec)
|
||||||
end
|
end
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
@ -109,7 +109,7 @@ function ui.handle_buttons(fields)
|
||||||
|
|
||||||
if fields["btn_error_confirm"] then
|
if fields["btn_error_confirm"] then
|
||||||
gamedata.errormessage = nil
|
gamedata.errormessage = nil
|
||||||
menu.update()
|
update_menu()
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -145,7 +145,7 @@ end
|
||||||
-- initialize callbacks
|
-- initialize callbacks
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
multicraft.button_handler = function(fields)
|
core.button_handler = function(fields)
|
||||||
if fields["btn_error_confirm"] then
|
if fields["btn_error_confirm"] then
|
||||||
gamedata.errormessage = nil
|
gamedata.errormessage = nil
|
||||||
ui.update()
|
ui.update()
|
||||||
|
@ -158,7 +158,7 @@ multicraft.button_handler = function(fields)
|
||||||
end
|
end
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
multicraft.event_handler = function(event)
|
core.event_handler = function(event)
|
||||||
if ui.handle_events(event) then
|
if ui.handle_events(event) then
|
||||||
ui.update()
|
ui.update()
|
||||||
return
|
return
|
||||||
|
|
|
@ -4,8 +4,8 @@
|
||||||
-- Authentication handler
|
-- Authentication handler
|
||||||
--
|
--
|
||||||
|
|
||||||
function multicraft.string_to_privs(str, delim)
|
function core.string_to_privs(str, delim)
|
||||||
if type(str) ~= "string" then return end
|
assert(type(str) == "string")
|
||||||
delim = delim or ','
|
delim = delim or ','
|
||||||
local privs = {}
|
local privs = {}
|
||||||
for _, priv in pairs(string.split(str, delim)) do
|
for _, priv in pairs(string.split(str, delim)) do
|
||||||
|
@ -14,7 +14,7 @@ function multicraft.string_to_privs(str, delim)
|
||||||
return privs
|
return privs
|
||||||
end
|
end
|
||||||
|
|
||||||
function multicraft.privs_to_string(privs, delim)
|
function core.privs_to_string(privs, delim)
|
||||||
assert(type(privs) == "table")
|
assert(type(privs) == "table")
|
||||||
delim = delim or ','
|
delim = delim or ','
|
||||||
local list = {}
|
local list = {}
|
||||||
|
@ -26,34 +26,17 @@ function multicraft.privs_to_string(privs, delim)
|
||||||
return table.concat(list, delim)
|
return table.concat(list, delim)
|
||||||
end
|
end
|
||||||
|
|
||||||
assert(multicraft.string_to_privs("a,b").b == true)
|
assert(core.string_to_privs("a,b").b == true)
|
||||||
assert(multicraft.privs_to_string({a=true,b=true}) == "a,b")
|
assert(core.privs_to_string({a=true,b=true}) == "a,b")
|
||||||
|
|
||||||
multicraft.auth_file_path = multicraft.get_worldpath().."/auth.txt"
|
core.auth_file_path = core.get_worldpath().."/auth.txt"
|
||||||
multicraft.auth_table = {}
|
core.auth_table = {}
|
||||||
|
|
||||||
local hex={}
|
|
||||||
for i=0,255 do
|
|
||||||
hex[string.format("%0x",i)]=string.char(i)
|
|
||||||
hex[string.format("%0X",i)]=string.char(i)
|
|
||||||
end
|
|
||||||
|
|
||||||
local function uri_decode(str)
|
|
||||||
str = string.gsub (str, "+", " ")
|
|
||||||
return (str:gsub('%%(%x%x)',hex))
|
|
||||||
end
|
|
||||||
|
|
||||||
function uri_encode (str)
|
|
||||||
str = string.gsub (str, "([^0-9a-zA-Z_ -])", function (c) return string.format ("%%%02X", string.byte(c)) end)
|
|
||||||
str = string.gsub (str, " ", "+")
|
|
||||||
return str
|
|
||||||
end
|
|
||||||
|
|
||||||
local function read_auth_file()
|
local function read_auth_file()
|
||||||
local newtable = {}
|
local newtable = {}
|
||||||
local file, errmsg = io.open(multicraft.auth_file_path, 'rb')
|
local file, errmsg = io.open(core.auth_file_path, 'rb')
|
||||||
if not file then
|
if not file then
|
||||||
multicraft.log("info", multicraft.auth_file_path.." could not be opened for reading ("..errmsg.."); assuming new world")
|
core.log("info", core.auth_file_path.." could not be opened for reading ("..errmsg.."); assuming new world")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
for line in file:lines() do
|
for line in file:lines() do
|
||||||
|
@ -64,19 +47,19 @@ local function read_auth_file()
|
||||||
if not (name and password and privilege_string) then
|
if not (name and password and privilege_string) then
|
||||||
error("Invalid line in auth.txt: "..dump(line))
|
error("Invalid line in auth.txt: "..dump(line))
|
||||||
end
|
end
|
||||||
local privileges = multicraft.string_to_privs(privilege_string)
|
local privileges = core.string_to_privs(privilege_string)
|
||||||
newtable[uri_decode(name)] = {password=password, privileges=privileges, last_login=last_login}
|
newtable[name] = {password=password, privileges=privileges, last_login=last_login}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
io.close(file)
|
io.close(file)
|
||||||
multicraft.auth_table = newtable
|
core.auth_table = newtable
|
||||||
multicraft.notify_authentication_modified()
|
core.notify_authentication_modified()
|
||||||
end
|
end
|
||||||
|
|
||||||
local function save_auth_file()
|
local function save_auth_file()
|
||||||
local newtable = {}
|
local newtable = {}
|
||||||
-- Check table for validness before attempting to save
|
-- Check table for validness before attempting to save
|
||||||
for name, stuff in pairs(multicraft.auth_table) do
|
for name, stuff in pairs(core.auth_table) do
|
||||||
assert(type(name) == "string")
|
assert(type(name) == "string")
|
||||||
assert(name ~= "")
|
assert(name ~= "")
|
||||||
assert(type(stuff) == "table")
|
assert(type(stuff) == "table")
|
||||||
|
@ -84,13 +67,13 @@ local function save_auth_file()
|
||||||
assert(type(stuff.privileges) == "table")
|
assert(type(stuff.privileges) == "table")
|
||||||
assert(stuff.last_login == nil or type(stuff.last_login) == "number")
|
assert(stuff.last_login == nil or type(stuff.last_login) == "number")
|
||||||
end
|
end
|
||||||
local file, errmsg = io.open(multicraft.auth_file_path, 'w+b')
|
local file, errmsg = io.open(core.auth_file_path, 'w+b')
|
||||||
if not file then
|
if not file then
|
||||||
error(multicraft.auth_file_path.." could not be opened for writing: "..errmsg)
|
error(core.auth_file_path.." could not be opened for writing: "..errmsg)
|
||||||
end
|
end
|
||||||
for name, stuff in pairs(multicraft.auth_table) do
|
for name, stuff in pairs(core.auth_table) do
|
||||||
local priv_string = multicraft.privs_to_string(stuff.privileges)
|
local priv_string = core.privs_to_string(stuff.privileges)
|
||||||
local parts = {uri_encode(name), stuff.password, priv_string, stuff.last_login or ""}
|
local parts = {name, stuff.password, priv_string, stuff.last_login or ""}
|
||||||
file:write(table.concat(parts, ":").."\n")
|
file:write(table.concat(parts, ":").."\n")
|
||||||
end
|
end
|
||||||
io.close(file)
|
io.close(file)
|
||||||
|
@ -98,7 +81,7 @@ end
|
||||||
|
|
||||||
read_auth_file()
|
read_auth_file()
|
||||||
|
|
||||||
multicraft.builtin_auth_handler = {
|
core.builtin_auth_handler = {
|
||||||
get_auth = function(name)
|
get_auth = function(name)
|
||||||
assert(type(name) == "string")
|
assert(type(name) == "string")
|
||||||
-- Figure out what password to use for a new player (singleplayer
|
-- Figure out what password to use for a new player (singleplayer
|
||||||
|
@ -106,47 +89,43 @@ multicraft.builtin_auth_handler = {
|
||||||
-- usually empty too)
|
-- usually empty too)
|
||||||
local new_password_hash = ""
|
local new_password_hash = ""
|
||||||
-- If not in authentication table, return nil
|
-- If not in authentication table, return nil
|
||||||
if not multicraft.auth_table[name] then
|
if not core.auth_table[name] then
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
-- Figure out what privileges the player should have.
|
-- Figure out what privileges the player should have.
|
||||||
-- Take a copy of the privilege table
|
-- Take a copy of the privilege table
|
||||||
local privileges = {}
|
local privileges = {}
|
||||||
for priv, _ in pairs(multicraft.auth_table[name].privileges) do
|
for priv, _ in pairs(core.auth_table[name].privileges) do
|
||||||
privileges[priv] = true
|
privileges[priv] = true
|
||||||
end
|
end
|
||||||
-- If singleplayer, give all privileges except those marked as give_to_singleplayer = false
|
-- If singleplayer, give all privileges except those marked as give_to_singleplayer = false
|
||||||
if multicraft.is_singleplayer() then
|
if core.is_singleplayer() then
|
||||||
for priv, def in pairs(multicraft.registered_privileges) do
|
for priv, def in pairs(core.registered_privileges) do
|
||||||
if def.give_to_singleplayer then
|
if def.give_to_singleplayer then
|
||||||
privileges[priv] = true
|
privileges[priv] = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
-- For the admin, give everything
|
-- For the admin, give everything
|
||||||
elseif name == multicraft.setting_get("name") then
|
elseif name == core.setting_get("name") then
|
||||||
for priv, def in pairs(multicraft.registered_privileges) do
|
for priv, def in pairs(core.registered_privileges) do
|
||||||
privileges[priv] = true
|
privileges[priv] = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
-- All done
|
-- All done
|
||||||
return {
|
return {
|
||||||
password = multicraft.auth_table[name].password,
|
password = core.auth_table[name].password,
|
||||||
privileges = privileges,
|
privileges = privileges,
|
||||||
-- Is set to nil if unknown
|
-- Is set to nil if unknown
|
||||||
last_login = multicraft.auth_table[name].last_login,
|
last_login = core.auth_table[name].last_login,
|
||||||
}
|
}
|
||||||
end,
|
end,
|
||||||
create_auth = function(name, password)
|
create_auth = function(name, password)
|
||||||
assert(type(name) == "string")
|
assert(type(name) == "string")
|
||||||
assert(type(password) == "string")
|
assert(type(password) == "string")
|
||||||
multicraft.log('info', "Built-in authentication handler adding player '"..name.."'")
|
core.log('info', "Built-in authentication handler adding player '"..name.."'")
|
||||||
local privs = multicraft.setting_get("default_privs")
|
core.auth_table[name] = {
|
||||||
if multicraft.setting_getbool("creative_mode") and multicraft.setting_get("default_privs_creative") then
|
|
||||||
privs = multicraft.setting_get("default_privs_creative")
|
|
||||||
end
|
|
||||||
multicraft.auth_table[name] = {
|
|
||||||
password = password,
|
password = password,
|
||||||
privileges = multicraft.string_to_privs(privs),
|
privileges = core.string_to_privs(core.setting_get("default_privs")),
|
||||||
last_login = os.time(),
|
last_login = os.time(),
|
||||||
}
|
}
|
||||||
save_auth_file()
|
save_auth_file()
|
||||||
|
@ -154,11 +133,11 @@ multicraft.builtin_auth_handler = {
|
||||||
set_password = function(name, password)
|
set_password = function(name, password)
|
||||||
assert(type(name) == "string")
|
assert(type(name) == "string")
|
||||||
assert(type(password) == "string")
|
assert(type(password) == "string")
|
||||||
if not multicraft.auth_table[name] then
|
if not core.auth_table[name] then
|
||||||
multicraft.builtin_auth_handler.create_auth(name, password)
|
core.builtin_auth_handler.create_auth(name, password)
|
||||||
else
|
else
|
||||||
multicraft.log('info', "Built-in authentication handler setting password of player '"..name.."'")
|
core.log('info', "Built-in authentication handler setting password of player '"..name.."'")
|
||||||
multicraft.auth_table[name].password = password
|
core.auth_table[name].password = password
|
||||||
save_auth_file()
|
save_auth_file()
|
||||||
end
|
end
|
||||||
return true
|
return true
|
||||||
|
@ -166,13 +145,13 @@ multicraft.builtin_auth_handler = {
|
||||||
set_privileges = function(name, privileges)
|
set_privileges = function(name, privileges)
|
||||||
assert(type(name) == "string")
|
assert(type(name) == "string")
|
||||||
assert(type(privileges) == "table")
|
assert(type(privileges) == "table")
|
||||||
if not multicraft.auth_table[name] then
|
if not core.auth_table[name] then
|
||||||
multicraft.builtin_auth_handler.create_auth(name,
|
core.builtin_auth_handler.create_auth(name,
|
||||||
multicraft.get_password_hash(name,
|
core.get_password_hash(name,
|
||||||
multicraft.setting_get("default_password")))
|
core.setting_get("default_password")))
|
||||||
end
|
end
|
||||||
multicraft.auth_table[name].privileges = privileges
|
core.auth_table[name].privileges = privileges
|
||||||
multicraft.notify_authentication_modified(name)
|
core.notify_authentication_modified(name)
|
||||||
save_auth_file()
|
save_auth_file()
|
||||||
end,
|
end,
|
||||||
reload = function()
|
reload = function()
|
||||||
|
@ -181,26 +160,26 @@ multicraft.builtin_auth_handler = {
|
||||||
end,
|
end,
|
||||||
record_login = function(name)
|
record_login = function(name)
|
||||||
assert(type(name) == "string")
|
assert(type(name) == "string")
|
||||||
assert(multicraft.auth_table[name]).last_login = os.time()
|
assert(core.auth_table[name]).last_login = os.time()
|
||||||
save_auth_file()
|
save_auth_file()
|
||||||
end,
|
end,
|
||||||
}
|
}
|
||||||
|
|
||||||
function multicraft.register_authentication_handler(handler)
|
function core.register_authentication_handler(handler)
|
||||||
if multicraft.registered_auth_handler then
|
if core.registered_auth_handler then
|
||||||
error("Add-on authentication handler already registered by "..multicraft.registered_auth_handler_modname)
|
error("Add-on authentication handler already registered by "..core.registered_auth_handler_modname)
|
||||||
end
|
end
|
||||||
multicraft.registered_auth_handler = handler
|
core.registered_auth_handler = handler
|
||||||
multicraft.registered_auth_handler_modname = multicraft.get_current_modname()
|
core.registered_auth_handler_modname = core.get_current_modname()
|
||||||
end
|
end
|
||||||
|
|
||||||
function multicraft.get_auth_handler()
|
function core.get_auth_handler()
|
||||||
return multicraft.registered_auth_handler or multicraft.builtin_auth_handler
|
return core.registered_auth_handler or core.builtin_auth_handler
|
||||||
end
|
end
|
||||||
|
|
||||||
local function auth_pass(name)
|
local function auth_pass(name)
|
||||||
return function(...)
|
return function(...)
|
||||||
local auth_handler = multicraft.get_auth_handler()
|
local auth_handler = core.get_auth_handler()
|
||||||
if auth_handler[name] then
|
if auth_handler[name] then
|
||||||
return auth_handler[name](...)
|
return auth_handler[name](...)
|
||||||
end
|
end
|
||||||
|
@ -208,14 +187,14 @@ local function auth_pass(name)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
multicraft.set_player_password = auth_pass("set_password")
|
core.set_player_password = auth_pass("set_password")
|
||||||
multicraft.set_player_privs = auth_pass("set_privileges")
|
core.set_player_privs = auth_pass("set_privileges")
|
||||||
multicraft.auth_reload = auth_pass("reload")
|
core.auth_reload = auth_pass("reload")
|
||||||
|
|
||||||
|
|
||||||
local record_login = auth_pass("record_login")
|
local record_login = auth_pass("record_login")
|
||||||
|
|
||||||
multicraft.register_on_joinplayer(function(player)
|
core.register_on_joinplayer(function(player)
|
||||||
record_login(player:get_player_name())
|
record_login(player:get_player_name())
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|
|
@ -4,19 +4,19 @@
|
||||||
-- Chat command handler
|
-- Chat command handler
|
||||||
--
|
--
|
||||||
|
|
||||||
multicraft.chatcommands = {}
|
core.chatcommands = {}
|
||||||
function multicraft.register_chatcommand(cmd, def)
|
function core.register_chatcommand(cmd, def)
|
||||||
def = def or {}
|
def = def or {}
|
||||||
def.params = def.params or ""
|
def.params = def.params or ""
|
||||||
def.description = def.description or ""
|
def.description = def.description or ""
|
||||||
def.privs = def.privs or {}
|
def.privs = def.privs or {}
|
||||||
multicraft.chatcommands[cmd] = def
|
core.chatcommands[cmd] = def
|
||||||
end
|
end
|
||||||
|
|
||||||
if multicraft.setting_getbool("mod_profiling") then
|
if core.setting_getbool("mod_profiling") then
|
||||||
local tracefct = profiling_print_log
|
local tracefct = profiling_print_log
|
||||||
profiling_print_log = nil
|
profiling_print_log = nil
|
||||||
multicraft.register_chatcommand("save_mod_profile",
|
core.register_chatcommand("save_mod_profile",
|
||||||
{
|
{
|
||||||
params = "",
|
params = "",
|
||||||
description = "save mod profiling data to logfile " ..
|
description = "save mod profiling data to logfile " ..
|
||||||
|
@ -26,23 +26,23 @@ if multicraft.setting_getbool("mod_profiling") then
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
multicraft.register_on_chat_message(function(name, message)
|
core.register_on_chat_message(function(name, message)
|
||||||
local cmd, param = string.match(message, "^/([^ ]+) *(.*)")
|
local cmd, param = string.match(message, "^/([^ ]+) *(.*)")
|
||||||
if not param then
|
if not param then
|
||||||
param = ""
|
param = ""
|
||||||
end
|
end
|
||||||
local cmd_def = multicraft.chatcommands[cmd]
|
local cmd_def = core.chatcommands[cmd]
|
||||||
if not cmd_def then
|
if not cmd_def then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
local has_privs, missing_privs = multicraft.check_player_privs(name, cmd_def.privs)
|
local has_privs, missing_privs = core.check_player_privs(name, cmd_def.privs)
|
||||||
if has_privs then
|
if has_privs then
|
||||||
local success, message = cmd_def.func(name, param)
|
local success, message = cmd_def.func(name, param)
|
||||||
if message then
|
if message then
|
||||||
multicraft.chat_send_player(name, message)
|
core.chat_send_player(name, message)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
multicraft.chat_send_player(name, "You don't have permission"
|
core.chat_send_player(name, "You don't have permission"
|
||||||
.. " to run this command (missing privileges: "
|
.. " to run this command (missing privileges: "
|
||||||
.. table.concat(missing_privs, ", ") .. ")")
|
.. table.concat(missing_privs, ", ") .. ")")
|
||||||
end
|
end
|
||||||
|
@ -52,22 +52,22 @@ end)
|
||||||
--
|
--
|
||||||
-- Chat commands
|
-- Chat commands
|
||||||
--
|
--
|
||||||
multicraft.register_chatcommand("me", {
|
core.register_chatcommand("me", {
|
||||||
params = "<action>",
|
params = "<action>",
|
||||||
description = "chat action (eg. /me orders a pizza)",
|
description = "chat action (eg. /me orders a pizza)",
|
||||||
privs = {shout=true},
|
privs = {shout=true},
|
||||||
func = function(name, param)
|
func = function(name, param)
|
||||||
multicraft.chat_send_all("* " .. name .. " " .. param)
|
core.chat_send_all("* " .. name .. " " .. param)
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
multicraft.register_chatcommand("help", {
|
core.register_chatcommand("help", {
|
||||||
privs = {},
|
privs = {},
|
||||||
params = "[all/privs/<cmd>]",
|
params = "[all/privs/<cmd>]",
|
||||||
description = "Get help for commands or list privileges",
|
description = "Get help for commands or list privileges",
|
||||||
func = function(name, param)
|
func = function(name, param)
|
||||||
local function format_help_line(cmd, def)
|
local function format_help_line(cmd, def)
|
||||||
local msg = cmd
|
local msg = "/"..cmd
|
||||||
if def.params and def.params ~= "" then
|
if def.params and def.params ~= "" then
|
||||||
msg = msg .. " " .. def.params
|
msg = msg .. " " .. def.params
|
||||||
end
|
end
|
||||||
|
@ -79,8 +79,8 @@ multicraft.register_chatcommand("help", {
|
||||||
if param == "" then
|
if param == "" then
|
||||||
local msg = ""
|
local msg = ""
|
||||||
local cmds = {}
|
local cmds = {}
|
||||||
for cmd, def in pairs(multicraft.chatcommands) do
|
for cmd, def in pairs(core.chatcommands) do
|
||||||
if multicraft.check_player_privs(name, def.privs) then
|
if core.check_player_privs(name, def.privs) then
|
||||||
table.insert(cmds, cmd)
|
table.insert(cmds, cmd)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -90,8 +90,8 @@ multicraft.register_chatcommand("help", {
|
||||||
.. " or '/help all' to list everything."
|
.. " or '/help all' to list everything."
|
||||||
elseif param == "all" then
|
elseif param == "all" then
|
||||||
local cmds = {}
|
local cmds = {}
|
||||||
for cmd, def in pairs(multicraft.chatcommands) do
|
for cmd, def in pairs(core.chatcommands) do
|
||||||
if multicraft.check_player_privs(name, def.privs) then
|
if core.check_player_privs(name, def.privs) then
|
||||||
table.insert(cmds, format_help_line(cmd, def))
|
table.insert(cmds, format_help_line(cmd, def))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -99,14 +99,14 @@ multicraft.register_chatcommand("help", {
|
||||||
return true, "Available commands:\n"..table.concat(cmds, "\n")
|
return true, "Available commands:\n"..table.concat(cmds, "\n")
|
||||||
elseif param == "privs" then
|
elseif param == "privs" then
|
||||||
local privs = {}
|
local privs = {}
|
||||||
for priv, def in pairs(multicraft.registered_privileges) do
|
for priv, def in pairs(core.registered_privileges) do
|
||||||
table.insert(privs, priv .. ": " .. def.description)
|
table.insert(privs, priv .. ": " .. def.description)
|
||||||
end
|
end
|
||||||
table.sort(privs)
|
table.sort(privs)
|
||||||
return true, "Available privileges:\n"..table.concat(privs, "\n")
|
return true, "Available privileges:\n"..table.concat(privs, "\n")
|
||||||
else
|
else
|
||||||
local cmd = param
|
local cmd = param
|
||||||
local def = multicraft.chatcommands[cmd]
|
local def = core.chatcommands[cmd]
|
||||||
if not def then
|
if not def then
|
||||||
return false, "Command not available: "..cmd
|
return false, "Command not available: "..cmd
|
||||||
else
|
else
|
||||||
|
@ -116,42 +116,42 @@ multicraft.register_chatcommand("help", {
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
multicraft.register_chatcommand("privs", {
|
core.register_chatcommand("privs", {
|
||||||
params = "<name>",
|
params = "<name>",
|
||||||
description = "print out privileges of player",
|
description = "print out privileges of player",
|
||||||
func = function(name, param)
|
func = function(name, param)
|
||||||
param = (param ~= "" and param or name)
|
param = (param ~= "" and param or name)
|
||||||
return true, "Privileges of " .. param .. ": "
|
return true, "Privileges of " .. param .. ": "
|
||||||
.. multicraft.privs_to_string(
|
.. core.privs_to_string(
|
||||||
multicraft.get_player_privs(param), ' ')
|
core.get_player_privs(param), ' ')
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
multicraft.register_chatcommand("grant", {
|
core.register_chatcommand("grant", {
|
||||||
params = "<name> <privilege>|all",
|
params = "<name> <privilege>|all",
|
||||||
description = "Give privilege to player",
|
description = "Give privilege to player",
|
||||||
func = function(name, param)
|
func = function(name, param)
|
||||||
if not multicraft.check_player_privs(name, {privs=true}) and
|
if not core.check_player_privs(name, {privs=true}) and
|
||||||
not multicraft.check_player_privs(name, {basic_privs=true}) then
|
not core.check_player_privs(name, {basic_privs=true}) then
|
||||||
return false, "Your privileges are insufficient."
|
return false, "Your privileges are insufficient."
|
||||||
end
|
end
|
||||||
local grantname, grantprivstr = string.match(param, "([^ ]+) (.+)")
|
local grantname, grantprivstr = string.match(param, "([^ ]+) (.+)")
|
||||||
if not grantname or not grantprivstr then
|
if not grantname or not grantprivstr then
|
||||||
return false, "Invalid parameters (see /help grant)"
|
return false, "Invalid parameters (see /help grant)"
|
||||||
elseif not multicraft.auth_table[grantname] then
|
elseif not core.auth_table[grantname] then
|
||||||
return false, "Player " .. grantname .. " does not exist."
|
return false, "Player " .. grantname .. " does not exist."
|
||||||
end
|
end
|
||||||
local grantprivs = multicraft.string_to_privs(grantprivstr)
|
local grantprivs = core.string_to_privs(grantprivstr)
|
||||||
if grantprivstr == "all" then
|
if grantprivstr == "all" then
|
||||||
grantprivs = multicraft.registered_privileges
|
grantprivs = core.registered_privileges
|
||||||
end
|
end
|
||||||
local privs = multicraft.get_player_privs(grantname)
|
local privs = core.get_player_privs(grantname)
|
||||||
local privs_unknown = ""
|
local privs_unknown = ""
|
||||||
for priv, _ in pairs(grantprivs) do
|
for priv, _ in pairs(grantprivs) do
|
||||||
if priv ~= "interact" and priv ~= "shout" and
|
if priv ~= "interact" and priv ~= "shout" and
|
||||||
not multicraft.check_player_privs(name, {privs=true}) then
|
not core.check_player_privs(name, {privs=true}) then
|
||||||
return false, "Your privileges are insufficient."
|
return false, "Your privileges are insufficient."
|
||||||
end
|
end
|
||||||
if not multicraft.registered_privileges[priv] then
|
if not core.registered_privileges[priv] then
|
||||||
privs_unknown = privs_unknown .. "Unknown privilege: " .. priv .. "\n"
|
privs_unknown = privs_unknown .. "Unknown privilege: " .. priv .. "\n"
|
||||||
end
|
end
|
||||||
privs[priv] = true
|
privs[priv] = true
|
||||||
|
@ -159,38 +159,38 @@ multicraft.register_chatcommand("grant", {
|
||||||
if privs_unknown ~= "" then
|
if privs_unknown ~= "" then
|
||||||
return false, privs_unknown
|
return false, privs_unknown
|
||||||
end
|
end
|
||||||
multicraft.set_player_privs(grantname, privs)
|
core.set_player_privs(grantname, privs)
|
||||||
multicraft.log("action", name..' granted ('..multicraft.privs_to_string(grantprivs, ', ')..') privileges to '..grantname)
|
core.log("action", name..' granted ('..core.privs_to_string(grantprivs, ', ')..') privileges to '..grantname)
|
||||||
if grantname ~= name then
|
if grantname ~= name then
|
||||||
multicraft.chat_send_player(grantname, name
|
core.chat_send_player(grantname, name
|
||||||
.. " granted you privileges: "
|
.. " granted you privileges: "
|
||||||
.. multicraft.privs_to_string(grantprivs, ' '))
|
.. core.privs_to_string(grantprivs, ' '))
|
||||||
end
|
end
|
||||||
return true, "Privileges of " .. grantname .. ": "
|
return true, "Privileges of " .. grantname .. ": "
|
||||||
.. multicraft.privs_to_string(
|
.. core.privs_to_string(
|
||||||
multicraft.get_player_privs(grantname), ' ')
|
core.get_player_privs(grantname), ' ')
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
multicraft.register_chatcommand("revoke", {
|
core.register_chatcommand("revoke", {
|
||||||
params = "<name> <privilege>|all",
|
params = "<name> <privilege>|all",
|
||||||
description = "Remove privilege from player",
|
description = "Remove privilege from player",
|
||||||
privs = {},
|
privs = {},
|
||||||
func = function(name, param)
|
func = function(name, param)
|
||||||
if not multicraft.check_player_privs(name, {privs=true}) and
|
if not core.check_player_privs(name, {privs=true}) and
|
||||||
not multicraft.check_player_privs(name, {basic_privs=true}) then
|
not core.check_player_privs(name, {basic_privs=true}) then
|
||||||
return false, "Your privileges are insufficient."
|
return false, "Your privileges are insufficient."
|
||||||
end
|
end
|
||||||
local revoke_name, revoke_priv_str = string.match(param, "([^ ]+) (.+)")
|
local revoke_name, revoke_priv_str = string.match(param, "([^ ]+) (.+)")
|
||||||
if not revoke_name or not revoke_priv_str then
|
if not revoke_name or not revoke_priv_str then
|
||||||
return false, "Invalid parameters (see /help revoke)"
|
return false, "Invalid parameters (see /help revoke)"
|
||||||
elseif not multicraft.auth_table[revoke_name] then
|
elseif not core.auth_table[revoke_name] then
|
||||||
return false, "Player " .. revoke_name .. " does not exist."
|
return false, "Player " .. revoke_name .. " does not exist."
|
||||||
end
|
end
|
||||||
local revoke_privs = multicraft.string_to_privs(revoke_priv_str)
|
local revoke_privs = core.string_to_privs(revoke_priv_str)
|
||||||
local privs = multicraft.get_player_privs(revoke_name)
|
local privs = core.get_player_privs(revoke_name)
|
||||||
for priv, _ in pairs(revoke_privs) do
|
for priv, _ in pairs(revoke_privs) do
|
||||||
if priv ~= "interact" and priv ~= "shout" and priv ~= "interact_extra" and
|
if priv ~= "interact" and priv ~= "shout" and priv ~= "interact_extra" and
|
||||||
not multicraft.check_player_privs(name, {privs=true}) then
|
not core.check_player_privs(name, {privs=true}) then
|
||||||
return false, "Your privileges are insufficient."
|
return false, "Your privileges are insufficient."
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -201,22 +201,22 @@ multicraft.register_chatcommand("revoke", {
|
||||||
privs[priv] = nil
|
privs[priv] = nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
multicraft.set_player_privs(revoke_name, privs)
|
core.set_player_privs(revoke_name, privs)
|
||||||
multicraft.log("action", name..' revoked ('
|
core.log("action", name..' revoked ('
|
||||||
..multicraft.privs_to_string(revoke_privs, ', ')
|
..core.privs_to_string(revoke_privs, ', ')
|
||||||
..') privileges from '..revoke_name)
|
..') privileges from '..revoke_name)
|
||||||
if revoke_name ~= name then
|
if revoke_name ~= name then
|
||||||
multicraft.chat_send_player(revoke_name, name
|
core.chat_send_player(revoke_name, name
|
||||||
.. " revoked privileges from you: "
|
.. " revoked privileges from you: "
|
||||||
.. multicraft.privs_to_string(revoke_privs, ' '))
|
.. core.privs_to_string(revoke_privs, ' '))
|
||||||
end
|
end
|
||||||
return true, "Privileges of " .. revoke_name .. ": "
|
return true, "Privileges of " .. revoke_name .. ": "
|
||||||
.. multicraft.privs_to_string(
|
.. core.privs_to_string(
|
||||||
multicraft.get_player_privs(revoke_name), ' ')
|
core.get_player_privs(revoke_name), ' ')
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
multicraft.register_chatcommand("setpassword", {
|
core.register_chatcommand("setpassword", {
|
||||||
params = "<name> <password>",
|
params = "<name> <password>",
|
||||||
description = "set given password",
|
description = "set given password",
|
||||||
privs = {password=true},
|
privs = {password=true},
|
||||||
|
@ -229,25 +229,32 @@ multicraft.register_chatcommand("setpassword", {
|
||||||
if not toname then
|
if not toname then
|
||||||
return false, "Name field required"
|
return false, "Name field required"
|
||||||
end
|
end
|
||||||
local actstr = "?"
|
local act_str_past = "?"
|
||||||
|
local act_str_pres = "?"
|
||||||
if not raw_password then
|
if not raw_password then
|
||||||
multicraft.set_player_password(toname, "")
|
core.set_player_password(toname, "")
|
||||||
actstr = "cleared"
|
act_str_past = "cleared"
|
||||||
|
act_str_pres = "clears"
|
||||||
else
|
else
|
||||||
multicraft.set_player_password(toname,
|
core.set_player_password(toname,
|
||||||
multicraft.get_password_hash(toname,
|
core.get_password_hash(toname,
|
||||||
raw_password))
|
raw_password))
|
||||||
actstr = "set"
|
act_str_past = "set"
|
||||||
|
act_str_pres = "sets"
|
||||||
end
|
end
|
||||||
if toname ~= name then
|
if toname ~= name then
|
||||||
multicraft.chat_send_player(toname, "Your password was "
|
core.chat_send_player(toname, "Your password was "
|
||||||
.. actstr .. " by " .. name)
|
.. act_str_past .. " by " .. name)
|
||||||
end
|
end
|
||||||
return true, "Password of player \"" .. toname .. "\" " .. actstr
|
|
||||||
|
core.log("action", name .. " " .. act_str_pres
|
||||||
|
.. " password of " .. toname .. ".")
|
||||||
|
|
||||||
|
return true, "Password of player \"" .. toname .. "\" " .. act_str_past
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
multicraft.register_chatcommand("clearpassword", {
|
core.register_chatcommand("clearpassword", {
|
||||||
params = "<name>",
|
params = "<name>",
|
||||||
description = "set empty password",
|
description = "set empty password",
|
||||||
privs = {password=true},
|
privs = {password=true},
|
||||||
|
@ -256,22 +263,25 @@ multicraft.register_chatcommand("clearpassword", {
|
||||||
if toname == "" then
|
if toname == "" then
|
||||||
return false, "Name field required"
|
return false, "Name field required"
|
||||||
end
|
end
|
||||||
multicraft.set_player_password(toname, '')
|
core.set_player_password(toname, '')
|
||||||
|
|
||||||
|
core.log("action", name .. " clears password of " .. toname .. ".")
|
||||||
|
|
||||||
return true, "Password of player \"" .. toname .. "\" cleared"
|
return true, "Password of player \"" .. toname .. "\" cleared"
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
multicraft.register_chatcommand("auth_reload", {
|
core.register_chatcommand("auth_reload", {
|
||||||
params = "",
|
params = "",
|
||||||
description = "reload authentication data",
|
description = "reload authentication data",
|
||||||
privs = {server=true},
|
privs = {server=true},
|
||||||
func = function(name, param)
|
func = function(name, param)
|
||||||
local done = multicraft.auth_reload()
|
local done = core.auth_reload()
|
||||||
return done, (done and "Done." or "Failed.")
|
return done, (done and "Done." or "Failed.")
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
multicraft.register_chatcommand("teleport", {
|
core.register_chatcommand("teleport", {
|
||||||
params = "<X>,<Y>,<Z> | <to_name> | <name> <X>,<Y>,<Z> | <name> <to_name>",
|
params = "<X>,<Y>,<Z> | <to_name> | <name> <X>,<Y>,<Z> | <name> <to_name>",
|
||||||
description = "teleport to given position",
|
description = "teleport to given position",
|
||||||
privs = {teleport=true},
|
privs = {teleport=true},
|
||||||
|
@ -286,9 +296,9 @@ multicraft.register_chatcommand("teleport", {
|
||||||
}
|
}
|
||||||
for _, d in ipairs(tries) do
|
for _, d in ipairs(tries) do
|
||||||
local p = {x = pos.x+d.x, y = pos.y+d.y, z = pos.z+d.z}
|
local p = {x = pos.x+d.x, y = pos.y+d.y, z = pos.z+d.z}
|
||||||
local n = multicraft.get_node_or_nil(p)
|
local n = core.get_node_or_nil(p)
|
||||||
if n and n.name then
|
if n and n.name then
|
||||||
local def = multicraft.registered_nodes[n.name]
|
local def = core.registered_nodes[n.name]
|
||||||
if def and not def.walkable then
|
if def and not def.walkable then
|
||||||
return p, true
|
return p, true
|
||||||
end
|
end
|
||||||
|
@ -303,19 +313,19 @@ multicraft.register_chatcommand("teleport", {
|
||||||
p.x = tonumber(p.x)
|
p.x = tonumber(p.x)
|
||||||
p.y = tonumber(p.y)
|
p.y = tonumber(p.y)
|
||||||
p.z = tonumber(p.z)
|
p.z = tonumber(p.z)
|
||||||
teleportee = multicraft.get_player_by_name(name)
|
teleportee = core.get_player_by_name(name)
|
||||||
if teleportee and p.x and p.y and p.z then
|
if teleportee and p.x and p.y and p.z then
|
||||||
teleportee:setpos(p)
|
teleportee:setpos(p)
|
||||||
return true, "Teleporting to "..multicraft.pos_to_string(p)
|
return true, "Teleporting to "..core.pos_to_string(p)
|
||||||
end
|
end
|
||||||
|
|
||||||
local teleportee = nil
|
local teleportee = nil
|
||||||
local p = nil
|
local p = nil
|
||||||
local target_name = nil
|
local target_name = nil
|
||||||
target_name = param:match("^([^ ]+)$")
|
target_name = param:match("^([^ ]+)$")
|
||||||
teleportee = multicraft.get_player_by_name(name)
|
teleportee = core.get_player_by_name(name)
|
||||||
if target_name then
|
if target_name then
|
||||||
local target = multicraft.get_player_by_name(target_name)
|
local target = core.get_player_by_name(target_name)
|
||||||
if target then
|
if target then
|
||||||
p = target:getpos()
|
p = target:getpos()
|
||||||
end
|
end
|
||||||
|
@ -324,10 +334,10 @@ multicraft.register_chatcommand("teleport", {
|
||||||
p = find_free_position_near(p)
|
p = find_free_position_near(p)
|
||||||
teleportee:setpos(p)
|
teleportee:setpos(p)
|
||||||
return true, "Teleporting to " .. target_name
|
return true, "Teleporting to " .. target_name
|
||||||
.. " at "..multicraft.pos_to_string(p)
|
.. " at "..core.pos_to_string(p)
|
||||||
end
|
end
|
||||||
|
|
||||||
if not multicraft.check_player_privs(name, {bring=true}) then
|
if not core.check_player_privs(name, {bring=true}) then
|
||||||
return false, "You don't have permission to teleport other players (missing bring privilege)"
|
return false, "You don't have permission to teleport other players (missing bring privilege)"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -338,12 +348,12 @@ multicraft.register_chatcommand("teleport", {
|
||||||
"^([^ ]+) +([%d.-]+)[, ] *([%d.-]+)[, ] *([%d.-]+)$")
|
"^([^ ]+) +([%d.-]+)[, ] *([%d.-]+)[, ] *([%d.-]+)$")
|
||||||
p.x, p.y, p.z = tonumber(p.x), tonumber(p.y), tonumber(p.z)
|
p.x, p.y, p.z = tonumber(p.x), tonumber(p.y), tonumber(p.z)
|
||||||
if teleportee_name then
|
if teleportee_name then
|
||||||
teleportee = multicraft.get_player_by_name(teleportee_name)
|
teleportee = core.get_player_by_name(teleportee_name)
|
||||||
end
|
end
|
||||||
if teleportee and p.x and p.y and p.z then
|
if teleportee and p.x and p.y and p.z then
|
||||||
teleportee:setpos(p)
|
teleportee:setpos(p)
|
||||||
return true, "Teleporting " .. teleportee_name
|
return true, "Teleporting " .. teleportee_name
|
||||||
.. " to " .. multicraft.pos_to_string(p)
|
.. " to " .. core.pos_to_string(p)
|
||||||
end
|
end
|
||||||
|
|
||||||
local teleportee = nil
|
local teleportee = nil
|
||||||
|
@ -352,10 +362,10 @@ multicraft.register_chatcommand("teleport", {
|
||||||
local target_name = nil
|
local target_name = nil
|
||||||
teleportee_name, target_name = string.match(param, "^([^ ]+) +([^ ]+)$")
|
teleportee_name, target_name = string.match(param, "^([^ ]+) +([^ ]+)$")
|
||||||
if teleportee_name then
|
if teleportee_name then
|
||||||
teleportee = multicraft.get_player_by_name(teleportee_name)
|
teleportee = core.get_player_by_name(teleportee_name)
|
||||||
end
|
end
|
||||||
if target_name then
|
if target_name then
|
||||||
local target = multicraft.get_player_by_name(target_name)
|
local target = core.get_player_by_name(target_name)
|
||||||
if target then
|
if target then
|
||||||
p = target:getpos()
|
p = target:getpos()
|
||||||
end
|
end
|
||||||
|
@ -365,7 +375,7 @@ multicraft.register_chatcommand("teleport", {
|
||||||
teleportee:setpos(p)
|
teleportee:setpos(p)
|
||||||
return true, "Teleporting " .. teleportee_name
|
return true, "Teleporting " .. teleportee_name
|
||||||
.. " to " .. target_name
|
.. " to " .. target_name
|
||||||
.. " at " .. multicraft.pos_to_string(p)
|
.. " at " .. core.pos_to_string(p)
|
||||||
end
|
end
|
||||||
|
|
||||||
return false, 'Invalid parameters ("' .. param
|
return false, 'Invalid parameters ("' .. param
|
||||||
|
@ -373,27 +383,27 @@ multicraft.register_chatcommand("teleport", {
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
multicraft.register_chatcommand("set", {
|
core.register_chatcommand("set", {
|
||||||
params = "[-n] <name> <value> | <name>",
|
params = "[-n] <name> <value> | <name>",
|
||||||
description = "set or read server configuration setting",
|
description = "set or read server configuration setting",
|
||||||
privs = {server=true},
|
privs = {server=true},
|
||||||
func = function(name, param)
|
func = function(name, param)
|
||||||
local arg, setname, setvalue = string.match(param, "(-[n]) ([^ ]+) (.+)")
|
local arg, setname, setvalue = string.match(param, "(-[n]) ([^ ]+) (.+)")
|
||||||
if arg and arg == "-n" and setname and setvalue then
|
if arg and arg == "-n" and setname and setvalue then
|
||||||
multicraft.setting_set(setname, setvalue)
|
core.setting_set(setname, setvalue)
|
||||||
return true, setname .. " = " .. setvalue
|
return true, setname .. " = " .. setvalue
|
||||||
end
|
end
|
||||||
local setname, setvalue = string.match(param, "([^ ]+) (.+)")
|
local setname, setvalue = string.match(param, "([^ ]+) (.+)")
|
||||||
if setname and setvalue then
|
if setname and setvalue then
|
||||||
if not multicraft.setting_get(setname) then
|
if not core.setting_get(setname) then
|
||||||
return false, "Failed. Use '/set -n <name> <value>' to create a new setting."
|
return false, "Failed. Use '/set -n <name> <value>' to create a new setting."
|
||||||
end
|
end
|
||||||
multicraft.setting_set(setname, setvalue)
|
core.setting_set(setname, setvalue)
|
||||||
return true, setname .. " = " .. setvalue
|
return true, setname .. " = " .. setvalue
|
||||||
end
|
end
|
||||||
local setname = string.match(param, "([^ ]+)")
|
local setname = string.match(param, "([^ ]+)")
|
||||||
if setname then
|
if setname then
|
||||||
local setvalue = multicraft.setting_get(setname)
|
local setvalue = core.setting_get(setname)
|
||||||
if not setvalue then
|
if not setvalue then
|
||||||
setvalue = "<not set>"
|
setvalue = "<not set>"
|
||||||
end
|
end
|
||||||
|
@ -403,55 +413,62 @@ multicraft.register_chatcommand("set", {
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
multicraft.register_chatcommand("deleteblocks", {
|
core.register_chatcommand("deleteblocks", {
|
||||||
params = "[here] [<pos1> <pos2>]",
|
params = "(here [radius]) | (<pos1> <pos2>)",
|
||||||
description = "delete map blocks contained in area pos1 to pos2",
|
description = "delete map blocks contained in area pos1 to pos2",
|
||||||
privs = {server=true},
|
privs = {server=true},
|
||||||
func = function(name, param)
|
func = function(name, param)
|
||||||
local p1 = {}
|
local p1 = {}
|
||||||
local p2 = {}
|
local p2 = {}
|
||||||
if param == "here" then
|
local args = param:split(" ")
|
||||||
local player = multicraft.get_player_by_name(name)
|
if args[1] == "here" then
|
||||||
|
local player = core.get_player_by_name(name)
|
||||||
if player == nil then
|
if player == nil then
|
||||||
multicraft.log("error", "player is nil")
|
core.log("error", "player is nil")
|
||||||
return false, "Unable to get current position; player is nil"
|
return false, "Unable to get current position; player is nil"
|
||||||
end
|
end
|
||||||
p1 = player:getpos()
|
p1 = player:getpos()
|
||||||
p2 = p1
|
p2 = p1
|
||||||
|
|
||||||
|
if #args >= 2 then
|
||||||
|
local radius = tonumber(args[2]) or 0
|
||||||
|
p1 = vector.add(p1, radius)
|
||||||
|
p2 = vector.subtract(p2, radius)
|
||||||
|
end
|
||||||
else
|
else
|
||||||
local pos1, pos2 = unpack(param:split(") ("))
|
local pos1, pos2 = unpack(param:split(") ("))
|
||||||
if pos1 == nil or pos2 == nil then
|
if pos1 == nil or pos2 == nil then
|
||||||
return false, "Incorrect area format. Expected: (x1,y1,z1) (x2,y2,z2)"
|
return false, "Incorrect area format. Expected: (x1,y1,z1) (x2,y2,z2)"
|
||||||
end
|
end
|
||||||
|
|
||||||
p1 = multicraft.string_to_pos(pos1 .. ")")
|
p1 = core.string_to_pos(pos1 .. ")")
|
||||||
p2 = multicraft.string_to_pos("(" .. pos2)
|
p2 = core.string_to_pos("(" .. pos2)
|
||||||
|
|
||||||
if p1 == nil or p2 == nil then
|
if p1 == nil or p2 == nil then
|
||||||
return false, "Incorrect area format. Expected: (x1,y1,z1) (x2,y2,z2)"
|
return false, "Incorrect area format. Expected: (x1,y1,z1) (x2,y2,z2)"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if multicraft.delete_area(p1, p2) then
|
if core.delete_area(p1, p2) then
|
||||||
return true, "Successfully cleared area ranging from " ..
|
return true, "Successfully cleared area ranging from " ..
|
||||||
multicraft.pos_to_string(p1, 1) .. " to " .. multicraft.pos_to_string(p2, 1)
|
core.pos_to_string(p1, 1) .. " to " .. core.pos_to_string(p2, 1)
|
||||||
else
|
else
|
||||||
return false, "Failed to clear one or more blocks in area"
|
return false, "Failed to clear one or more blocks in area"
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
multicraft.register_chatcommand("mods", {
|
core.register_chatcommand("mods", {
|
||||||
params = "",
|
params = "",
|
||||||
description = "List mods installed on the server",
|
description = "List mods installed on the server",
|
||||||
privs = {},
|
privs = {},
|
||||||
func = function(name, param)
|
func = function(name, param)
|
||||||
return true, table.concat(multicraft.get_modnames(), ", ")
|
return true, table.concat(core.get_modnames(), ", ")
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
local function handle_give_command(cmd, giver, receiver, stackstring)
|
local function handle_give_command(cmd, giver, receiver, stackstring)
|
||||||
multicraft.log("action", giver .. " invoked " .. cmd
|
core.log("action", giver .. " invoked " .. cmd
|
||||||
.. ', stackstring="' .. stackstring .. '"')
|
.. ', stackstring="' .. stackstring .. '"')
|
||||||
local itemstack = ItemStack(stackstring)
|
local itemstack = ItemStack(stackstring)
|
||||||
if itemstack:is_empty() then
|
if itemstack:is_empty() then
|
||||||
|
@ -459,7 +476,7 @@ local function handle_give_command(cmd, giver, receiver, stackstring)
|
||||||
elseif not itemstack:is_known() then
|
elseif not itemstack:is_known() then
|
||||||
return false, "Cannot give an unknown item"
|
return false, "Cannot give an unknown item"
|
||||||
end
|
end
|
||||||
local receiverref = multicraft.get_player_by_name(receiver)
|
local receiverref = core.get_player_by_name(receiver)
|
||||||
if receiverref == nil then
|
if receiverref == nil then
|
||||||
return false, receiver .. " is not a known player"
|
return false, receiver .. " is not a known player"
|
||||||
end
|
end
|
||||||
|
@ -479,14 +496,14 @@ local function handle_give_command(cmd, giver, receiver, stackstring)
|
||||||
return true, ("%q %sadded to inventory.")
|
return true, ("%q %sadded to inventory.")
|
||||||
:format(stackstring, partiality)
|
:format(stackstring, partiality)
|
||||||
else
|
else
|
||||||
multicraft.chat_send_player(receiver, ("%q %sadded to inventory.")
|
core.chat_send_player(receiver, ("%q %sadded to inventory.")
|
||||||
:format(stackstring, partiality))
|
:format(stackstring, partiality))
|
||||||
return true, ("%q %sadded to %s's inventory.")
|
return true, ("%q %sadded to %s's inventory.")
|
||||||
:format(stackstring, partiality, receiver)
|
:format(stackstring, partiality, receiver)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
multicraft.register_chatcommand("give", {
|
core.register_chatcommand("give", {
|
||||||
params = "<name> <ItemString>",
|
params = "<name> <ItemString>",
|
||||||
description = "give item to player",
|
description = "give item to player",
|
||||||
privs = {give=true},
|
privs = {give=true},
|
||||||
|
@ -499,7 +516,7 @@ multicraft.register_chatcommand("give", {
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
multicraft.register_chatcommand("giveme", {
|
core.register_chatcommand("giveme", {
|
||||||
params = "<ItemString>",
|
params = "<ItemString>",
|
||||||
description = "give item to yourself",
|
description = "give item to yourself",
|
||||||
privs = {give=true},
|
privs = {give=true},
|
||||||
|
@ -512,7 +529,7 @@ multicraft.register_chatcommand("giveme", {
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
multicraft.register_chatcommand("spawnentity", {
|
core.register_chatcommand("spawnentity", {
|
||||||
params = "<EntityName>",
|
params = "<EntityName>",
|
||||||
description = "Spawn entity at your position",
|
description = "Spawn entity at your position",
|
||||||
privs = {give=true, interact=true},
|
privs = {give=true, interact=true},
|
||||||
|
@ -521,27 +538,27 @@ multicraft.register_chatcommand("spawnentity", {
|
||||||
if not entityname then
|
if not entityname then
|
||||||
return false, "EntityName required"
|
return false, "EntityName required"
|
||||||
end
|
end
|
||||||
multicraft.log("action", ("/spawnentity invoked, entityname=%q")
|
core.log("action", ("/spawnentity invoked, entityname=%q")
|
||||||
:format(entityname))
|
:format(entityname))
|
||||||
local player = multicraft.get_player_by_name(name)
|
local player = core.get_player_by_name(name)
|
||||||
if player == nil then
|
if player == nil then
|
||||||
multicraft.log("error", "Unable to spawn entity, player is nil")
|
core.log("error", "Unable to spawn entity, player is nil")
|
||||||
return false, "Unable to spawn entity, player is nil"
|
return false, "Unable to spawn entity, player is nil"
|
||||||
end
|
end
|
||||||
local p = player:getpos()
|
local p = player:getpos()
|
||||||
p.y = p.y + 1
|
p.y = p.y + 1
|
||||||
multicraft.add_entity(p, entityname)
|
core.add_entity(p, entityname)
|
||||||
return true, ("%q spawned."):format(entityname)
|
return true, ("%q spawned."):format(entityname)
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
multicraft.register_chatcommand("pulverize", {
|
core.register_chatcommand("pulverize", {
|
||||||
params = "",
|
params = "",
|
||||||
description = "Destroy item in hand",
|
description = "Destroy item in hand",
|
||||||
func = function(name, param)
|
func = function(name, param)
|
||||||
local player = multicraft.get_player_by_name(name)
|
local player = core.get_player_by_name(name)
|
||||||
if not player then
|
if not player then
|
||||||
multicraft.log("error", "Unable to pulverize, no player.")
|
core.log("error", "Unable to pulverize, no player.")
|
||||||
return false, "Unable to pulverize, no player."
|
return false, "Unable to pulverize, no player."
|
||||||
end
|
end
|
||||||
if player:get_wielded_item():is_empty() then
|
if player:get_wielded_item():is_empty() then
|
||||||
|
@ -553,24 +570,24 @@ multicraft.register_chatcommand("pulverize", {
|
||||||
})
|
})
|
||||||
|
|
||||||
-- Key = player name
|
-- Key = player name
|
||||||
multicraft.rollback_punch_callbacks = {}
|
core.rollback_punch_callbacks = {}
|
||||||
|
|
||||||
multicraft.register_on_punchnode(function(pos, node, puncher)
|
core.register_on_punchnode(function(pos, node, puncher)
|
||||||
local name = puncher:get_player_name()
|
local name = puncher:get_player_name()
|
||||||
if multicraft.rollback_punch_callbacks[name] then
|
if core.rollback_punch_callbacks[name] then
|
||||||
multicraft.rollback_punch_callbacks[name](pos, node, puncher)
|
core.rollback_punch_callbacks[name](pos, node, puncher)
|
||||||
multicraft.rollback_punch_callbacks[name] = nil
|
core.rollback_punch_callbacks[name] = nil
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
multicraft.register_chatcommand("rollback_check", {
|
core.register_chatcommand("rollback_check", {
|
||||||
params = "[<range>] [<seconds>] [limit]",
|
params = "[<range>] [<seconds>] [limit]",
|
||||||
description = "Check who has last touched a node or near it,"
|
description = "Check who has last touched a node or near it,"
|
||||||
.. " max. <seconds> ago (default range=0,"
|
.. " max. <seconds> ago (default range=0,"
|
||||||
.. " seconds=86400=24h, limit=5)",
|
.. " seconds=86400=24h, limit=5)",
|
||||||
privs = {rollback=true},
|
privs = {rollback=true},
|
||||||
func = function(name, param)
|
func = function(name, param)
|
||||||
if not multicraft.setting_getbool("enable_rollback_recording") then
|
if not core.setting_getbool("enable_rollback_recording") then
|
||||||
return false, "Rollback functions are disabled."
|
return false, "Rollback functions are disabled."
|
||||||
end
|
end
|
||||||
local range, seconds, limit =
|
local range, seconds, limit =
|
||||||
|
@ -582,17 +599,17 @@ multicraft.register_chatcommand("rollback_check", {
|
||||||
return false, "That limit is too high!"
|
return false, "That limit is too high!"
|
||||||
end
|
end
|
||||||
|
|
||||||
multicraft.rollback_punch_callbacks[name] = function(pos, node, puncher)
|
core.rollback_punch_callbacks[name] = function(pos, node, puncher)
|
||||||
local name = puncher:get_player_name()
|
local name = puncher:get_player_name()
|
||||||
multicraft.chat_send_player(name, "Checking " .. multicraft.pos_to_string(pos) .. "...")
|
core.chat_send_player(name, "Checking " .. core.pos_to_string(pos) .. "...")
|
||||||
local actions = multicraft.rollback_get_node_actions(pos, range, seconds, limit)
|
local actions = core.rollback_get_node_actions(pos, range, seconds, limit)
|
||||||
if not actions then
|
if not actions then
|
||||||
multicraft.chat_send_player(name, "Rollback functions are disabled")
|
core.chat_send_player(name, "Rollback functions are disabled")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local num_actions = #actions
|
local num_actions = #actions
|
||||||
if num_actions == 0 then
|
if num_actions == 0 then
|
||||||
multicraft.chat_send_player(name, "Nobody has touched"
|
core.chat_send_player(name, "Nobody has touched"
|
||||||
.. " the specified location in "
|
.. " the specified location in "
|
||||||
.. seconds .. " seconds")
|
.. seconds .. " seconds")
|
||||||
return
|
return
|
||||||
|
@ -600,10 +617,10 @@ multicraft.register_chatcommand("rollback_check", {
|
||||||
local time = os.time()
|
local time = os.time()
|
||||||
for i = num_actions, 1, -1 do
|
for i = num_actions, 1, -1 do
|
||||||
local action = actions[i]
|
local action = actions[i]
|
||||||
multicraft.chat_send_player(name,
|
core.chat_send_player(name,
|
||||||
("%s %s %s -> %s %d seconds ago.")
|
("%s %s %s -> %s %d seconds ago.")
|
||||||
:format(
|
:format(
|
||||||
multicraft.pos_to_string(action.pos),
|
core.pos_to_string(action.pos),
|
||||||
action.actor,
|
action.actor,
|
||||||
action.oldnode.name,
|
action.oldnode.name,
|
||||||
action.newnode.name,
|
action.newnode.name,
|
||||||
|
@ -616,12 +633,12 @@ multicraft.register_chatcommand("rollback_check", {
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
multicraft.register_chatcommand("rollback", {
|
core.register_chatcommand("rollback", {
|
||||||
params = "<player name> [<seconds>] | :<actor> [<seconds>]",
|
params = "<player name> [<seconds>] | :<actor> [<seconds>]",
|
||||||
description = "revert actions of a player; default for <seconds> is 60",
|
description = "revert actions of a player; default for <seconds> is 60",
|
||||||
privs = {rollback=true},
|
privs = {rollback=true},
|
||||||
func = function(name, param)
|
func = function(name, param)
|
||||||
if not multicraft.setting_getbool("enable_rollback_recording") then
|
if not core.setting_getbool("enable_rollback_recording") then
|
||||||
return false, "Rollback functions are disabled."
|
return false, "Rollback functions are disabled."
|
||||||
end
|
end
|
||||||
local target_name, seconds = string.match(param, ":([^ ]+) *(%d*)")
|
local target_name, seconds = string.match(param, ":([^ ]+) *(%d*)")
|
||||||
|
@ -635,10 +652,10 @@ multicraft.register_chatcommand("rollback", {
|
||||||
target_name = "player:"..player_name
|
target_name = "player:"..player_name
|
||||||
end
|
end
|
||||||
seconds = tonumber(seconds) or 60
|
seconds = tonumber(seconds) or 60
|
||||||
multicraft.chat_send_player(name, "Reverting actions of "
|
core.chat_send_player(name, "Reverting actions of "
|
||||||
.. target_name .. " since "
|
.. target_name .. " since "
|
||||||
.. seconds .. " seconds.")
|
.. seconds .. " seconds.")
|
||||||
local success, log = multicraft.rollback_revert_actions_by(
|
local success, log = core.rollback_revert_actions_by(
|
||||||
target_name, seconds)
|
target_name, seconds)
|
||||||
local response = ""
|
local response = ""
|
||||||
if #log > 100 then
|
if #log > 100 then
|
||||||
|
@ -654,25 +671,25 @@ multicraft.register_chatcommand("rollback", {
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
multicraft.register_chatcommand("status", {
|
core.register_chatcommand("status", {
|
||||||
description = "Print server status",
|
description = "Print server status",
|
||||||
func = function(name, param)
|
func = function(name, param)
|
||||||
return true, multicraft.get_server_status()
|
return true, core.get_server_status()
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
multicraft.register_chatcommand("time", {
|
core.register_chatcommand("time", {
|
||||||
params = "<0..23>:<0..59> | <0..24000>",
|
params = "<0..23>:<0..59> | <0..24000>",
|
||||||
description = "set time of day",
|
description = "set time of day",
|
||||||
privs = {},
|
privs = {},
|
||||||
func = function(name, param)
|
func = function(name, param)
|
||||||
if param == "" then
|
if param == "" then
|
||||||
local current_time = math.floor(multicraft.get_timeofday() * 1440)
|
local current_time = math.floor(core.get_timeofday() * 1440)
|
||||||
local minutes = current_time % 60
|
local minutes = current_time % 60
|
||||||
local hour = (current_time - minutes) / 60
|
local hour = (current_time - minutes) / 60
|
||||||
return true, ("Current time is %d:%02d"):format(hour, minutes)
|
return true, ("Current time is %d:%02d"):format(hour, minutes)
|
||||||
end
|
end
|
||||||
local player_privs = multicraft.get_player_privs(name)
|
local player_privs = minetest.get_player_privs(name)
|
||||||
if not player_privs.settime then
|
if not player_privs.settime then
|
||||||
return false, "You don't have permission to run this command " ..
|
return false, "You don't have permission to run this command " ..
|
||||||
"(missing privilege: settime)."
|
"(missing privilege: settime)."
|
||||||
|
@ -684,8 +701,8 @@ multicraft.register_chatcommand("time", {
|
||||||
return false, "Invalid time."
|
return false, "Invalid time."
|
||||||
end
|
end
|
||||||
-- Backward compatibility.
|
-- Backward compatibility.
|
||||||
multicraft.set_timeofday((new_time % 24000) / 24000)
|
core.set_timeofday((new_time % 24000) / 24000)
|
||||||
multicraft.log("action", name .. " sets time to " .. new_time)
|
core.log("action", name .. " sets time to " .. new_time)
|
||||||
return true, "Time of day changed."
|
return true, "Time of day changed."
|
||||||
end
|
end
|
||||||
hour = tonumber(hour)
|
hour = tonumber(hour)
|
||||||
|
@ -695,85 +712,89 @@ multicraft.register_chatcommand("time", {
|
||||||
elseif minute < 0 or minute > 59 then
|
elseif minute < 0 or minute > 59 then
|
||||||
return false, "Invalid minute (must be between 0 and 59 inclusive)."
|
return false, "Invalid minute (must be between 0 and 59 inclusive)."
|
||||||
end
|
end
|
||||||
multicraft.set_timeofday((hour * 60 + minute) / 1440)
|
core.set_timeofday((hour * 60 + minute) / 1440)
|
||||||
multicraft.log("action", name .. " sets time to " .. hour .. ":" .. minute)
|
core.log("action", name .. " sets time to " .. hour .. ":" .. minute)
|
||||||
return true, "Time of day changed."
|
return true, "Time of day changed."
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
multicraft.register_chatcommand("shutdown", {
|
core.register_chatcommand("shutdown", {
|
||||||
description = "shutdown server",
|
description = "shutdown server",
|
||||||
privs = {server=true},
|
privs = {server=true},
|
||||||
func = function(name, param)
|
func = function(name, param)
|
||||||
multicraft.log("action", name .. " shuts down server")
|
core.log("action", name .. " shuts down server")
|
||||||
multicraft.request_shutdown()
|
core.request_shutdown()
|
||||||
multicraft.chat_send_all("*** Server shutting down (operator request).")
|
core.chat_send_all("*** Server shutting down (operator request).")
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
multicraft.register_chatcommand("ban", {
|
core.register_chatcommand("ban", {
|
||||||
params = "<name>",
|
params = "<name>",
|
||||||
description = "Ban IP of player",
|
description = "Ban IP of player",
|
||||||
privs = {ban=true},
|
privs = {ban=true},
|
||||||
func = function(name, param)
|
func = function(name, param)
|
||||||
if param == "" then
|
if param == "" then
|
||||||
return true, "Ban list: " .. multicraft.get_ban_list()
|
return true, "Ban list: " .. core.get_ban_list()
|
||||||
end
|
end
|
||||||
if not multicraft.get_player_by_name(param) then
|
if not core.get_player_by_name(param) then
|
||||||
return false, "No such player."
|
return false, "No such player."
|
||||||
end
|
end
|
||||||
if not multicraft.ban_player(param) then
|
if not core.ban_player(param) then
|
||||||
return false, "Failed to ban player."
|
return false, "Failed to ban player."
|
||||||
end
|
end
|
||||||
local desc = multicraft.get_ban_description(param)
|
local desc = core.get_ban_description(param)
|
||||||
multicraft.log("action", name .. " bans " .. desc .. ".")
|
core.log("action", name .. " bans " .. desc .. ".")
|
||||||
return true, "Banned " .. desc .. "."
|
return true, "Banned " .. desc .. "."
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
multicraft.register_chatcommand("unban", {
|
core.register_chatcommand("unban", {
|
||||||
params = "<name/ip>",
|
params = "<name/ip>",
|
||||||
description = "remove IP ban",
|
description = "remove IP ban",
|
||||||
privs = {ban=true},
|
privs = {ban=true},
|
||||||
func = function(name, param)
|
func = function(name, param)
|
||||||
if not multicraft.unban_player_or_ip(param) then
|
if not core.unban_player_or_ip(param) then
|
||||||
return false, "Failed to unban player/IP."
|
return false, "Failed to unban player/IP."
|
||||||
end
|
end
|
||||||
multicraft.log("action", name .. " unbans " .. param)
|
core.log("action", name .. " unbans " .. param)
|
||||||
return true, "Unbanned " .. param
|
return true, "Unbanned " .. param
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
multicraft.register_chatcommand("kick", {
|
core.register_chatcommand("kick", {
|
||||||
params = "<name> [reason]",
|
params = "<name> [reason]",
|
||||||
description = "kick a player",
|
description = "kick a player",
|
||||||
privs = {kick=true},
|
privs = {kick=true},
|
||||||
func = function(name, param)
|
func = function(name, param)
|
||||||
local tokick, reason = param:match("([^ ]+) (.+)")
|
local tokick, reason = param:match("([^ ]+) (.+)")
|
||||||
tokick = tokick or param
|
tokick = tokick or param
|
||||||
if not multicraft.kick_player(tokick, reason) then
|
if not core.kick_player(tokick, reason) then
|
||||||
return false, "Failed to kick player " .. tokick
|
return false, "Failed to kick player " .. tokick
|
||||||
end
|
end
|
||||||
multicraft.log("action", name .. " kicked " .. tokick)
|
local log_reason = ""
|
||||||
|
if reason then
|
||||||
|
log_reason = " with reason \"" .. reason .. "\""
|
||||||
|
end
|
||||||
|
core.log("action", name .. " kicks " .. tokick .. log_reason)
|
||||||
return true, "Kicked " .. tokick
|
return true, "Kicked " .. tokick
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
multicraft.register_chatcommand("clearobjects", {
|
core.register_chatcommand("clearobjects", {
|
||||||
description = "clear all objects in world",
|
description = "clear all objects in world",
|
||||||
privs = {server=true},
|
privs = {server=true},
|
||||||
func = function(name, param)
|
func = function(name, param)
|
||||||
multicraft.log("action", name .. " clears all objects.")
|
core.log("action", name .. " clears all objects.")
|
||||||
multicraft.chat_send_all("Clearing all objects. This may take long."
|
core.chat_send_all("Clearing all objects. This may take long."
|
||||||
.. " You may experience a timeout. (by "
|
.. " You may experience a timeout. (by "
|
||||||
.. name .. ")")
|
.. name .. ")")
|
||||||
multicraft.clear_objects()
|
core.clear_objects()
|
||||||
multicraft.log("action", "Object clearing done.")
|
core.log("action", "Object clearing done.")
|
||||||
multicraft.chat_send_all("*** Cleared all objects.")
|
core.chat_send_all("*** Cleared all objects.")
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
multicraft.register_chatcommand("msg", {
|
core.register_chatcommand("msg", {
|
||||||
params = "<name> <message>",
|
params = "<name> <message>",
|
||||||
description = "Send a private message",
|
description = "Send a private message",
|
||||||
privs = {shout=true},
|
privs = {shout=true},
|
||||||
|
@ -782,38 +803,26 @@ multicraft.register_chatcommand("msg", {
|
||||||
if not sendto then
|
if not sendto then
|
||||||
return false, "Invalid usage, see /help msg."
|
return false, "Invalid usage, see /help msg."
|
||||||
end
|
end
|
||||||
if not multicraft.get_player_by_name(sendto) then
|
if not core.get_player_by_name(sendto) then
|
||||||
return false, "The player " .. sendto
|
return false, "The player " .. sendto
|
||||||
.. " is not online."
|
.. " is not online."
|
||||||
end
|
end
|
||||||
multicraft.log("action", "PM from " .. name .. " to " .. sendto
|
core.log("action", "PM from " .. name .. " to " .. sendto
|
||||||
.. ": " .. message)
|
.. ": " .. message)
|
||||||
multicraft.chat_send_player(sendto, "PM from " .. name .. ": "
|
core.chat_send_player(sendto, "PM from " .. name .. ": "
|
||||||
.. message)
|
.. message)
|
||||||
return true, "Message sent."
|
return true, "Message sent."
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
multicraft.register_chatcommand("die", {
|
core.register_chatcommand("last-login", {
|
||||||
params = "",
|
|
||||||
description = "Kills yourself.",
|
|
||||||
func = function(name, param)
|
|
||||||
local player = multicraft.get_player_by_name(name)
|
|
||||||
if not player then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
player:set_hp(0)
|
|
||||||
end,
|
|
||||||
})
|
|
||||||
|
|
||||||
multicraft.register_chatcommand("last-login", {
|
|
||||||
params = "[name]",
|
params = "[name]",
|
||||||
description = "Get the last login time of a player",
|
description = "Get the last login time of a player",
|
||||||
func = function(name, param)
|
func = function(name, param)
|
||||||
if param == "" then
|
if param == "" then
|
||||||
param = name
|
param = name
|
||||||
end
|
end
|
||||||
local pauth = multicraft.get_auth_handler().get_auth(param)
|
local pauth = core.get_auth_handler().get_auth(param)
|
||||||
if pauth and pauth.last_login then
|
if pauth and pauth.last_login then
|
||||||
-- Time in UTC, ISO 8601 format
|
-- Time in UTC, ISO 8601 format
|
||||||
return true, "Last login time was " ..
|
return true, "Last login time was " ..
|
||||||
|
@ -822,17 +831,3 @@ multicraft.register_chatcommand("last-login", {
|
||||||
return false, "Last login time is unknown"
|
return false, "Last login time is unknown"
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
multicraft.register_chatcommand( "stat", {
|
|
||||||
params = "[name]",
|
|
||||||
description = "show in-game action statistics",
|
|
||||||
func = function(name, param)
|
|
||||||
if param == "" then
|
|
||||||
param = name
|
|
||||||
elseif not multicraft.get_player_by_name(param) then
|
|
||||||
return false, "No such player."
|
|
||||||
end
|
|
||||||
local formspec = multicraft.stat_formspec(param)
|
|
||||||
multicraft.show_formspec(name, 'stat', formspec)
|
|
||||||
end
|
|
||||||
})
|
|
||||||
|
|
|
@ -4,35 +4,35 @@
|
||||||
-- Default material types
|
-- Default material types
|
||||||
--
|
--
|
||||||
function digprop_err()
|
function digprop_err()
|
||||||
multicraft.log("info", debug.traceback())
|
core.log("info", debug.traceback())
|
||||||
multicraft.log("info", "WARNING: The multicraft.digprop_* functions are obsolete and need to be replaced by item groups.")
|
core.log("info", "WARNING: The core.digprop_* functions are obsolete and need to be replaced by item groups.")
|
||||||
end
|
end
|
||||||
|
|
||||||
multicraft.digprop_constanttime = digprop_err
|
core.digprop_constanttime = digprop_err
|
||||||
multicraft.digprop_stonelike = digprop_err
|
core.digprop_stonelike = digprop_err
|
||||||
multicraft.digprop_dirtlike = digprop_err
|
core.digprop_dirtlike = digprop_err
|
||||||
multicraft.digprop_gravellike = digprop_err
|
core.digprop_gravellike = digprop_err
|
||||||
multicraft.digprop_woodlike = digprop_err
|
core.digprop_woodlike = digprop_err
|
||||||
multicraft.digprop_leaveslike = digprop_err
|
core.digprop_leaveslike = digprop_err
|
||||||
multicraft.digprop_glasslike = digprop_err
|
core.digprop_glasslike = digprop_err
|
||||||
|
|
||||||
multicraft.node_metadata_inventory_move_allow_all = function()
|
core.node_metadata_inventory_move_allow_all = function()
|
||||||
multicraft.log("info", "WARNING: multicraft.node_metadata_inventory_move_allow_all is obsolete and does nothing.")
|
core.log("info", "WARNING: core.node_metadata_inventory_move_allow_all is obsolete and does nothing.")
|
||||||
end
|
end
|
||||||
|
|
||||||
multicraft.add_to_creative_inventory = function(itemstring)
|
core.add_to_creative_inventory = function(itemstring)
|
||||||
multicraft.log('info', "WARNING: multicraft.add_to_creative_inventory: This function is deprecated and does nothing.")
|
core.log('info', "WARNING: core.add_to_creative_inventory: This function is deprecated and does nothing.")
|
||||||
end
|
end
|
||||||
|
|
||||||
--
|
--
|
||||||
-- EnvRef
|
-- EnvRef
|
||||||
--
|
--
|
||||||
multicraft.env = {}
|
core.env = {}
|
||||||
local envref_deprecation_message_printed = false
|
local envref_deprecation_message_printed = false
|
||||||
setmetatable(multicraft.env, {
|
setmetatable(core.env, {
|
||||||
__index = function(table, key)
|
__index = function(table, key)
|
||||||
if not envref_deprecation_message_printed then
|
if not envref_deprecation_message_printed then
|
||||||
multicraft.log("info", "WARNING: multicraft.env:[...] is deprecated and should be replaced with multicraft.[...]")
|
core.log("info", "WARNING: core.env:[...] is deprecated and should be replaced with core.[...]")
|
||||||
envref_deprecation_message_printed = true
|
envref_deprecation_message_printed = true
|
||||||
end
|
end
|
||||||
local func = core[key]
|
local func = core[key]
|
||||||
|
@ -47,7 +47,7 @@ setmetatable(multicraft.env, {
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
function multicraft.rollback_get_last_node_actor(pos, range, seconds)
|
function core.rollback_get_last_node_actor(pos, range, seconds)
|
||||||
return multicraft.rollback_get_node_actions(pos, range, seconds, 1)[1]
|
return core.rollback_get_node_actions(pos, range, seconds, 1)[1]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
-- Minetest: builtin/detached_inventory.lua
|
-- Minetest: builtin/detached_inventory.lua
|
||||||
|
|
||||||
multicraft.detached_inventories = {}
|
core.detached_inventories = {}
|
||||||
|
|
||||||
function multicraft.create_detached_inventory(name, callbacks)
|
function core.create_detached_inventory(name, callbacks)
|
||||||
local stuff = {}
|
local stuff = {}
|
||||||
stuff.name = name
|
stuff.name = name
|
||||||
if callbacks then
|
if callbacks then
|
||||||
|
@ -13,7 +13,7 @@ function multicraft.create_detached_inventory(name, callbacks)
|
||||||
stuff.on_put = callbacks.on_put
|
stuff.on_put = callbacks.on_put
|
||||||
stuff.on_take = callbacks.on_take
|
stuff.on_take = callbacks.on_take
|
||||||
end
|
end
|
||||||
multicraft.detached_inventories[name] = stuff
|
core.detached_inventories[name] = stuff
|
||||||
return multicraft.create_detached_inventory_raw(name)
|
return core.create_detached_inventory_raw(name)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -4,32 +4,7 @@
|
||||||
-- Falling stuff
|
-- Falling stuff
|
||||||
--
|
--
|
||||||
|
|
||||||
function node_drop(np, remove_fast)
|
core.register_entity(":__builtin:falling_node", {
|
||||||
local n2 = multicraft.get_node(np)
|
|
||||||
-- If it's not air or liquid, remove node and replace it with
|
|
||||||
-- it's drops
|
|
||||||
if n2.name ~= "air" and (not multicraft.registered_nodes[n2.name] or
|
|
||||||
multicraft.registered_nodes[n2.name].liquidtype == "none") then
|
|
||||||
multicraft.remove_node(np, remove_fast)
|
|
||||||
if multicraft.registered_nodes[n2.name].buildable_to == false then
|
|
||||||
-- Add dropped items
|
|
||||||
local drops = multicraft.get_node_drops(n2.name, "")
|
|
||||||
local _, dropped_item
|
|
||||||
for _, dropped_item in ipairs(drops) do
|
|
||||||
multicraft.add_item(np, dropped_item)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
-- Run script hook
|
|
||||||
local _, callback
|
|
||||||
for _, callback in ipairs(multicraft.registered_on_dignodes) do
|
|
||||||
callback(np, n2, nil)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local remove_fast = 0
|
|
||||||
|
|
||||||
multicraft.register_entity(":__builtin:falling_node", {
|
|
||||||
initial_properties = {
|
initial_properties = {
|
||||||
physical = true,
|
physical = true,
|
||||||
collide_with_objects = false,
|
collide_with_objects = false,
|
||||||
|
@ -51,9 +26,9 @@ multicraft.register_entity(":__builtin:falling_node", {
|
||||||
end
|
end
|
||||||
local item_texture = nil
|
local item_texture = nil
|
||||||
local item_type = ""
|
local item_type = ""
|
||||||
if multicraft.registered_items[itemname] then
|
if core.registered_items[itemname] then
|
||||||
item_texture = multicraft.registered_items[itemname].inventory_image
|
item_texture = core.registered_items[itemname].inventory_image
|
||||||
item_type = multicraft.registered_items[itemname].type
|
item_type = core.registered_items[itemname].type
|
||||||
end
|
end
|
||||||
local prop = {
|
local prop = {
|
||||||
is_visible = true,
|
is_visible = true,
|
||||||
|
@ -72,42 +47,58 @@ multicraft.register_entity(":__builtin:falling_node", {
|
||||||
end,
|
end,
|
||||||
|
|
||||||
on_step = function(self, dtime)
|
on_step = function(self, dtime)
|
||||||
if dtime > 0.2 then remove_fast = 2 else remove_fast = 0 end
|
|
||||||
-- Set gravity
|
-- Set gravity
|
||||||
self.object:setacceleration({x=0, y=-10, z=0})
|
self.object:setacceleration({x=0, y=-10, z=0})
|
||||||
-- Turn to actual sand when collides to ground or just move
|
-- Turn to actual sand when collides to ground or just move
|
||||||
local pos = self.object:getpos()
|
local pos = self.object:getpos()
|
||||||
local bcp = {x=pos.x, y=pos.y-0.7, z=pos.z} -- Position of bottom center point
|
local bcp = {x=pos.x, y=pos.y-0.7, z=pos.z} -- Position of bottom center point
|
||||||
local bcn = multicraft.get_node(bcp)
|
local bcn = core.get_node(bcp)
|
||||||
local bcd = multicraft.registered_nodes[bcn.name]
|
local bcd = core.registered_nodes[bcn.name]
|
||||||
-- Note: walkable is in the node definition, not in item groups
|
-- Note: walkable is in the node definition, not in item groups
|
||||||
if not bcd or
|
if not bcd or
|
||||||
(bcd.walkable or
|
(bcd.walkable or
|
||||||
(multicraft.get_item_group(self.node.name, "float") ~= 0 and
|
(core.get_item_group(self.node.name, "float") ~= 0 and
|
||||||
bcd.liquidtype ~= "none")) then
|
bcd.liquidtype ~= "none")) then
|
||||||
if bcd and bcd.leveled and bcd.leveled > 0 and
|
if bcd and bcd.leveled and
|
||||||
bcn.name == self.node.name then
|
bcn.name == self.node.name then
|
||||||
local addlevel = self.node.level
|
local addlevel = self.node.level
|
||||||
if addlevel == nil or addlevel <= 0 then
|
if addlevel == nil or addlevel <= 0 then
|
||||||
addlevel = bcd.leveled
|
addlevel = bcd.leveled
|
||||||
end
|
end
|
||||||
if multicraft.add_node_level(bcp, addlevel) == 0 then
|
if core.add_node_level(bcp, addlevel) == 0 then
|
||||||
self.object:remove()
|
self.object:remove()
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
elseif bcd and bcd.buildable_to and
|
elseif bcd and bcd.buildable_to and
|
||||||
(multicraft.get_item_group(self.node.name, "float") == 0 or
|
(core.get_item_group(self.node.name, "float") == 0 or
|
||||||
bcd.liquidtype == "none") then
|
bcd.liquidtype == "none") then
|
||||||
multicraft.remove_node(bcp, remove_fast)
|
core.remove_node(bcp)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local np = {x=bcp.x, y=bcp.y+1, z=bcp.z}
|
local np = {x=bcp.x, y=bcp.y+1, z=bcp.z}
|
||||||
-- Check what's here
|
-- Check what's here
|
||||||
local n2 = multicraft.get_node(np)
|
local n2 = core.get_node(np)
|
||||||
-- remove node and replace it with it's drops
|
-- If it's not air or liquid, remove node and replace it with
|
||||||
node_drop(np, remove_fast)
|
-- it's drops
|
||||||
|
if n2.name ~= "air" and (not core.registered_nodes[n2.name] or
|
||||||
|
core.registered_nodes[n2.name].liquidtype == "none") then
|
||||||
|
core.remove_node(np)
|
||||||
|
if core.registered_nodes[n2.name].buildable_to == false then
|
||||||
|
-- Add dropped items
|
||||||
|
local drops = core.get_node_drops(n2.name, "")
|
||||||
|
local _, dropped_item
|
||||||
|
for _, dropped_item in ipairs(drops) do
|
||||||
|
core.add_item(np, dropped_item)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
-- Run script hook
|
||||||
|
local _, callback
|
||||||
|
for _, callback in ipairs(core.registered_on_dignodes) do
|
||||||
|
callback(np, n2, nil)
|
||||||
|
end
|
||||||
|
end
|
||||||
-- Create node and remove entity
|
-- Create node and remove entity
|
||||||
multicraft.add_node(np, self.node)
|
core.add_node(np, self.node)
|
||||||
self.object:remove()
|
self.object:remove()
|
||||||
nodeupdate(np)
|
nodeupdate(np)
|
||||||
return
|
return
|
||||||
|
@ -121,26 +112,25 @@ multicraft.register_entity(":__builtin:falling_node", {
|
||||||
})
|
})
|
||||||
|
|
||||||
function spawn_falling_node(p, node)
|
function spawn_falling_node(p, node)
|
||||||
local obj = multicraft.add_entity(p, "__builtin:falling_node")
|
local obj = core.add_entity(p, "__builtin:falling_node")
|
||||||
if not obj then return end
|
|
||||||
obj:get_luaentity():set_node(node)
|
obj:get_luaentity():set_node(node)
|
||||||
end
|
end
|
||||||
|
|
||||||
function drop_attached_node(p)
|
function drop_attached_node(p)
|
||||||
local nn = multicraft.get_node(p).name
|
local nn = core.get_node(p).name
|
||||||
multicraft.remove_node(p, remove_fast)
|
core.remove_node(p)
|
||||||
for _,item in ipairs(multicraft.get_node_drops(nn, "")) do
|
for _,item in ipairs(core.get_node_drops(nn, "")) do
|
||||||
local pos = {
|
local pos = {
|
||||||
x = p.x + math.random()/2 - 0.25,
|
x = p.x + math.random()/2 - 0.25,
|
||||||
y = p.y + math.random()/2 - 0.25,
|
y = p.y + math.random()/2 - 0.25,
|
||||||
z = p.z + math.random()/2 - 0.25,
|
z = p.z + math.random()/2 - 0.25,
|
||||||
}
|
}
|
||||||
multicraft.add_item(pos, item)
|
core.add_item(pos, item)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function check_attached_node(p, n)
|
function check_attached_node(p, n)
|
||||||
local def = multicraft.registered_nodes[n.name]
|
local def = core.registered_nodes[n.name]
|
||||||
local d = {x=0, y=0, z=0}
|
local d = {x=0, y=0, z=0}
|
||||||
if def.paramtype2 == "wallmounted" then
|
if def.paramtype2 == "wallmounted" then
|
||||||
if n.param2 == 0 then
|
if n.param2 == 0 then
|
||||||
|
@ -160,8 +150,8 @@ function check_attached_node(p, n)
|
||||||
d.y = -1
|
d.y = -1
|
||||||
end
|
end
|
||||||
local p2 = {x=p.x+d.x, y=p.y+d.y, z=p.z+d.z}
|
local p2 = {x=p.x+d.x, y=p.y+d.y, z=p.z+d.z}
|
||||||
local nn = multicraft.get_node(p2).name
|
local nn = core.get_node(p2).name
|
||||||
local def2 = multicraft.registered_nodes[nn]
|
local def2 = core.registered_nodes[nn]
|
||||||
if def2 and not def2.walkable then
|
if def2 and not def2.walkable then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
@ -173,30 +163,30 @@ end
|
||||||
--
|
--
|
||||||
|
|
||||||
function nodeupdate_single(p, delay)
|
function nodeupdate_single(p, delay)
|
||||||
local n = multicraft.get_node(p)
|
local n = core.get_node(p)
|
||||||
if multicraft.get_item_group(n.name, "falling_node") ~= 0 then
|
if core.get_item_group(n.name, "falling_node") ~= 0 then
|
||||||
local p_bottom = {x=p.x, y=p.y-1, z=p.z}
|
local p_bottom = {x=p.x, y=p.y-1, z=p.z}
|
||||||
local n_bottom = multicraft.get_node(p_bottom)
|
local n_bottom = core.get_node(p_bottom)
|
||||||
-- Note: walkable is in the node definition, not in item groups
|
-- Note: walkable is in the node definition, not in item groups
|
||||||
if multicraft.registered_nodes[n_bottom.name] and
|
if core.registered_nodes[n_bottom.name] and
|
||||||
(multicraft.get_item_group(n.name, "float") == 0 or
|
(core.get_item_group(n.name, "float") == 0 or
|
||||||
multicraft.registered_nodes[n_bottom.name].liquidtype == "none") and
|
core.registered_nodes[n_bottom.name].liquidtype == "none") and
|
||||||
(n.name ~= n_bottom.name or (multicraft.registered_nodes[n_bottom.name].leveled and
|
(n.name ~= n_bottom.name or (core.registered_nodes[n_bottom.name].leveled and
|
||||||
multicraft.get_node_level(p_bottom) < multicraft.get_node_max_level(p_bottom))) and
|
core.get_node_level(p_bottom) < core.get_node_max_level(p_bottom))) and
|
||||||
(not multicraft.registered_nodes[n_bottom.name].walkable or
|
(not core.registered_nodes[n_bottom.name].walkable or
|
||||||
multicraft.registered_nodes[n_bottom.name].buildable_to) then
|
core.registered_nodes[n_bottom.name].buildable_to) then
|
||||||
if delay then
|
if delay then
|
||||||
multicraft.after(0.1, nodeupdate_single, {x=p.x, y=p.y, z=p.z}, false)
|
core.after(0.1, nodeupdate_single, {x=p.x, y=p.y, z=p.z}, false)
|
||||||
else
|
else
|
||||||
n.level = multicraft.get_node_level(p)
|
n.level = core.get_node_level(p)
|
||||||
multicraft.remove_node(p, remove_fast)
|
core.remove_node(p)
|
||||||
spawn_falling_node(p, n)
|
spawn_falling_node(p, n)
|
||||||
nodeupdate(p)
|
nodeupdate(p)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if multicraft.get_item_group(n.name, "attached_node") ~= 0 then
|
if core.get_item_group(n.name, "attached_node") ~= 0 then
|
||||||
if not check_attached_node(p, n) then
|
if not check_attached_node(p, n) then
|
||||||
drop_attached_node(p)
|
drop_attached_node(p)
|
||||||
nodeupdate(p)
|
nodeupdate(p)
|
||||||
|
@ -226,9 +216,9 @@ end
|
||||||
function on_placenode(p, node)
|
function on_placenode(p, node)
|
||||||
nodeupdate(p)
|
nodeupdate(p)
|
||||||
end
|
end
|
||||||
multicraft.register_on_placenode(on_placenode)
|
core.register_on_placenode(on_placenode)
|
||||||
|
|
||||||
function on_dignode(p, node)
|
function on_dignode(p, node)
|
||||||
nodeupdate(p)
|
nodeupdate(p)
|
||||||
end
|
end
|
||||||
multicraft.register_on_dignode(on_dignode)
|
core.register_on_dignode(on_dignode)
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
-- Prevent anyone else accessing those functions
|
-- Prevent anyone else accessing those functions
|
||||||
local forceload_block = multicraft.forceload_block
|
local forceload_block = core.forceload_block
|
||||||
local forceload_free_block = multicraft.forceload_free_block
|
local forceload_free_block = core.forceload_free_block
|
||||||
multicraft.forceload_block = nil
|
core.forceload_block = nil
|
||||||
multicraft.forceload_free_block = nil
|
core.forceload_free_block = nil
|
||||||
|
|
||||||
local blocks_forceloaded
|
local blocks_forceloaded
|
||||||
local total_forceloaded = 0
|
local total_forceloaded = 0
|
||||||
|
@ -15,14 +15,14 @@ local function get_blockpos(pos)
|
||||||
z = math.floor(pos.z/BLOCKSIZE)}
|
z = math.floor(pos.z/BLOCKSIZE)}
|
||||||
end
|
end
|
||||||
|
|
||||||
function multicraft.forceload_block(pos)
|
function core.forceload_block(pos)
|
||||||
local blockpos = get_blockpos(pos)
|
local blockpos = get_blockpos(pos)
|
||||||
local hash = multicraft.hash_node_position(blockpos)
|
local hash = core.hash_node_position(blockpos)
|
||||||
if blocks_forceloaded[hash] ~= nil then
|
if blocks_forceloaded[hash] ~= nil then
|
||||||
blocks_forceloaded[hash] = blocks_forceloaded[hash] + 1
|
blocks_forceloaded[hash] = blocks_forceloaded[hash] + 1
|
||||||
return true
|
return true
|
||||||
else
|
else
|
||||||
if total_forceloaded >= (tonumber(multicraft.setting_get("max_forceloaded_blocks")) or 16) then
|
if total_forceloaded >= (tonumber(core.setting_get("max_forceloaded_blocks")) or 16) then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
total_forceloaded = total_forceloaded+1
|
total_forceloaded = total_forceloaded+1
|
||||||
|
@ -32,9 +32,9 @@ function multicraft.forceload_block(pos)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function multicraft.forceload_free_block(pos)
|
function core.forceload_free_block(pos)
|
||||||
local blockpos = get_blockpos(pos)
|
local blockpos = get_blockpos(pos)
|
||||||
local hash = multicraft.hash_node_position(blockpos)
|
local hash = core.hash_node_position(blockpos)
|
||||||
if blocks_forceloaded[hash] == nil then return end
|
if blocks_forceloaded[hash] == nil then return end
|
||||||
if blocks_forceloaded[hash] > 1 then
|
if blocks_forceloaded[hash] > 1 then
|
||||||
blocks_forceloaded[hash] = blocks_forceloaded[hash] - 1
|
blocks_forceloaded[hash] = blocks_forceloaded[hash] - 1
|
||||||
|
@ -46,19 +46,19 @@ function multicraft.forceload_free_block(pos)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Keep the forceloaded areas after restart
|
-- Keep the forceloaded areas after restart
|
||||||
local wpath = multicraft.get_worldpath()
|
local wpath = core.get_worldpath()
|
||||||
local function read_file(filename)
|
local function read_file(filename)
|
||||||
local f = io.open(filename, "r")
|
local f = io.open(filename, "r")
|
||||||
if f==nil then return {} end
|
if f==nil then return {} end
|
||||||
local t = f:read("*all")
|
local t = f:read("*all")
|
||||||
f:close()
|
f:close()
|
||||||
if t=="" or t==nil then return {} end
|
if t=="" or t==nil then return {} end
|
||||||
return multicraft.deserialize(t) or {}
|
return core.deserialize(t) or {}
|
||||||
end
|
end
|
||||||
|
|
||||||
local function write_file(filename, table)
|
local function write_file(filename, table)
|
||||||
local f = io.open(filename, "w")
|
local f = io.open(filename, "w")
|
||||||
f:write(multicraft.serialize(table))
|
f:write(core.serialize(table))
|
||||||
f:close()
|
f:close()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -67,13 +67,13 @@ for _, __ in pairs(blocks_forceloaded) do
|
||||||
total_forceloaded = total_forceloaded + 1
|
total_forceloaded = total_forceloaded + 1
|
||||||
end
|
end
|
||||||
|
|
||||||
multicraft.after(5, function()
|
core.after(5, function()
|
||||||
for hash, _ in pairs(blocks_forceloaded) do
|
for hash, _ in pairs(blocks_forceloaded) do
|
||||||
local blockpos = multicraft.get_position_from_hash(hash)
|
local blockpos = core.get_position_from_hash(hash)
|
||||||
forceload_block(blockpos)
|
forceload_block(blockpos)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
multicraft.register_on_shutdown(function()
|
core.register_on_shutdown(function()
|
||||||
write_file(wpath.."/force_loaded.txt", blocks_forceloaded)
|
write_file(wpath.."/force_loaded.txt", blocks_forceloaded)
|
||||||
end)
|
end)
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
|
||||||
local scriptpath = multicraft.get_builtin_path()..DIR_DELIM
|
local scriptpath = minetest.get_builtin_path()..DIR_DELIM
|
||||||
local commonpath = scriptpath.."common"..DIR_DELIM
|
local commonpath = scriptpath.."common"..DIR_DELIM
|
||||||
local gamepath = scriptpath.."game"..DIR_DELIM
|
local gamepath = scriptpath.."game"..DIR_DELIM
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@ dofile(commonpath.."vector.lua")
|
||||||
dofile(gamepath.."item.lua")
|
dofile(gamepath.."item.lua")
|
||||||
dofile(gamepath.."register.lua")
|
dofile(gamepath.."register.lua")
|
||||||
|
|
||||||
if multicraft.setting_getbool("mod_profiling") then
|
if core.setting_getbool("mod_profiling") then
|
||||||
dofile(gamepath.."mod_profiling.lua")
|
dofile(gamepath.."mod_profiling.lua")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -17,7 +17,6 @@ dofile(gamepath.."deprecated.lua")
|
||||||
dofile(gamepath.."misc.lua")
|
dofile(gamepath.."misc.lua")
|
||||||
dofile(gamepath.."privileges.lua")
|
dofile(gamepath.."privileges.lua")
|
||||||
dofile(gamepath.."auth.lua")
|
dofile(gamepath.."auth.lua")
|
||||||
dofile(gamepath.."stat.lua")
|
|
||||||
dofile(gamepath.."chatcommands.lua")
|
dofile(gamepath.."chatcommands.lua")
|
||||||
dofile(gamepath.."static_spawn.lua")
|
dofile(gamepath.."static_spawn.lua")
|
||||||
dofile(gamepath.."detached_inventory.lua")
|
dofile(gamepath.."detached_inventory.lua")
|
||||||
|
@ -27,6 +26,3 @@ dofile(gamepath.."voxelarea.lua")
|
||||||
dofile(gamepath.."forceloading.lua")
|
dofile(gamepath.."forceloading.lua")
|
||||||
dofile(gamepath.."statbars.lua")
|
dofile(gamepath.."statbars.lua")
|
||||||
|
|
||||||
if multicraft.setting_getbool("mod_debugging") then
|
|
||||||
dofile(gamepath.."mod_debugging.lua")
|
|
||||||
end
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ end
|
||||||
-- Item definition helpers
|
-- Item definition helpers
|
||||||
--
|
--
|
||||||
|
|
||||||
function multicraft.inventorycube(img1, img2, img3)
|
function core.inventorycube(img1, img2, img3)
|
||||||
img2 = img2 or img1
|
img2 = img2 or img1
|
||||||
img3 = img3 or img1
|
img3 = img3 or img1
|
||||||
return "[inventorycube"
|
return "[inventorycube"
|
||||||
|
@ -22,7 +22,7 @@ function multicraft.inventorycube(img1, img2, img3)
|
||||||
.. "{" .. img3:gsub("%^", "&")
|
.. "{" .. img3:gsub("%^", "&")
|
||||||
end
|
end
|
||||||
|
|
||||||
function multicraft.get_pointed_thing_position(pointed_thing, above)
|
function core.get_pointed_thing_position(pointed_thing, above)
|
||||||
if pointed_thing.type == "node" then
|
if pointed_thing.type == "node" then
|
||||||
if above then
|
if above then
|
||||||
-- The position where a node would be placed
|
-- The position where a node would be placed
|
||||||
|
@ -43,7 +43,7 @@ function multicraft.get_pointed_thing_position(pointed_thing, above)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function multicraft.dir_to_facedir(dir, is6d)
|
function core.dir_to_facedir(dir, is6d)
|
||||||
--account for y if requested
|
--account for y if requested
|
||||||
if is6d and math.abs(dir.y) > math.abs(dir.x) and math.abs(dir.y) > math.abs(dir.z) then
|
if is6d and math.abs(dir.y) > math.abs(dir.x) and math.abs(dir.y) > math.abs(dir.z) then
|
||||||
|
|
||||||
|
@ -96,7 +96,7 @@ function multicraft.dir_to_facedir(dir, is6d)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function multicraft.facedir_to_dir(facedir)
|
function core.facedir_to_dir(facedir)
|
||||||
--a table of possible dirs
|
--a table of possible dirs
|
||||||
return ({{x=0, y=0, z=1},
|
return ({{x=0, y=0, z=1},
|
||||||
{x=1, y=0, z=0},
|
{x=1, y=0, z=0},
|
||||||
|
@ -106,7 +106,7 @@ function multicraft.facedir_to_dir(facedir)
|
||||||
{x=0, y=1, z=0}})
|
{x=0, y=1, z=0}})
|
||||||
|
|
||||||
--indexed into by a table of correlating facedirs
|
--indexed into by a table of correlating facedirs
|
||||||
[({[0]=1, 2, 3, 4,
|
[({[0]=1, 2, 3, 4,
|
||||||
5, 2, 6, 4,
|
5, 2, 6, 4,
|
||||||
6, 2, 5, 4,
|
6, 2, 5, 4,
|
||||||
1, 5, 3, 6,
|
1, 5, 3, 6,
|
||||||
|
@ -117,7 +117,7 @@ function multicraft.facedir_to_dir(facedir)
|
||||||
[facedir]]
|
[facedir]]
|
||||||
end
|
end
|
||||||
|
|
||||||
function multicraft.dir_to_wallmounted(dir)
|
function core.dir_to_wallmounted(dir)
|
||||||
if math.abs(dir.y) > math.max(math.abs(dir.x), math.abs(dir.z)) then
|
if math.abs(dir.y) > math.max(math.abs(dir.x), math.abs(dir.z)) then
|
||||||
if dir.y < 0 then
|
if dir.y < 0 then
|
||||||
return 1
|
return 1
|
||||||
|
@ -139,7 +139,7 @@ function multicraft.dir_to_wallmounted(dir)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function multicraft.get_node_drops(nodename, toolname)
|
function core.get_node_drops(nodename, toolname)
|
||||||
local drop = ItemStack({name=nodename}):get_definition().drop
|
local drop = ItemStack({name=nodename}):get_definition().drop
|
||||||
if drop == nil then
|
if drop == nil then
|
||||||
-- default drop
|
-- default drop
|
||||||
|
@ -188,7 +188,7 @@ function multicraft.get_node_drops(nodename, toolname)
|
||||||
return got_items
|
return got_items
|
||||||
end
|
end
|
||||||
|
|
||||||
function multicraft.item_place_node(itemstack, placer, pointed_thing, param2)
|
function core.item_place_node(itemstack, placer, pointed_thing, param2)
|
||||||
local item = itemstack:peek_item()
|
local item = itemstack:peek_item()
|
||||||
local def = itemstack:get_definition()
|
local def = itemstack:get_definition()
|
||||||
if def.type ~= "node" or pointed_thing.type ~= "node" then
|
if def.type ~= "node" or pointed_thing.type ~= "node" then
|
||||||
|
@ -196,24 +196,24 @@ function multicraft.item_place_node(itemstack, placer, pointed_thing, param2)
|
||||||
end
|
end
|
||||||
|
|
||||||
local under = pointed_thing.under
|
local under = pointed_thing.under
|
||||||
local oldnode_under = multicraft.get_node_or_nil(under)
|
local oldnode_under = core.get_node_or_nil(under)
|
||||||
local above = pointed_thing.above
|
local above = pointed_thing.above
|
||||||
local oldnode_above = multicraft.get_node_or_nil(above)
|
local oldnode_above = core.get_node_or_nil(above)
|
||||||
|
|
||||||
if not oldnode_under or not oldnode_above then
|
if not oldnode_under or not oldnode_above then
|
||||||
multicraft.log("info", placer:get_player_name() .. " tried to place"
|
core.log("info", placer:get_player_name() .. " tried to place"
|
||||||
.. " node in unloaded position " .. multicraft.pos_to_string(above))
|
.. " node in unloaded position " .. core.pos_to_string(above))
|
||||||
return itemstack, false
|
return itemstack, false
|
||||||
end
|
end
|
||||||
|
|
||||||
local olddef_under = ItemStack({name=oldnode_under.name}):get_definition()
|
local olddef_under = ItemStack({name=oldnode_under.name}):get_definition()
|
||||||
olddef_under = olddef_under or multicraft.nodedef_default
|
olddef_under = olddef_under or core.nodedef_default
|
||||||
local olddef_above = ItemStack({name=oldnode_above.name}):get_definition()
|
local olddef_above = ItemStack({name=oldnode_above.name}):get_definition()
|
||||||
olddef_above = olddef_above or multicraft.nodedef_default
|
olddef_above = olddef_above or core.nodedef_default
|
||||||
|
|
||||||
if not olddef_above.buildable_to and not olddef_under.buildable_to then
|
if not olddef_above.buildable_to and not olddef_under.buildable_to then
|
||||||
multicraft.log("info", placer:get_player_name() .. " tried to place"
|
core.log("info", placer:get_player_name() .. " tried to place"
|
||||||
.. " node in invalid position " .. multicraft.pos_to_string(above)
|
.. " node in invalid position " .. core.pos_to_string(above)
|
||||||
.. ", replacing " .. oldnode_above.name)
|
.. ", replacing " .. oldnode_above.name)
|
||||||
return itemstack, false
|
return itemstack, false
|
||||||
end
|
end
|
||||||
|
@ -223,23 +223,23 @@ function multicraft.item_place_node(itemstack, placer, pointed_thing, param2)
|
||||||
|
|
||||||
-- If node under is buildable_to, place into it instead (eg. snow)
|
-- If node under is buildable_to, place into it instead (eg. snow)
|
||||||
if olddef_under.buildable_to then
|
if olddef_under.buildable_to then
|
||||||
multicraft.log("info", "node under is buildable to")
|
core.log("info", "node under is buildable to")
|
||||||
place_to = {x = under.x, y = under.y, z = under.z}
|
place_to = {x = under.x, y = under.y, z = under.z}
|
||||||
end
|
end
|
||||||
|
|
||||||
if multicraft.is_protected(place_to, placer:get_player_name()) then
|
if core.is_protected(place_to, placer:get_player_name()) then
|
||||||
multicraft.log("action", placer:get_player_name()
|
core.log("action", placer:get_player_name()
|
||||||
.. " tried to place " .. def.name
|
.. " tried to place " .. def.name
|
||||||
.. " at protected position "
|
.. " at protected position "
|
||||||
.. multicraft.pos_to_string(place_to))
|
.. core.pos_to_string(place_to))
|
||||||
multicraft.record_protection_violation(place_to, placer:get_player_name())
|
core.record_protection_violation(place_to, placer:get_player_name())
|
||||||
return itemstack
|
return itemstack
|
||||||
end
|
end
|
||||||
|
|
||||||
multicraft.log("action", placer:get_player_name() .. " places node "
|
core.log("action", placer:get_player_name() .. " places node "
|
||||||
.. def.name .. " at " .. multicraft.pos_to_string(place_to))
|
.. def.name .. " at " .. core.pos_to_string(place_to))
|
||||||
|
|
||||||
local oldnode = multicraft.get_node(place_to)
|
local oldnode = core.get_node(place_to)
|
||||||
local newnode = {name = def.name, param1 = 0, param2 = param2}
|
local newnode = {name = def.name, param1 = 0, param2 = param2}
|
||||||
|
|
||||||
-- Calculate direction for wall mounted stuff like torches and signs
|
-- Calculate direction for wall mounted stuff like torches and signs
|
||||||
|
@ -249,7 +249,7 @@ function multicraft.item_place_node(itemstack, placer, pointed_thing, param2)
|
||||||
y = under.y - above.y,
|
y = under.y - above.y,
|
||||||
z = under.z - above.z
|
z = under.z - above.z
|
||||||
}
|
}
|
||||||
newnode.param2 = multicraft.dir_to_wallmounted(dir)
|
newnode.param2 = core.dir_to_wallmounted(dir)
|
||||||
-- Calculate the direction for furnaces and chests and stuff
|
-- Calculate the direction for furnaces and chests and stuff
|
||||||
elseif def.paramtype2 == 'facedir' and not param2 then
|
elseif def.paramtype2 == 'facedir' and not param2 then
|
||||||
local placer_pos = placer:getpos()
|
local placer_pos = placer:getpos()
|
||||||
|
@ -259,27 +259,21 @@ function multicraft.item_place_node(itemstack, placer, pointed_thing, param2)
|
||||||
y = above.y - placer_pos.y,
|
y = above.y - placer_pos.y,
|
||||||
z = above.z - placer_pos.z
|
z = above.z - placer_pos.z
|
||||||
}
|
}
|
||||||
newnode.param2 = multicraft.dir_to_facedir(dir)
|
newnode.param2 = core.dir_to_facedir(dir)
|
||||||
multicraft.log("action", "facedir: " .. newnode.param2)
|
core.log("action", "facedir: " .. newnode.param2)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Check if the node is attached and if it can be placed there
|
-- Check if the node is attached and if it can be placed there
|
||||||
if multicraft.get_item_group(def.name, "attached_node") ~= 0 and
|
if core.get_item_group(def.name, "attached_node") ~= 0 and
|
||||||
not check_attached_node(place_to, newnode) then
|
not check_attached_node(place_to, newnode) then
|
||||||
multicraft.log("action", "attached node " .. def.name ..
|
core.log("action", "attached node " .. def.name ..
|
||||||
" can not be placed at " .. multicraft.pos_to_string(place_to))
|
" can not be placed at " .. core.pos_to_string(place_to))
|
||||||
return itemstack, false
|
return itemstack, false
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Add node and update
|
-- Add node and update
|
||||||
local olddef = multicraft.registered_nodes[oldnode.name]
|
core.add_node(place_to, newnode)
|
||||||
if olddef.leveled and olddef.leveled>0 and olddef.liquidtype ~= "none" and
|
|
||||||
(newnode.name == oldnode.name or newnode.name == olddef.liquid_alternative_flowing or newnode.name == olddef.liquid_alternative_source) then
|
|
||||||
multicraft.add_node_level(place_to, olddef.leveled)
|
|
||||||
else
|
|
||||||
multicraft.add_node(place_to, newnode)
|
|
||||||
end
|
|
||||||
|
|
||||||
local take_item = true
|
local take_item = true
|
||||||
|
|
||||||
|
@ -296,7 +290,7 @@ function multicraft.item_place_node(itemstack, placer, pointed_thing, param2)
|
||||||
|
|
||||||
-- Run script hook
|
-- Run script hook
|
||||||
local _, callback
|
local _, callback
|
||||||
for _, callback in ipairs(multicraft.registered_on_placenodes) do
|
for _, callback in ipairs(core.registered_on_placenodes) do
|
||||||
-- Deepcopy pos, node and pointed_thing because callback can modify them
|
-- Deepcopy pos, node and pointed_thing because callback can modify them
|
||||||
local place_to_copy = {x=place_to.x, y=place_to.y, z=place_to.z}
|
local place_to_copy = {x=place_to.x, y=place_to.y, z=place_to.z}
|
||||||
local newnode_copy = {name=newnode.name, param1=newnode.param1, param2=newnode.param2}
|
local newnode_copy = {name=newnode.name, param1=newnode.param1, param2=newnode.param2}
|
||||||
|
@ -313,34 +307,34 @@ function multicraft.item_place_node(itemstack, placer, pointed_thing, param2)
|
||||||
return itemstack, true
|
return itemstack, true
|
||||||
end
|
end
|
||||||
|
|
||||||
function multicraft.item_place_object(itemstack, placer, pointed_thing)
|
function core.item_place_object(itemstack, placer, pointed_thing)
|
||||||
local pos = multicraft.get_pointed_thing_position(pointed_thing, true)
|
local pos = core.get_pointed_thing_position(pointed_thing, true)
|
||||||
if pos ~= nil then
|
if pos ~= nil then
|
||||||
local item = itemstack:take_item()
|
local item = itemstack:take_item()
|
||||||
multicraft.add_item(pos, item)
|
core.add_item(pos, item)
|
||||||
end
|
end
|
||||||
return itemstack
|
return itemstack
|
||||||
end
|
end
|
||||||
|
|
||||||
function multicraft.item_place(itemstack, placer, pointed_thing, param2)
|
function core.item_place(itemstack, placer, pointed_thing, param2)
|
||||||
-- Call on_rightclick if the pointed node defines it
|
-- Call on_rightclick if the pointed node defines it
|
||||||
if pointed_thing.type == "node" and placer and
|
if pointed_thing.type == "node" and placer and
|
||||||
not placer:get_player_control().sneak then
|
not placer:get_player_control().sneak then
|
||||||
local n = multicraft.get_node(pointed_thing.under)
|
local n = core.get_node(pointed_thing.under)
|
||||||
local nn = n.name
|
local nn = n.name
|
||||||
if multicraft.registered_nodes[nn] and multicraft.registered_nodes[nn].on_rightclick then
|
if core.registered_nodes[nn] and core.registered_nodes[nn].on_rightclick then
|
||||||
return multicraft.registered_nodes[nn].on_rightclick(pointed_thing.under, n,
|
return core.registered_nodes[nn].on_rightclick(pointed_thing.under, n,
|
||||||
placer, itemstack, pointed_thing) or itemstack, false
|
placer, itemstack, pointed_thing) or itemstack, false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if itemstack:get_definition().type == "node" then
|
if itemstack:get_definition().type == "node" then
|
||||||
return multicraft.item_place_node(itemstack, placer, pointed_thing, param2)
|
return core.item_place_node(itemstack, placer, pointed_thing, param2)
|
||||||
end
|
end
|
||||||
return itemstack
|
return itemstack
|
||||||
end
|
end
|
||||||
|
|
||||||
function multicraft.item_drop(itemstack, dropper, pos)
|
function core.item_drop(itemstack, dropper, pos)
|
||||||
if dropper.is_player then
|
if dropper.is_player then
|
||||||
local v = dropper:get_look_dir()
|
local v = dropper:get_look_dir()
|
||||||
local p = {x=pos.x, y=pos.y+1.2, z=pos.z}
|
local p = {x=pos.x, y=pos.y+1.2, z=pos.z}
|
||||||
|
@ -349,7 +343,7 @@ function multicraft.item_drop(itemstack, dropper, pos)
|
||||||
cs = 1
|
cs = 1
|
||||||
end
|
end
|
||||||
local item = itemstack:take_item(cs)
|
local item = itemstack:take_item(cs)
|
||||||
local obj = multicraft.add_item(p, item)
|
local obj = core.add_item(p, item)
|
||||||
if obj then
|
if obj then
|
||||||
v.x = v.x*2
|
v.x = v.x*2
|
||||||
v.y = v.y*2 + 2
|
v.y = v.y*2 + 2
|
||||||
|
@ -358,30 +352,48 @@ function multicraft.item_drop(itemstack, dropper, pos)
|
||||||
end
|
end
|
||||||
|
|
||||||
else
|
else
|
||||||
multicraft.add_item(pos, itemstack)
|
core.add_item(pos, itemstack)
|
||||||
end
|
end
|
||||||
return itemstack
|
return itemstack
|
||||||
end
|
end
|
||||||
|
|
||||||
function multicraft.item_eat(hp_change, replace_with_item)
|
function core.do_item_eat(hp_change, replace_with_item, itemstack, user, pointed_thing)
|
||||||
return function(itemstack, user, pointed_thing) -- closure
|
for _, callback in pairs(core.registered_on_item_eats) do
|
||||||
for _, callback in pairs(multicraft.registered_on_item_eats) do
|
local result = callback(hp_change, replace_with_item, itemstack, user, pointed_thing)
|
||||||
local result = callback(hp_change, replace_with_item, itemstack, user, pointed_thing)
|
if result then
|
||||||
if result then
|
return result
|
||||||
return result
|
end
|
||||||
|
end
|
||||||
|
if itemstack:take_item() ~= nil then
|
||||||
|
user:set_hp(user:get_hp() + hp_change)
|
||||||
|
|
||||||
|
if replace_with_item then
|
||||||
|
if itemstack:is_empty() then
|
||||||
|
itemstack:add_item(replace_with_item)
|
||||||
|
else
|
||||||
|
local inv = user:get_inventory()
|
||||||
|
if inv:room_for_item("main", {name=replace_with_item}) then
|
||||||
|
inv:add_item("main", replace_with_item)
|
||||||
|
else
|
||||||
|
local pos = user:getpos()
|
||||||
|
pos.y = math.floor(pos.y + 0.5)
|
||||||
|
core.add_item(pos, replace_with_item)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if itemstack:take_item() ~= nil then
|
end
|
||||||
user:set_hp(user:get_hp() + hp_change)
|
return itemstack
|
||||||
itemstack:add_item(replace_with_item) -- note: replace_with_item is optional
|
end
|
||||||
end
|
|
||||||
return itemstack
|
function core.item_eat(hp_change, replace_with_item)
|
||||||
|
return function(itemstack, user, pointed_thing) -- closure
|
||||||
|
return core.do_item_eat(hp_change, replace_with_item, itemstack, user, pointed_thing)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function multicraft.node_punch(pos, node, puncher, pointed_thing)
|
function core.node_punch(pos, node, puncher, pointed_thing)
|
||||||
-- Run script hook
|
-- Run script hook
|
||||||
for _, callback in ipairs(multicraft.registered_on_punchnodes) do
|
for _, callback in ipairs(core.registered_on_punchnodes) do
|
||||||
-- Copy pos and node because callback can modify them
|
-- Copy pos and node because callback can modify them
|
||||||
local pos_copy = vector.new(pos)
|
local pos_copy = vector.new(pos)
|
||||||
local node_copy = {name=node.name, param1=node.param1, param2=node.param2}
|
local node_copy = {name=node.name, param1=node.param1, param2=node.param2}
|
||||||
|
@ -390,7 +402,7 @@ function multicraft.node_punch(pos, node, puncher, pointed_thing)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function multicraft.handle_node_drops(pos, drops, digger)
|
function core.handle_node_drops(pos, drops, digger)
|
||||||
-- Add dropped items to object's inventory
|
-- Add dropped items to object's inventory
|
||||||
if digger:get_inventory() then
|
if digger:get_inventory() then
|
||||||
local _, dropped_item
|
local _, dropped_item
|
||||||
|
@ -402,60 +414,60 @@ function multicraft.handle_node_drops(pos, drops, digger)
|
||||||
y = pos.y + math.random()/2-0.25,
|
y = pos.y + math.random()/2-0.25,
|
||||||
z = pos.z + math.random()/2-0.25,
|
z = pos.z + math.random()/2-0.25,
|
||||||
}
|
}
|
||||||
multicraft.add_item(p, left)
|
core.add_item(p, left)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function multicraft.node_dig(pos, node, digger)
|
function core.node_dig(pos, node, digger)
|
||||||
local def = ItemStack({name=node.name}):get_definition()
|
local def = ItemStack({name=node.name}):get_definition()
|
||||||
if not def.diggable or (def.can_dig and not def.can_dig(pos,digger)) then
|
if not def.diggable or (def.can_dig and not def.can_dig(pos,digger)) then
|
||||||
multicraft.log("info", digger:get_player_name() .. " tried to dig "
|
core.log("info", digger:get_player_name() .. " tried to dig "
|
||||||
.. node.name .. " which is not diggable "
|
.. node.name .. " which is not diggable "
|
||||||
.. multicraft.pos_to_string(pos))
|
.. core.pos_to_string(pos))
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
if multicraft.is_protected(pos, digger:get_player_name()) then
|
if core.is_protected(pos, digger:get_player_name()) then
|
||||||
multicraft.log("action", digger:get_player_name()
|
core.log("action", digger:get_player_name()
|
||||||
.. " tried to dig " .. node.name
|
.. " tried to dig " .. node.name
|
||||||
.. " at protected position "
|
.. " at protected position "
|
||||||
.. multicraft.pos_to_string(pos))
|
.. core.pos_to_string(pos))
|
||||||
multicraft.record_protection_violation(pos, digger:get_player_name())
|
core.record_protection_violation(pos, digger:get_player_name())
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
multicraft.log('action', digger:get_player_name() .. " digs "
|
core.log('action', digger:get_player_name() .. " digs "
|
||||||
.. node.name .. " at " .. multicraft.pos_to_string(pos))
|
.. node.name .. " at " .. core.pos_to_string(pos))
|
||||||
|
|
||||||
local wielded = digger:get_wielded_item()
|
local wielded = digger:get_wielded_item()
|
||||||
local drops = multicraft.get_node_drops(node.name, wielded:get_name())
|
local drops = core.get_node_drops(node.name, wielded:get_name())
|
||||||
|
|
||||||
local wdef = wielded:get_definition()
|
local wdef = wielded:get_definition()
|
||||||
local tp = wielded:get_tool_capabilities()
|
local tp = wielded:get_tool_capabilities()
|
||||||
local dp = multicraft.get_dig_params(def.groups, tp)
|
local dp = core.get_dig_params(def.groups, tp)
|
||||||
if wdef and wdef.after_use then
|
if wdef and wdef.after_use then
|
||||||
wielded = wdef.after_use(wielded, digger, node, dp) or wielded
|
wielded = wdef.after_use(wielded, digger, node, dp) or wielded
|
||||||
else
|
else
|
||||||
-- Wear out tool
|
-- Wear out tool
|
||||||
if not multicraft.setting_getbool("creative_mode") then
|
if not core.setting_getbool("creative_mode") then
|
||||||
wielded:add_wear(dp.wear)
|
wielded:add_wear(dp.wear)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
digger:set_wielded_item(wielded)
|
digger:set_wielded_item(wielded)
|
||||||
|
|
||||||
-- Handle drops
|
-- Handle drops
|
||||||
multicraft.handle_node_drops(pos, drops, digger)
|
core.handle_node_drops(pos, drops, digger)
|
||||||
|
|
||||||
local oldmetadata = nil
|
local oldmetadata = nil
|
||||||
if def.after_dig_node then
|
if def.after_dig_node then
|
||||||
oldmetadata = multicraft.get_meta(pos):to_table()
|
oldmetadata = core.get_meta(pos):to_table()
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Remove node and update
|
-- Remove node and update
|
||||||
multicraft.remove_node(pos)
|
core.remove_node(pos)
|
||||||
|
|
||||||
-- Run callback
|
-- Run callback
|
||||||
if def.after_dig_node then
|
if def.after_dig_node then
|
||||||
-- Copy pos and node because callback can modify them
|
-- Copy pos and node because callback can modify them
|
||||||
|
@ -466,7 +478,7 @@ function multicraft.node_dig(pos, node, digger)
|
||||||
|
|
||||||
-- Run script hook
|
-- Run script hook
|
||||||
local _, callback
|
local _, callback
|
||||||
for _, callback in ipairs(multicraft.registered_on_dignodes) do
|
for _, callback in ipairs(core.registered_on_dignodes) do
|
||||||
-- Copy pos and node because callback can modify them
|
-- Copy pos and node because callback can modify them
|
||||||
local pos_copy = {x=pos.x, y=pos.y, z=pos.z}
|
local pos_copy = {x=pos.x, y=pos.y, z=pos.z}
|
||||||
local node_copy = {name=node.name, param1=node.param1, param2=node.param2}
|
local node_copy = {name=node.name, param1=node.param1, param2=node.param2}
|
||||||
|
@ -474,7 +486,7 @@ function multicraft.node_dig(pos, node, digger)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- This is used to allow mods to redefine multicraft.item_place and so on
|
-- This is used to allow mods to redefine core.item_place and so on
|
||||||
-- NOTE: This is not the preferred way. Preferred way is to provide enough
|
-- NOTE: This is not the preferred way. Preferred way is to provide enough
|
||||||
-- callbacks to not require redefining global functions. -celeron55
|
-- callbacks to not require redefining global functions. -celeron55
|
||||||
local function redef_wrapper(table, name)
|
local function redef_wrapper(table, name)
|
||||||
|
@ -487,7 +499,7 @@ end
|
||||||
-- Item definition defaults
|
-- Item definition defaults
|
||||||
--
|
--
|
||||||
|
|
||||||
multicraft.nodedef_default = {
|
core.nodedef_default = {
|
||||||
-- Item properties
|
-- Item properties
|
||||||
type="node",
|
type="node",
|
||||||
-- name intentionally not defined here
|
-- name intentionally not defined here
|
||||||
|
@ -503,20 +515,20 @@ multicraft.nodedef_default = {
|
||||||
node_placement_prediction = nil,
|
node_placement_prediction = nil,
|
||||||
|
|
||||||
-- Interaction callbacks
|
-- Interaction callbacks
|
||||||
on_place = redef_wrapper(core, 'item_place'), -- multicraft.item_place
|
on_place = redef_wrapper(core, 'item_place'), -- core.item_place
|
||||||
on_drop = redef_wrapper(core, 'item_drop'), -- multicraft.item_drop
|
on_drop = redef_wrapper(core, 'item_drop'), -- core.item_drop
|
||||||
on_use = nil,
|
on_use = nil,
|
||||||
can_dig = nil,
|
can_dig = nil,
|
||||||
|
|
||||||
on_punch = redef_wrapper(core, 'node_punch'), -- multicraft.node_punch
|
on_punch = redef_wrapper(core, 'node_punch'), -- core.node_punch
|
||||||
on_rightclick = nil,
|
on_rightclick = nil,
|
||||||
on_dig = redef_wrapper(core, 'node_dig'), -- multicraft.node_dig
|
on_dig = redef_wrapper(core, 'node_dig'), -- core.node_dig
|
||||||
|
|
||||||
on_receive_fields = nil,
|
on_receive_fields = nil,
|
||||||
|
|
||||||
on_metadata_inventory_move = multicraft.node_metadata_inventory_move_allow_all,
|
on_metadata_inventory_move = core.node_metadata_inventory_move_allow_all,
|
||||||
on_metadata_inventory_offer = multicraft.node_metadata_inventory_offer_allow_all,
|
on_metadata_inventory_offer = core.node_metadata_inventory_offer_allow_all,
|
||||||
on_metadata_inventory_take = multicraft.node_metadata_inventory_take_allow_all,
|
on_metadata_inventory_take = core.node_metadata_inventory_take_allow_all,
|
||||||
|
|
||||||
-- Node properties
|
-- Node properties
|
||||||
drawtype = "normal",
|
drawtype = "normal",
|
||||||
|
@ -551,7 +563,7 @@ multicraft.nodedef_default = {
|
||||||
legacy_wallmounted = false,
|
legacy_wallmounted = false,
|
||||||
}
|
}
|
||||||
|
|
||||||
multicraft.craftitemdef_default = {
|
core.craftitemdef_default = {
|
||||||
type="craft",
|
type="craft",
|
||||||
-- name intentionally not defined here
|
-- name intentionally not defined here
|
||||||
description = "",
|
description = "",
|
||||||
|
@ -564,12 +576,12 @@ multicraft.craftitemdef_default = {
|
||||||
tool_capabilities = nil,
|
tool_capabilities = nil,
|
||||||
|
|
||||||
-- Interaction callbacks
|
-- Interaction callbacks
|
||||||
on_place = redef_wrapper(core, 'item_place'), -- multicraft.item_place
|
on_place = redef_wrapper(core, 'item_place'), -- core.item_place
|
||||||
on_drop = redef_wrapper(core, 'item_drop'), -- multicraft.item_drop
|
on_drop = redef_wrapper(core, 'item_drop'), -- core.item_drop
|
||||||
on_use = nil,
|
on_use = nil,
|
||||||
}
|
}
|
||||||
|
|
||||||
multicraft.tooldef_default = {
|
core.tooldef_default = {
|
||||||
type="tool",
|
type="tool",
|
||||||
-- name intentionally not defined here
|
-- name intentionally not defined here
|
||||||
description = "",
|
description = "",
|
||||||
|
@ -582,12 +594,12 @@ multicraft.tooldef_default = {
|
||||||
tool_capabilities = nil,
|
tool_capabilities = nil,
|
||||||
|
|
||||||
-- Interaction callbacks
|
-- Interaction callbacks
|
||||||
on_place = redef_wrapper(core, 'item_place'), -- multicraft.item_place
|
on_place = redef_wrapper(core, 'item_place'), -- core.item_place
|
||||||
on_drop = redef_wrapper(core, 'item_drop'), -- multicraft.item_drop
|
on_drop = redef_wrapper(core, 'item_drop'), -- core.item_drop
|
||||||
on_use = nil,
|
on_use = nil,
|
||||||
}
|
}
|
||||||
|
|
||||||
multicraft.noneitemdef_default = { -- This is used for the hand and unknown items
|
core.noneitemdef_default = { -- This is used for the hand and unknown items
|
||||||
type="none",
|
type="none",
|
||||||
-- name intentionally not defined here
|
-- name intentionally not defined here
|
||||||
description = "",
|
description = "",
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
-- Minetest: builtin/item_entity.lua
|
-- Minetest: builtin/item_entity.lua
|
||||||
|
|
||||||
function multicraft.spawn_item(pos, item)
|
function core.spawn_item(pos, item)
|
||||||
-- Take item in any format
|
-- Take item in any format
|
||||||
local stack = ItemStack(item)
|
local stack = ItemStack(item)
|
||||||
local obj = multicraft.add_entity(pos, "__builtin:item")
|
local obj = core.add_entity(pos, "__builtin:item")
|
||||||
obj:get_luaentity():set_item(stack:to_string())
|
obj:get_luaentity():set_item(stack:to_string())
|
||||||
return obj
|
return obj
|
||||||
end
|
end
|
||||||
|
@ -11,12 +11,12 @@ end
|
||||||
-- If item_entity_ttl is not set, enity will have default life time
|
-- If item_entity_ttl is not set, enity will have default life time
|
||||||
-- Setting it to -1 disables the feature
|
-- Setting it to -1 disables the feature
|
||||||
|
|
||||||
local time_to_live = tonumber(multicraft.setting_get("item_entity_ttl"))
|
local time_to_live = tonumber(core.setting_get("item_entity_ttl"))
|
||||||
if not time_to_live then
|
if not time_to_live then
|
||||||
time_to_live = -1
|
time_to_live = 900
|
||||||
end
|
end
|
||||||
|
|
||||||
multicraft.register_entity(":__builtin:item", {
|
core.register_entity(":__builtin:item", {
|
||||||
initial_properties = {
|
initial_properties = {
|
||||||
hp_max = 1,
|
hp_max = 1,
|
||||||
physical = true,
|
physical = true,
|
||||||
|
@ -52,9 +52,9 @@ multicraft.register_entity(":__builtin:item", {
|
||||||
end
|
end
|
||||||
local item_texture = nil
|
local item_texture = nil
|
||||||
local item_type = ""
|
local item_type = ""
|
||||||
if multicraft.registered_items[itemname] then
|
if core.registered_items[itemname] then
|
||||||
item_texture = multicraft.registered_items[itemname].inventory_image
|
item_texture = core.registered_items[itemname].inventory_image
|
||||||
item_type = multicraft.registered_items[itemname].type
|
item_type = core.registered_items[itemname].type
|
||||||
end
|
end
|
||||||
local prop = {
|
local prop = {
|
||||||
is_visible = true,
|
is_visible = true,
|
||||||
|
@ -68,7 +68,7 @@ multicraft.register_entity(":__builtin:item", {
|
||||||
end,
|
end,
|
||||||
|
|
||||||
get_staticdata = function(self)
|
get_staticdata = function(self)
|
||||||
return multicraft.serialize({
|
return core.serialize({
|
||||||
itemstring = self.itemstring,
|
itemstring = self.itemstring,
|
||||||
always_collect = self.always_collect,
|
always_collect = self.always_collect,
|
||||||
age = self.age
|
age = self.age
|
||||||
|
@ -77,7 +77,7 @@ multicraft.register_entity(":__builtin:item", {
|
||||||
|
|
||||||
on_activate = function(self, staticdata, dtime_s)
|
on_activate = function(self, staticdata, dtime_s)
|
||||||
if string.sub(staticdata, 1, string.len("return")) == "return" then
|
if string.sub(staticdata, 1, string.len("return")) == "return" then
|
||||||
local data = multicraft.deserialize(staticdata)
|
local data = core.deserialize(staticdata)
|
||||||
if data and type(data) == "table" then
|
if data and type(data) == "table" then
|
||||||
self.itemstring = data.itemstring
|
self.itemstring = data.itemstring
|
||||||
self.always_collect = data.always_collect
|
self.always_collect = data.always_collect
|
||||||
|
@ -155,7 +155,7 @@ multicraft.register_entity(":__builtin:item", {
|
||||||
end
|
end
|
||||||
local p = self.object:getpos()
|
local p = self.object:getpos()
|
||||||
p.y = p.y - 0.5
|
p.y = p.y - 0.5
|
||||||
local node = multicraft.get_node_or_nil(p)
|
local node = core.get_node_or_nil(p)
|
||||||
local in_unloaded = (node == nil)
|
local in_unloaded = (node == nil)
|
||||||
if in_unloaded then
|
if in_unloaded then
|
||||||
-- Don't infinetly fall into unloaded map
|
-- Don't infinetly fall into unloaded map
|
||||||
|
@ -168,11 +168,11 @@ multicraft.register_entity(":__builtin:item", {
|
||||||
local nn = node.name
|
local nn = node.name
|
||||||
-- If node is not registered or node is walkably solid and resting on nodebox
|
-- If node is not registered or node is walkably solid and resting on nodebox
|
||||||
local v = self.object:getvelocity()
|
local v = self.object:getvelocity()
|
||||||
if not multicraft.registered_nodes[nn] or (multicraft.registered_nodes[nn].walkable and multicraft.get_item_group(nn, "slippery")==0) and v.y == 0 then
|
if not core.registered_nodes[nn] or core.registered_nodes[nn].walkable and v.y == 0 then
|
||||||
if self.physical_state then
|
if self.physical_state then
|
||||||
local own_stack = ItemStack(self.object:get_luaentity().itemstring)
|
local own_stack = ItemStack(self.object:get_luaentity().itemstring)
|
||||||
-- Merge with close entities of the same item
|
-- Merge with close entities of the same item
|
||||||
for _, object in ipairs(multicraft.get_objects_inside_radius(p, 0.8)) do
|
for _, object in ipairs(core.get_objects_inside_radius(p, 0.8)) do
|
||||||
local obj = object:get_luaentity()
|
local obj = object:get_luaentity()
|
||||||
if obj and obj.name == "__builtin:item"
|
if obj and obj.name == "__builtin:item"
|
||||||
and obj.physical_state == false then
|
and obj.physical_state == false then
|
||||||
|
@ -192,17 +192,6 @@ multicraft.register_entity(":__builtin:item", {
|
||||||
self.object:setacceleration({x = 0, y = -10, z = 0})
|
self.object:setacceleration({x = 0, y = -10, z = 0})
|
||||||
self.physical_state = true
|
self.physical_state = true
|
||||||
self.object:set_properties({physical = true})
|
self.object:set_properties({physical = true})
|
||||||
elseif multicraft.get_item_group(nn, "slippery") ~= 0 then
|
|
||||||
if math.abs(v.x) < .2 and math.abs(v.z) < .2 then
|
|
||||||
self.object:setvelocity({x=0,y=0,z=0})
|
|
||||||
self.object:setacceleration({x=0, y=0, z=0})
|
|
||||||
self.physical_state = false
|
|
||||||
self.object:set_properties({
|
|
||||||
physical = false
|
|
||||||
})
|
|
||||||
else
|
|
||||||
self.object:setacceleration({x=-v.x, y=-10, z=-v.z})
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
|
|
|
@ -4,36 +4,34 @@
|
||||||
-- Misc. API functions
|
-- Misc. API functions
|
||||||
--
|
--
|
||||||
|
|
||||||
multicraft.timers_to_add = {}
|
core.timers_to_add = {}
|
||||||
multicraft.timers = {}
|
core.timers = {}
|
||||||
multicraft.register_globalstep(function(dtime)
|
core.register_globalstep(function(dtime)
|
||||||
for _, timer in ipairs(multicraft.timers_to_add) do
|
for _, timer in ipairs(core.timers_to_add) do
|
||||||
table.insert(multicraft.timers, timer)
|
table.insert(core.timers, timer)
|
||||||
end
|
end
|
||||||
multicraft.timers_to_add = {}
|
core.timers_to_add = {}
|
||||||
local end_ms = os.clock() * 1000 + 50
|
|
||||||
local index = 1
|
local index = 1
|
||||||
while index <= #multicraft.timers do
|
while index <= #core.timers do
|
||||||
local timer = multicraft.timers[index]
|
local timer = core.timers[index]
|
||||||
timer.time = timer.time - dtime
|
timer.time = timer.time - dtime
|
||||||
if timer.time <= 0 then
|
if timer.time <= 0 then
|
||||||
timer.func(unpack(timer.args or {}))
|
timer.func(unpack(timer.args or {}))
|
||||||
table.remove(multicraft.timers,index)
|
table.remove(core.timers,index)
|
||||||
else
|
else
|
||||||
index = index + 1
|
index = index + 1
|
||||||
end
|
end
|
||||||
if os.clock() * 1000 > end_ms then return end
|
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
function multicraft.after(time, func, ...)
|
function core.after(time, func, ...)
|
||||||
assert(tonumber(time) and type(func) == "function",
|
assert(tonumber(time) and type(func) == "function",
|
||||||
"Invalid multicraft.after invocation")
|
"Invalid core.after invocation")
|
||||||
table.insert(multicraft.timers_to_add, {time=time, func=func, args={...}})
|
table.insert(core.timers_to_add, {time=time, func=func, args={...}})
|
||||||
end
|
end
|
||||||
|
|
||||||
function multicraft.check_player_privs(name, privs)
|
function core.check_player_privs(name, privs)
|
||||||
local player_privs = multicraft.get_player_privs(name)
|
local player_privs = core.get_player_privs(name)
|
||||||
local missing_privileges = {}
|
local missing_privileges = {}
|
||||||
for priv, val in pairs(privs) do
|
for priv, val in pairs(privs) do
|
||||||
if val then
|
if val then
|
||||||
|
@ -50,29 +48,29 @@ end
|
||||||
|
|
||||||
local player_list = {}
|
local player_list = {}
|
||||||
|
|
||||||
multicraft.register_on_joinplayer(function(player)
|
core.register_on_joinplayer(function(player)
|
||||||
player_list[player:get_player_name()] = player
|
player_list[player:get_player_name()] = player
|
||||||
end)
|
end)
|
||||||
|
|
||||||
multicraft.register_on_leaveplayer(function(player)
|
core.register_on_leaveplayer(function(player)
|
||||||
player_list[player:get_player_name()] = nil
|
player_list[player:get_player_name()] = nil
|
||||||
end)
|
end)
|
||||||
|
|
||||||
function multicraft.get_connected_players()
|
function core.get_connected_players()
|
||||||
local temp_table = {}
|
local temp_table = {}
|
||||||
for index, value in pairs(player_list) do
|
for index, value in pairs(player_list) do
|
||||||
if value:is_player_connected() then
|
if value:is_player_connected() then
|
||||||
table.insert(temp_table, value)
|
table.insert(temp_table, value)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return temp_table
|
return temp_table
|
||||||
end
|
end
|
||||||
|
|
||||||
function multicraft.hash_node_position(pos)
|
function core.hash_node_position(pos)
|
||||||
return (pos.z+32768)*65536*65536 + (pos.y+32768)*65536 + pos.x+32768
|
return (pos.z+32768)*65536*65536 + (pos.y+32768)*65536 + pos.x+32768
|
||||||
end
|
end
|
||||||
|
|
||||||
function multicraft.get_position_from_hash(hash)
|
function core.get_position_from_hash(hash)
|
||||||
local pos = {}
|
local pos = {}
|
||||||
pos.x = (hash%65536) - 32768
|
pos.x = (hash%65536) - 32768
|
||||||
hash = math.floor(hash/65536)
|
hash = math.floor(hash/65536)
|
||||||
|
@ -82,41 +80,41 @@ function multicraft.get_position_from_hash(hash)
|
||||||
return pos
|
return pos
|
||||||
end
|
end
|
||||||
|
|
||||||
function multicraft.get_item_group(name, group)
|
function core.get_item_group(name, group)
|
||||||
if not multicraft.registered_items[name] or not
|
if not core.registered_items[name] or not
|
||||||
multicraft.registered_items[name].groups[group] then
|
core.registered_items[name].groups[group] then
|
||||||
return 0
|
return 0
|
||||||
end
|
end
|
||||||
return multicraft.registered_items[name].groups[group]
|
return core.registered_items[name].groups[group]
|
||||||
end
|
end
|
||||||
|
|
||||||
function multicraft.get_node_group(name, group)
|
function core.get_node_group(name, group)
|
||||||
multicraft.log("deprecated", "Deprecated usage of get_node_group, use get_item_group instead")
|
core.log("deprecated", "Deprecated usage of get_node_group, use get_item_group instead")
|
||||||
return multicraft.get_item_group(name, group)
|
return core.get_item_group(name, group)
|
||||||
end
|
end
|
||||||
|
|
||||||
function multicraft.setting_get_pos(name)
|
function core.setting_get_pos(name)
|
||||||
local value = multicraft.setting_get(name)
|
local value = core.setting_get(name)
|
||||||
if not value then
|
if not value then
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
return multicraft.string_to_pos(value)
|
return core.string_to_pos(value)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- To be overriden by protection mods
|
-- To be overriden by protection mods
|
||||||
function multicraft.is_protected(pos, name)
|
function core.is_protected(pos, name)
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
function multicraft.record_protection_violation(pos, name)
|
function core.record_protection_violation(pos, name)
|
||||||
for _, func in pairs(multicraft.registered_on_protection_violation) do
|
for _, func in pairs(core.registered_on_protection_violation) do
|
||||||
func(pos, name)
|
func(pos, name)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local raillike_ids = {}
|
local raillike_ids = {}
|
||||||
local raillike_cur_id = 0
|
local raillike_cur_id = 0
|
||||||
function multicraft.raillike_group(name)
|
function core.raillike_group(name)
|
||||||
local id = raillike_ids[name]
|
local id = raillike_ids[name]
|
||||||
if not id then
|
if not id then
|
||||||
raillike_cur_id = raillike_cur_id + 1
|
raillike_cur_id = raillike_cur_id + 1
|
||||||
|
|
|
@ -1,126 +0,0 @@
|
||||||
-- Freeminer: builtin/game/mod_debugging.lua
|
|
||||||
-- by rubenwardy
|
|
||||||
|
|
||||||
local mod = {}
|
|
||||||
mod.recipes = {}
|
|
||||||
mod.aliases = {}
|
|
||||||
|
|
||||||
multicraft.log("action", 'Mod debugging enabled')
|
|
||||||
-- Sees if there is a node with this group/these groups
|
|
||||||
-- Supports AND view group:name, name
|
|
||||||
local function group_exists(groupname)
|
|
||||||
local flags = groupname:split(",")
|
|
||||||
for name, def in pairs(multicraft.registered_items) do
|
|
||||||
local flag = true
|
|
||||||
for k, v in pairs(flags) do
|
|
||||||
local g = def.groups and def.groups[v:gsub('%group:', '')] or 0
|
|
||||||
if not g or g <= 0 then
|
|
||||||
flag = false
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if flag then
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Check that the item exists
|
|
||||||
function mod.assert(recipe, _name, output)
|
|
||||||
local name = mod.strip_name(_name)
|
|
||||||
if name == nil then
|
|
||||||
multicraft.log('error', 'nil in recipe for '..mod.strip_name(output))
|
|
||||||
print(recipe.from)
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
if mod.aliases[name] ~= nil then
|
|
||||||
name = mod.aliases[name]
|
|
||||||
end
|
|
||||||
|
|
||||||
if multicraft.registered_items[name] == nil and not group_exists(name) then
|
|
||||||
multicraft.log( 'error', 'missing item '..name.." in recipe for "..mod.strip_name(output) )
|
|
||||||
print(recipe.from)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Turns a itemstack name into just its item name
|
|
||||||
-- For example: "mod:item 99" -> "mod:item"
|
|
||||||
function mod.strip_name(name)
|
|
||||||
if name == nil then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
res = name:gsub('%"', '')
|
|
||||||
|
|
||||||
if res:sub(1, 1) == ":" then
|
|
||||||
res = table.concat{res:sub(1, 1-1), "", res:sub(1+1)}
|
|
||||||
end
|
|
||||||
|
|
||||||
for str in string.gmatch(res, "([^ ]+)") do
|
|
||||||
if str ~= " " and str ~= nil then
|
|
||||||
res=str
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if res == nil then
|
|
||||||
res=""
|
|
||||||
end
|
|
||||||
|
|
||||||
return res
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Cycles through the recipe table, checking the items.
|
|
||||||
-- Recursive
|
|
||||||
function mod.check_recipe(recipe, table, output)
|
|
||||||
if type(table) == "table" then
|
|
||||||
for i=1,# table do
|
|
||||||
mod.check_recipe(recipe, table[i], output)
|
|
||||||
end
|
|
||||||
else
|
|
||||||
mod.assert(recipe, table,output)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Check recipes once the game has loaded
|
|
||||||
multicraft.after(0, function()
|
|
||||||
for i=1, #mod.recipes do
|
|
||||||
if mod.recipes[i] and mod.recipes[i].output then
|
|
||||||
mod.assert(mod.recipes[i], mod.recipes[i].output, mod.recipes[i].output)
|
|
||||||
|
|
||||||
if type(mod.recipes[i].recipe) == "table" then
|
|
||||||
for a=1,# mod.recipes[i].recipe do
|
|
||||||
mod.check_recipe(mod.recipes[i], mod.recipes[i].recipe[a], mod.recipes[i].output)
|
|
||||||
end
|
|
||||||
else
|
|
||||||
mod.assert(mod.recipes[i], mod.recipes[i].recipe, mod.recipes[i].output)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
|
|
||||||
-- Override register_craft to catch craft recipes
|
|
||||||
local register_craft = multicraft.register_craft
|
|
||||||
multicraft.register_craft = function(recipe)
|
|
||||||
register_craft(recipe)
|
|
||||||
|
|
||||||
local name = mod.strip_name(recipe.output)
|
|
||||||
recipe.from = debug.traceback()
|
|
||||||
if name~=nil then
|
|
||||||
table.insert(mod.recipes, recipe)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Override register_alias to catch aliases
|
|
||||||
local register_alias = multicraft.register_alias
|
|
||||||
multicraft.register_alias = function(new, old)
|
|
||||||
register_alias(new, old)
|
|
||||||
|
|
||||||
local name = mod.strip_name(new)
|
|
||||||
local name2 = mod.strip_name(old)
|
|
||||||
if name~=nil and name2~=nil then
|
|
||||||
mod.aliases[new] = old
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -145,14 +145,14 @@ end
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
local function build_callback(log_id, fct)
|
local function build_callback(log_id, fct)
|
||||||
return function( toregister )
|
return function( toregister )
|
||||||
local modname = multicraft.get_current_modname()
|
local modname = core.get_current_modname()
|
||||||
|
|
||||||
fct(function(...)
|
fct(function(...)
|
||||||
local starttime = multicraft.get_us_time()
|
local starttime = core.get_us_time()
|
||||||
-- note maximum 10 return values are supported unless someone finds
|
-- note maximum 10 return values are supported unless someone finds
|
||||||
-- a way to store a variable lenght return value list
|
-- a way to store a variable lenght return value list
|
||||||
local r0, r1, r2, r3, r4, r5, r6, r7, r8, r9 = toregister(...)
|
local r0, r1, r2, r3, r4, r5, r6, r7, r8, r9 = toregister(...)
|
||||||
local delta = multicraft.get_us_time() - starttime
|
local delta = core.get_us_time() - starttime
|
||||||
mod_statistics.log_time(log_id, modname, delta)
|
mod_statistics.log_time(log_id, modname, delta)
|
||||||
return r0, r1, r2, r3, r4, r5, r6, r7, r8, r9
|
return r0, r1, r2, r3, r4, r5, r6, r7, r8, r9
|
||||||
end
|
end
|
||||||
|
@ -165,14 +165,14 @@ function profiling_print_log(cmd, filter)
|
||||||
|
|
||||||
print("Filter:" .. dump(filter))
|
print("Filter:" .. dump(filter))
|
||||||
|
|
||||||
multicraft.log("action", "Values below show times/percentages per server step.")
|
core.log("action", "Values below show times/percentages per server step.")
|
||||||
multicraft.log("action", "Following suffixes are used for entities:")
|
core.log("action", "Following suffixes are used for entities:")
|
||||||
multicraft.log("action", "\t#oa := on_activate, #os := on_step, #op := on_punch, #or := on_rightclick, #gs := get_staticdata")
|
core.log("action", "\t#oa := on_activate, #os := on_step, #op := on_punch, #or := on_rightclick, #gs := get_staticdata")
|
||||||
multicraft.log("action",
|
core.log("action",
|
||||||
string.format("%16s | %25s | %10s | %10s | %10s | %9s | %9s | %9s",
|
string.format("%16s | %25s | %10s | %10s | %10s | %9s | %9s | %9s",
|
||||||
"modname", "type" , "min µs", "max µs", "avg µs", "min %", "max %", "avg %")
|
"modname", "type" , "min µs", "max µs", "avg µs", "min %", "max %", "avg %")
|
||||||
)
|
)
|
||||||
multicraft.log("action",
|
core.log("action",
|
||||||
"-----------------+---------------------------+-----------+" ..
|
"-----------------+---------------------------+-----------+" ..
|
||||||
"-----------+-----------+-----------+-----------+-----------")
|
"-----------+-----------+-----------+-----------+-----------")
|
||||||
for modname,statistics in pairs(mod_statistics.stats) do
|
for modname,statistics in pairs(mod_statistics.stats) do
|
||||||
|
@ -183,7 +183,7 @@ function profiling_print_log(cmd, filter)
|
||||||
modname = "..." .. modname:sub(-13)
|
modname = "..." .. modname:sub(-13)
|
||||||
end
|
end
|
||||||
|
|
||||||
multicraft.log("action",
|
core.log("action",
|
||||||
string.format("%16s | %25s | %9d | %9d | %9d | %9d | %9d | %9d",
|
string.format("%16s | %25s | %9d | %9d | %9d | %9d | %9d | %9d",
|
||||||
modname,
|
modname,
|
||||||
" ",
|
" ",
|
||||||
|
@ -194,7 +194,7 @@ function profiling_print_log(cmd, filter)
|
||||||
statistics.max_per,
|
statistics.max_per,
|
||||||
statistics.avg_per)
|
statistics.avg_per)
|
||||||
)
|
)
|
||||||
if multicraft.setting_getbool("detailed_profiling") then
|
if core.setting_getbool("detailed_profiling") then
|
||||||
if statistics.types ~= nil then
|
if statistics.types ~= nil then
|
||||||
for type,typestats in pairs(statistics.types) do
|
for type,typestats in pairs(statistics.types) do
|
||||||
|
|
||||||
|
@ -202,7 +202,7 @@ function profiling_print_log(cmd, filter)
|
||||||
type = "..." .. type:sub(-22)
|
type = "..." .. type:sub(-22)
|
||||||
end
|
end
|
||||||
|
|
||||||
multicraft.log("action",
|
core.log("action",
|
||||||
string.format(
|
string.format(
|
||||||
"%16s | %25s | %9d | %9d | %9d | %9d | %9d | %9d",
|
"%16s | %25s | %9d | %9d | %9d | %9d | %9d | %9d",
|
||||||
" ",
|
" ",
|
||||||
|
@ -220,12 +220,12 @@ function profiling_print_log(cmd, filter)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
multicraft.log("action",
|
core.log("action",
|
||||||
"-----------------+---------------------------+-----------+" ..
|
"-----------------+---------------------------+-----------+" ..
|
||||||
"-----------+-----------+-----------+-----------+-----------")
|
"-----------+-----------+-----------+-----------+-----------")
|
||||||
|
|
||||||
if filter == "" then
|
if filter == "" then
|
||||||
multicraft.log("action",
|
core.log("action",
|
||||||
string.format("%16s | %25s | %9d | %9d | %9d | %9d | %9d | %9d",
|
string.format("%16s | %25s | %9d | %9d | %9d | %9d | %9d | %9d",
|
||||||
"total",
|
"total",
|
||||||
" ",
|
" ",
|
||||||
|
@ -237,23 +237,23 @@ function profiling_print_log(cmd, filter)
|
||||||
mod_statistics.stats["total"].avg_per)
|
mod_statistics.stats["total"].avg_per)
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
multicraft.log("action", " ")
|
core.log("action", " ")
|
||||||
|
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
local function initialize_profiling()
|
local function initialize_profiling()
|
||||||
multicraft.log("action", "Initialize tracing")
|
core.log("action", "Initialize tracing")
|
||||||
|
|
||||||
mod_statistics.entity_callbacks = {}
|
mod_statistics.entity_callbacks = {}
|
||||||
|
|
||||||
-- first register our own globalstep handler
|
-- first register our own globalstep handler
|
||||||
multicraft.register_globalstep(mod_statistics.update_statistics)
|
core.register_globalstep(mod_statistics.update_statistics)
|
||||||
|
|
||||||
local rp_register_entity = multicraft.register_entity
|
local rp_register_entity = core.register_entity
|
||||||
multicraft.register_entity = function(name, prototype)
|
core.register_entity = function(name, prototype)
|
||||||
local modname = multicraft.get_current_modname()
|
local modname = core.get_current_modname()
|
||||||
local new_on_activate = nil
|
local new_on_activate = nil
|
||||||
local new_on_step = nil
|
local new_on_step = nil
|
||||||
local new_on_punch = nil
|
local new_on_punch = nil
|
||||||
|
@ -264,9 +264,9 @@ local function initialize_profiling()
|
||||||
local cbid = name .. "#oa"
|
local cbid = name .. "#oa"
|
||||||
mod_statistics.entity_callbacks[cbid] = prototype.on_activate
|
mod_statistics.entity_callbacks[cbid] = prototype.on_activate
|
||||||
new_on_activate = function(self, staticdata, dtime_s)
|
new_on_activate = function(self, staticdata, dtime_s)
|
||||||
local starttime = multicraft.get_us_time()
|
local starttime = core.get_us_time()
|
||||||
mod_statistics.entity_callbacks[cbid](self, staticdata, dtime_s)
|
mod_statistics.entity_callbacks[cbid](self, staticdata, dtime_s)
|
||||||
local delta = multicraft.get_us_time() -starttime
|
local delta = core.get_us_time() -starttime
|
||||||
mod_statistics.log_time(cbid, modname, delta)
|
mod_statistics.log_time(cbid, modname, delta)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -275,9 +275,9 @@ local function initialize_profiling()
|
||||||
local cbid = name .. "#os"
|
local cbid = name .. "#os"
|
||||||
mod_statistics.entity_callbacks[cbid] = prototype.on_step
|
mod_statistics.entity_callbacks[cbid] = prototype.on_step
|
||||||
new_on_step = function(self, dtime)
|
new_on_step = function(self, dtime)
|
||||||
local starttime = multicraft.get_us_time()
|
local starttime = core.get_us_time()
|
||||||
mod_statistics.entity_callbacks[cbid](self, dtime)
|
mod_statistics.entity_callbacks[cbid](self, dtime)
|
||||||
local delta = multicraft.get_us_time() -starttime
|
local delta = core.get_us_time() -starttime
|
||||||
mod_statistics.log_time(cbid, modname, delta)
|
mod_statistics.log_time(cbid, modname, delta)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -286,9 +286,9 @@ local function initialize_profiling()
|
||||||
local cbid = name .. "#op"
|
local cbid = name .. "#op"
|
||||||
mod_statistics.entity_callbacks[cbid] = prototype.on_punch
|
mod_statistics.entity_callbacks[cbid] = prototype.on_punch
|
||||||
new_on_punch = function(self, hitter)
|
new_on_punch = function(self, hitter)
|
||||||
local starttime = multicraft.get_us_time()
|
local starttime = core.get_us_time()
|
||||||
mod_statistics.entity_callbacks[cbid](self, hitter)
|
mod_statistics.entity_callbacks[cbid](self, hitter)
|
||||||
local delta = multicraft.get_us_time() -starttime
|
local delta = core.get_us_time() -starttime
|
||||||
mod_statistics.log_time(cbid, modname, delta)
|
mod_statistics.log_time(cbid, modname, delta)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -297,9 +297,9 @@ local function initialize_profiling()
|
||||||
local cbid = name .. "#rc"
|
local cbid = name .. "#rc"
|
||||||
mod_statistics.entity_callbacks[cbid] = prototype.rightclick
|
mod_statistics.entity_callbacks[cbid] = prototype.rightclick
|
||||||
new_rightclick = function(self, clicker)
|
new_rightclick = function(self, clicker)
|
||||||
local starttime = multicraft.get_us_time()
|
local starttime = core.get_us_time()
|
||||||
mod_statistics.entity_callbacks[cbid](self, clicker)
|
mod_statistics.entity_callbacks[cbid](self, clicker)
|
||||||
local delta = multicraft.get_us_time() -starttime
|
local delta = core.get_us_time() -starttime
|
||||||
mod_statistics.log_time(cbid, modname, delta)
|
mod_statistics.log_time(cbid, modname, delta)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -308,9 +308,9 @@ local function initialize_profiling()
|
||||||
local cbid = name .. "#gs"
|
local cbid = name .. "#gs"
|
||||||
mod_statistics.entity_callbacks[cbid] = prototype.get_staticdata
|
mod_statistics.entity_callbacks[cbid] = prototype.get_staticdata
|
||||||
new_get_staticdata = function(self)
|
new_get_staticdata = function(self)
|
||||||
local starttime = multicraft.get_us_time()
|
local starttime = core.get_us_time()
|
||||||
local retval = mod_statistics.entity_callbacks[cbid](self)
|
local retval = mod_statistics.entity_callbacks[cbid](self)
|
||||||
local delta = multicraft.get_us_time() -starttime
|
local delta = core.get_us_time() -starttime
|
||||||
mod_statistics.log_time(cbid, modname, delta)
|
mod_statistics.log_time(cbid, modname, delta)
|
||||||
return retval
|
return retval
|
||||||
end
|
end
|
||||||
|
@ -330,10 +330,10 @@ local function initialize_profiling()
|
||||||
core[v] = build_callback(v, to_replace)
|
core[v] = build_callback(v, to_replace)
|
||||||
end
|
end
|
||||||
|
|
||||||
local rp_register_abm = multicraft.register_abm
|
local rp_register_abm = core.register_abm
|
||||||
multicraft.register_abm = function(spec)
|
core.register_abm = function(spec)
|
||||||
|
|
||||||
local modname = multicraft.get_current_modname()
|
local modname = core.get_current_modname()
|
||||||
|
|
||||||
local replacement_spec = {
|
local replacement_spec = {
|
||||||
nodenames = spec.nodenames,
|
nodenames = spec.nodenames,
|
||||||
|
@ -341,16 +341,16 @@ local function initialize_profiling()
|
||||||
interval = spec.interval,
|
interval = spec.interval,
|
||||||
chance = spec.chance,
|
chance = spec.chance,
|
||||||
action = function(pos, node, active_object_count, active_object_count_wider)
|
action = function(pos, node, active_object_count, active_object_count_wider)
|
||||||
local starttime = multicraft.get_us_time()
|
local starttime = core.get_us_time()
|
||||||
spec.action(pos, node, active_object_count, active_object_count_wider)
|
spec.action(pos, node, active_object_count, active_object_count_wider)
|
||||||
local delta = multicraft.get_us_time() - starttime
|
local delta = core.get_us_time() - starttime
|
||||||
mod_statistics.log_time("abm", modname, delta)
|
mod_statistics.log_time("abm", modname, delta)
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
rp_register_abm(replacement_spec)
|
rp_register_abm(replacement_spec)
|
||||||
end
|
end
|
||||||
|
|
||||||
multicraft.log("action", "Mod profiling initialized")
|
core.log("action", "Mod profiling initialized")
|
||||||
end
|
end
|
||||||
|
|
||||||
initialize_profiling()
|
initialize_profiling()
|
||||||
|
|
|
@ -4,9 +4,9 @@
|
||||||
-- Privileges
|
-- Privileges
|
||||||
--
|
--
|
||||||
|
|
||||||
multicraft.registered_privileges = {}
|
core.registered_privileges = {}
|
||||||
|
|
||||||
function multicraft.register_privilege(name, param)
|
function core.register_privilege(name, param)
|
||||||
local function fill_defaults(def)
|
local function fill_defaults(def)
|
||||||
if def.give_to_singleplayer == nil then
|
if def.give_to_singleplayer == nil then
|
||||||
def.give_to_singleplayer = true
|
def.give_to_singleplayer = true
|
||||||
|
@ -22,32 +22,32 @@ function multicraft.register_privilege(name, param)
|
||||||
def = {description = param}
|
def = {description = param}
|
||||||
end
|
end
|
||||||
fill_defaults(def)
|
fill_defaults(def)
|
||||||
multicraft.registered_privileges[name] = def
|
core.registered_privileges[name] = def
|
||||||
end
|
end
|
||||||
|
|
||||||
multicraft.register_privilege("interact", "Can interact with things and modify the world")
|
core.register_privilege("interact", "Can interact with things and modify the world")
|
||||||
multicraft.register_privilege("teleport", "Can use /teleport command")
|
core.register_privilege("teleport", "Can use /teleport command")
|
||||||
multicraft.register_privilege("bring", "Can teleport other players")
|
core.register_privilege("bring", "Can teleport other players")
|
||||||
multicraft.register_privilege("settime", "Can use /time")
|
core.register_privilege("settime", "Can use /time")
|
||||||
multicraft.register_privilege("privs", "Can modify privileges")
|
core.register_privilege("privs", "Can modify privileges")
|
||||||
multicraft.register_privilege("basic_privs", "Can modify 'shout' and 'interact' privileges")
|
core.register_privilege("basic_privs", "Can modify 'shout' and 'interact' privileges")
|
||||||
multicraft.register_privilege("server", "Can do server maintenance stuff")
|
core.register_privilege("server", "Can do server maintenance stuff")
|
||||||
multicraft.register_privilege("shout", "Can speak in chat")
|
core.register_privilege("shout", "Can speak in chat")
|
||||||
multicraft.register_privilege("ban", "Can ban and unban players")
|
core.register_privilege("ban", "Can ban and unban players")
|
||||||
multicraft.register_privilege("kick", "Can kick players")
|
core.register_privilege("kick", "Can kick players")
|
||||||
multicraft.register_privilege("give", "Can use /give and /giveme")
|
core.register_privilege("give", "Can use /give and /giveme")
|
||||||
multicraft.register_privilege("password", "Can use /setpassword and /clearpassword")
|
core.register_privilege("password", "Can use /setpassword and /clearpassword")
|
||||||
multicraft.register_privilege("fly", {
|
core.register_privilege("fly", {
|
||||||
description = "Can fly using the free_move mode",
|
description = "Can fly using the free_move mode",
|
||||||
give_to_singleplayer = false,
|
give_to_singleplayer = false,
|
||||||
})
|
})
|
||||||
multicraft.register_privilege("fast", {
|
core.register_privilege("fast", {
|
||||||
description = "Can walk fast using the fast_move mode",
|
description = "Can walk fast using the fast_move mode",
|
||||||
give_to_singleplayer = false,
|
give_to_singleplayer = false,
|
||||||
})
|
})
|
||||||
multicraft.register_privilege("noclip", {
|
core.register_privilege("noclip", {
|
||||||
description = "Can fly through walls",
|
description = "Can fly through walls",
|
||||||
give_to_singleplayer = false,
|
give_to_singleplayer = false,
|
||||||
})
|
})
|
||||||
multicraft.register_privilege("rollback", "Can use the rollback functionality")
|
core.register_privilege("rollback", "Can use the rollback functionality")
|
||||||
|
|
||||||
|
|
|
@ -4,367 +4,364 @@
|
||||||
-- Make raw registration functions inaccessible to anyone except this file
|
-- Make raw registration functions inaccessible to anyone except this file
|
||||||
--
|
--
|
||||||
|
|
||||||
local register_item_raw = multicraft.register_item_raw
|
local register_item_raw = core.register_item_raw
|
||||||
multicraft.register_item_raw = nil
|
core.register_item_raw = nil
|
||||||
|
|
||||||
local register_alias_raw = multicraft.register_alias_raw
|
local register_alias_raw = core.register_alias_raw
|
||||||
multicraft.register_alias_raw = nil
|
core.register_alias_raw = nil
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Item / entity / ABM registration functions
|
-- Item / entity / ABM registration functions
|
||||||
--
|
--
|
||||||
|
|
||||||
multicraft.registered_abms = {}
|
core.registered_abms = {}
|
||||||
multicraft.registered_entities = {}
|
core.registered_entities = {}
|
||||||
multicraft.registered_items = {}
|
core.registered_items = {}
|
||||||
multicraft.registered_nodes = {}
|
core.registered_nodes = {}
|
||||||
multicraft.registered_craftitems = {}
|
core.registered_craftitems = {}
|
||||||
multicraft.registered_tools = {}
|
core.registered_tools = {}
|
||||||
multicraft.registered_aliases = {}
|
core.registered_aliases = {}
|
||||||
|
|
||||||
-- For tables that are indexed by item name:
|
-- For tables that are indexed by item name:
|
||||||
-- If table[X] does not exist, default to table[multicraft.registered_aliases[X]]
|
-- If table[X] does not exist, default to table[core.registered_aliases[X]]
|
||||||
local alias_metatable = {
|
local alias_metatable = {
|
||||||
__index = function(t, name)
|
__index = function(t, name)
|
||||||
return rawget(t, multicraft.registered_aliases[name])
|
return rawget(t, core.registered_aliases[name])
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
setmetatable(multicraft.registered_items, alias_metatable)
|
setmetatable(core.registered_items, alias_metatable)
|
||||||
setmetatable(multicraft.registered_nodes, alias_metatable)
|
setmetatable(core.registered_nodes, alias_metatable)
|
||||||
setmetatable(multicraft.registered_craftitems, alias_metatable)
|
setmetatable(core.registered_craftitems, alias_metatable)
|
||||||
setmetatable(multicraft.registered_tools, alias_metatable)
|
setmetatable(core.registered_tools, alias_metatable)
|
||||||
|
|
||||||
-- These item names may not be used because they would interfere
|
-- These item names may not be used because they would interfere
|
||||||
-- with legacy itemstrings
|
-- with legacy itemstrings
|
||||||
local forbidden_item_names = {
|
local forbidden_item_names = {
|
||||||
MaterialItem = true,
|
MaterialItem = true,
|
||||||
MaterialItem2 = true,
|
MaterialItem2 = true,
|
||||||
MaterialItem3 = true,
|
MaterialItem3 = true,
|
||||||
NodeItem = true,
|
NodeItem = true,
|
||||||
node = true,
|
node = true,
|
||||||
CraftItem = true,
|
CraftItem = true,
|
||||||
craft = true,
|
craft = true,
|
||||||
MBOItem = true,
|
MBOItem = true,
|
||||||
ToolItem = true,
|
ToolItem = true,
|
||||||
tool = true,
|
tool = true,
|
||||||
}
|
}
|
||||||
|
|
||||||
local function check_modname_prefix(name)
|
local function check_modname_prefix(name)
|
||||||
if name:sub(1,1) == ":" then
|
if name:sub(1,1) == ":" then
|
||||||
-- Escape the modname prefix enforcement mechanism
|
-- Escape the modname prefix enforcement mechanism
|
||||||
return name:sub(2)
|
return name:sub(2)
|
||||||
else
|
else
|
||||||
-- Modname prefix enforcement
|
-- Modname prefix enforcement
|
||||||
local expected_prefix = multicraft.get_current_modname() .. ":"
|
local expected_prefix = core.get_current_modname() .. ":"
|
||||||
if name:sub(1, #expected_prefix) ~= expected_prefix then
|
if name:sub(1, #expected_prefix) ~= expected_prefix then
|
||||||
error("Name " .. name .. " does not follow naming conventions: " ..
|
error("Name " .. name .. " does not follow naming conventions: " ..
|
||||||
"\"modname:\" or \":\" prefix required")
|
"\"modname:\" or \":\" prefix required")
|
||||||
end
|
end
|
||||||
local subname = name:sub(#expected_prefix+1)
|
local subname = name:sub(#expected_prefix+1)
|
||||||
if subname:find("[^abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_]") then
|
if subname:find("[^abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_]") then
|
||||||
error("Name " .. name .. " does not follow naming conventions: " ..
|
error("Name " .. name .. " does not follow naming conventions: " ..
|
||||||
"contains unallowed characters")
|
"contains unallowed characters")
|
||||||
end
|
end
|
||||||
return name
|
return name
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function multicraft.register_abm(spec)
|
function core.register_abm(spec)
|
||||||
-- Add to multicraft.registered_abms
|
-- Add to core.registered_abms
|
||||||
multicraft.registered_abms[#multicraft.registered_abms+1] = spec
|
core.registered_abms[#core.registered_abms+1] = spec
|
||||||
end
|
end
|
||||||
|
|
||||||
function multicraft.register_entity(name, prototype)
|
function core.register_entity(name, prototype)
|
||||||
-- Check name
|
-- Check name
|
||||||
if name == nil then
|
if name == nil then
|
||||||
error("Unable to register entity: Name is nil")
|
error("Unable to register entity: Name is nil")
|
||||||
end
|
end
|
||||||
name = check_modname_prefix(tostring(name))
|
name = check_modname_prefix(tostring(name))
|
||||||
|
|
||||||
prototype.name = name
|
prototype.name = name
|
||||||
prototype.__index = prototype -- so that it can be used as a metatable
|
prototype.__index = prototype -- so that it can be used as a metatable
|
||||||
|
|
||||||
-- Add to multicraft.registered_entities
|
-- Add to core.registered_entities
|
||||||
multicraft.registered_entities[name] = prototype
|
core.registered_entities[name] = prototype
|
||||||
end
|
end
|
||||||
|
|
||||||
function multicraft.register_item(name, itemdef)
|
function core.register_item(name, itemdef)
|
||||||
-- Check name
|
-- Check name
|
||||||
if name == nil then
|
if name == nil then
|
||||||
error("Unable to register item: Name is nil")
|
error("Unable to register item: Name is nil")
|
||||||
end
|
end
|
||||||
name = check_modname_prefix(tostring(name))
|
name = check_modname_prefix(tostring(name))
|
||||||
if forbidden_item_names[name] then
|
if forbidden_item_names[name] then
|
||||||
error("Unable to register item: Name is forbidden: " .. name)
|
error("Unable to register item: Name is forbidden: " .. name)
|
||||||
end
|
end
|
||||||
itemdef.name = name
|
itemdef.name = name
|
||||||
|
|
||||||
-- Apply defaults and add to registered_* table
|
-- Apply defaults and add to registered_* table
|
||||||
if itemdef.type == "node" then
|
if itemdef.type == "node" then
|
||||||
-- Use the nodebox as selection box if it's not set manually
|
-- Use the nodebox as selection box if it's not set manually
|
||||||
if itemdef.drawtype == "nodebox" and not itemdef.selection_box then
|
if itemdef.drawtype == "nodebox" and not itemdef.selection_box then
|
||||||
itemdef.selection_box = itemdef.node_box
|
itemdef.selection_box = itemdef.node_box
|
||||||
elseif itemdef.drawtype == "fencelike" and not itemdef.selection_box then
|
elseif itemdef.drawtype == "fencelike" and not itemdef.selection_box then
|
||||||
itemdef.selection_box = {
|
itemdef.selection_box = {
|
||||||
type = "fixed",
|
type = "fixed",
|
||||||
fixed = {-1/8, -1/2, -1/8, 1/8, 1/2, 1/8},
|
fixed = {-1/8, -1/2, -1/8, 1/8, 1/2, 1/8},
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
setmetatable(itemdef, {__index = multicraft.nodedef_default})
|
setmetatable(itemdef, {__index = core.nodedef_default})
|
||||||
multicraft.registered_nodes[itemdef.name] = itemdef
|
core.registered_nodes[itemdef.name] = itemdef
|
||||||
elseif itemdef.type == "craft" then
|
elseif itemdef.type == "craft" then
|
||||||
setmetatable(itemdef, {__index = multicraft.craftitemdef_default})
|
setmetatable(itemdef, {__index = core.craftitemdef_default})
|
||||||
multicraft.registered_craftitems[itemdef.name] = itemdef
|
core.registered_craftitems[itemdef.name] = itemdef
|
||||||
elseif itemdef.type == "tool" then
|
elseif itemdef.type == "tool" then
|
||||||
setmetatable(itemdef, {__index = multicraft.tooldef_default})
|
setmetatable(itemdef, {__index = core.tooldef_default})
|
||||||
multicraft.registered_tools[itemdef.name] = itemdef
|
core.registered_tools[itemdef.name] = itemdef
|
||||||
elseif itemdef.type == "none" then
|
elseif itemdef.type == "none" then
|
||||||
setmetatable(itemdef, {__index = multicraft.noneitemdef_default})
|
setmetatable(itemdef, {__index = core.noneitemdef_default})
|
||||||
else
|
else
|
||||||
error("Unable to register item: Type is invalid: " .. dump(itemdef))
|
error("Unable to register item: Type is invalid: " .. dump(itemdef))
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Flowing liquid uses param2
|
-- Flowing liquid uses param2
|
||||||
if itemdef.type == "node" and itemdef.liquidtype == "flowing" and itemdef.paramtype2 == nil then
|
if itemdef.type == "node" and itemdef.liquidtype == "flowing" then
|
||||||
itemdef.paramtype2 = "flowingliquid"
|
itemdef.paramtype2 = "flowingliquid"
|
||||||
end
|
end
|
||||||
|
|
||||||
-- BEGIN Legacy stuff
|
-- BEGIN Legacy stuff
|
||||||
if itemdef.cookresult_itemstring ~= nil and itemdef.cookresult_itemstring ~= "" then
|
if itemdef.cookresult_itemstring ~= nil and itemdef.cookresult_itemstring ~= "" then
|
||||||
multicraft.register_craft({
|
core.register_craft({
|
||||||
type="cooking",
|
type="cooking",
|
||||||
output=itemdef.cookresult_itemstring,
|
output=itemdef.cookresult_itemstring,
|
||||||
recipe=itemdef.name,
|
recipe=itemdef.name,
|
||||||
cooktime=itemdef.furnace_cooktime
|
cooktime=itemdef.furnace_cooktime
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
if itemdef.furnace_burntime ~= nil and itemdef.furnace_burntime >= 0 then
|
if itemdef.furnace_burntime ~= nil and itemdef.furnace_burntime >= 0 then
|
||||||
multicraft.register_craft({
|
core.register_craft({
|
||||||
type="fuel",
|
type="fuel",
|
||||||
recipe=itemdef.name,
|
recipe=itemdef.name,
|
||||||
burntime=itemdef.furnace_burntime
|
burntime=itemdef.furnace_burntime
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
-- END Legacy stuff
|
-- END Legacy stuff
|
||||||
|
|
||||||
-- Disable all further modifications
|
-- Disable all further modifications
|
||||||
getmetatable(itemdef).__newindex = {}
|
getmetatable(itemdef).__newindex = {}
|
||||||
|
|
||||||
--multicraft.log("Registering item: " .. itemdef.name)
|
--core.log("Registering item: " .. itemdef.name)
|
||||||
multicraft.registered_items[itemdef.name] = itemdef
|
core.registered_items[itemdef.name] = itemdef
|
||||||
multicraft.registered_aliases[itemdef.name] = nil
|
core.registered_aliases[itemdef.name] = nil
|
||||||
register_item_raw(itemdef)
|
register_item_raw(itemdef)
|
||||||
end
|
end
|
||||||
|
|
||||||
function multicraft.register_node(name, nodedef)
|
function core.register_node(name, nodedef)
|
||||||
nodedef.type = "node"
|
nodedef.type = "node"
|
||||||
multicraft.register_item(name, nodedef)
|
core.register_item(name, nodedef)
|
||||||
end
|
end
|
||||||
|
|
||||||
function multicraft.register_craftitem(name, craftitemdef)
|
function core.register_craftitem(name, craftitemdef)
|
||||||
craftitemdef.type = "craft"
|
craftitemdef.type = "craft"
|
||||||
|
|
||||||
-- BEGIN Legacy stuff
|
-- BEGIN Legacy stuff
|
||||||
if craftitemdef.inventory_image == nil and craftitemdef.image ~= nil then
|
if craftitemdef.inventory_image == nil and craftitemdef.image ~= nil then
|
||||||
craftitemdef.inventory_image = craftitemdef.image
|
craftitemdef.inventory_image = craftitemdef.image
|
||||||
end
|
end
|
||||||
-- END Legacy stuff
|
-- END Legacy stuff
|
||||||
|
|
||||||
multicraft.register_item(name, craftitemdef)
|
core.register_item(name, craftitemdef)
|
||||||
end
|
end
|
||||||
|
|
||||||
function multicraft.register_tool(name, tooldef)
|
function core.register_tool(name, tooldef)
|
||||||
tooldef.type = "tool"
|
tooldef.type = "tool"
|
||||||
tooldef.stack_max = 1
|
tooldef.stack_max = 1
|
||||||
|
|
||||||
-- BEGIN Legacy stuff
|
-- BEGIN Legacy stuff
|
||||||
if tooldef.inventory_image == nil and tooldef.image ~= nil then
|
if tooldef.inventory_image == nil and tooldef.image ~= nil then
|
||||||
tooldef.inventory_image = tooldef.image
|
tooldef.inventory_image = tooldef.image
|
||||||
end
|
end
|
||||||
if tooldef.tool_capabilities == nil and
|
if tooldef.tool_capabilities == nil and
|
||||||
(tooldef.full_punch_interval ~= nil or
|
(tooldef.full_punch_interval ~= nil or
|
||||||
tooldef.basetime ~= nil or
|
tooldef.basetime ~= nil or
|
||||||
tooldef.dt_weight ~= nil or
|
tooldef.dt_weight ~= nil or
|
||||||
tooldef.dt_crackiness ~= nil or
|
tooldef.dt_crackiness ~= nil or
|
||||||
tooldef.dt_crumbliness ~= nil or
|
tooldef.dt_crumbliness ~= nil or
|
||||||
tooldef.dt_cuttability ~= nil or
|
tooldef.dt_cuttability ~= nil or
|
||||||
tooldef.basedurability ~= nil or
|
tooldef.basedurability ~= nil or
|
||||||
tooldef.dd_weight ~= nil or
|
tooldef.dd_weight ~= nil or
|
||||||
tooldef.dd_crackiness ~= nil or
|
tooldef.dd_crackiness ~= nil or
|
||||||
tooldef.dd_crumbliness ~= nil or
|
tooldef.dd_crumbliness ~= nil or
|
||||||
tooldef.dd_cuttability ~= nil) then
|
tooldef.dd_cuttability ~= nil) then
|
||||||
tooldef.tool_capabilities = {
|
tooldef.tool_capabilities = {
|
||||||
full_punch_interval = tooldef.full_punch_interval,
|
full_punch_interval = tooldef.full_punch_interval,
|
||||||
basetime = tooldef.basetime,
|
basetime = tooldef.basetime,
|
||||||
dt_weight = tooldef.dt_weight,
|
dt_weight = tooldef.dt_weight,
|
||||||
dt_crackiness = tooldef.dt_crackiness,
|
dt_crackiness = tooldef.dt_crackiness,
|
||||||
dt_crumbliness = tooldef.dt_crumbliness,
|
dt_crumbliness = tooldef.dt_crumbliness,
|
||||||
dt_cuttability = tooldef.dt_cuttability,
|
dt_cuttability = tooldef.dt_cuttability,
|
||||||
basedurability = tooldef.basedurability,
|
basedurability = tooldef.basedurability,
|
||||||
dd_weight = tooldef.dd_weight,
|
dd_weight = tooldef.dd_weight,
|
||||||
dd_crackiness = tooldef.dd_crackiness,
|
dd_crackiness = tooldef.dd_crackiness,
|
||||||
dd_crumbliness = tooldef.dd_crumbliness,
|
dd_crumbliness = tooldef.dd_crumbliness,
|
||||||
dd_cuttability = tooldef.dd_cuttability,
|
dd_cuttability = tooldef.dd_cuttability,
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
-- END Legacy stuff
|
-- END Legacy stuff
|
||||||
|
|
||||||
multicraft.register_item(name, tooldef)
|
core.register_item(name, tooldef)
|
||||||
end
|
end
|
||||||
|
|
||||||
function multicraft.register_alias(name, convert_to)
|
function core.register_alias(name, convert_to)
|
||||||
if forbidden_item_names[name] then
|
if forbidden_item_names[name] then
|
||||||
error("Unable to register alias: Name is forbidden: " .. name)
|
error("Unable to register alias: Name is forbidden: " .. name)
|
||||||
end
|
end
|
||||||
if multicraft.registered_items[name] ~= nil then
|
if core.registered_items[name] ~= nil then
|
||||||
multicraft.log("WARNING: Not registering alias, item with same name" ..
|
core.log("WARNING: Not registering alias, item with same name" ..
|
||||||
" is already defined: " .. name .. " -> " .. convert_to)
|
" is already defined: " .. name .. " -> " .. convert_to)
|
||||||
else
|
else
|
||||||
--multicraft.log("Registering alias: " .. name .. " -> " .. convert_to)
|
--core.log("Registering alias: " .. name .. " -> " .. convert_to)
|
||||||
multicraft.registered_aliases[name] = convert_to
|
core.registered_aliases[name] = convert_to
|
||||||
register_alias_raw(name, convert_to)
|
register_alias_raw(name, convert_to)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function multicraft.on_craft(itemstack, player, old_craft_list, craft_inv)
|
function core.on_craft(itemstack, player, old_craft_list, craft_inv)
|
||||||
for _, func in ipairs(multicraft.registered_on_crafts) do
|
for _, func in ipairs(core.registered_on_crafts) do
|
||||||
itemstack = func(itemstack, player, old_craft_list, craft_inv) or itemstack
|
itemstack = func(itemstack, player, old_craft_list, craft_inv) or itemstack
|
||||||
end
|
end
|
||||||
return itemstack
|
return itemstack
|
||||||
end
|
end
|
||||||
|
|
||||||
function multicraft.craft_predict(itemstack, player, old_craft_list, craft_inv)
|
function core.craft_predict(itemstack, player, old_craft_list, craft_inv)
|
||||||
for _, func in ipairs(multicraft.registered_craft_predicts) do
|
for _, func in ipairs(core.registered_craft_predicts) do
|
||||||
itemstack = func(itemstack, player, old_craft_list, craft_inv) or itemstack
|
itemstack = func(itemstack, player, old_craft_list, craft_inv) or itemstack
|
||||||
end
|
end
|
||||||
return itemstack
|
return itemstack
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Alias the forbidden item names to "" so they can't be
|
-- Alias the forbidden item names to "" so they can't be
|
||||||
-- created via itemstrings (e.g. /give)
|
-- created via itemstrings (e.g. /give)
|
||||||
local name
|
local name
|
||||||
for name in pairs(forbidden_item_names) do
|
for name in pairs(forbidden_item_names) do
|
||||||
multicraft.registered_aliases[name] = ""
|
core.registered_aliases[name] = ""
|
||||||
register_alias_raw(name, "")
|
register_alias_raw(name, "")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
-- Deprecated:
|
-- Deprecated:
|
||||||
-- Aliases for multicraft.register_alias (how ironic...)
|
-- Aliases for core.register_alias (how ironic...)
|
||||||
--multicraft.alias_node = multicraft.register_alias
|
--core.alias_node = core.register_alias
|
||||||
--multicraft.alias_tool = multicraft.register_alias
|
--core.alias_tool = core.register_alias
|
||||||
--multicraft.alias_craftitem = multicraft.register_alias
|
--core.alias_craftitem = core.register_alias
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Built-in node definitions. Also defined in C.
|
-- Built-in node definitions. Also defined in C.
|
||||||
--
|
--
|
||||||
|
|
||||||
multicraft.register_item(":unknown", {
|
core.register_item(":unknown", {
|
||||||
type = "none",
|
type = "none",
|
||||||
walkable = true,
|
description = "Unknown Item",
|
||||||
description = "Unknown Item",
|
inventory_image = "unknown_item.png",
|
||||||
tiles = {"trans.png"},
|
on_place = core.item_place,
|
||||||
inventory_image = "unknown_item.png",
|
on_drop = core.item_drop,
|
||||||
on_place = multicraft.item_place,
|
groups = {not_in_creative_inventory=1},
|
||||||
on_drop = multicraft.item_drop,
|
diggable = true,
|
||||||
groups = {not_in_creative_inventory=1},
|
|
||||||
diggable = true,
|
|
||||||
pointable = false,
|
|
||||||
})
|
})
|
||||||
|
|
||||||
multicraft.register_node(":air", {
|
core.register_node(":air", {
|
||||||
description = "Air (you hacker you!)",
|
description = "Air (you hacker you!)",
|
||||||
inventory_image = "unknown_node.png",
|
inventory_image = "unknown_node.png",
|
||||||
wield_image = "unknown_node.png",
|
wield_image = "unknown_node.png",
|
||||||
drawtype = "airlike",
|
drawtype = "airlike",
|
||||||
paramtype = "light",
|
paramtype = "light",
|
||||||
sunlight_propagates = true,
|
sunlight_propagates = true,
|
||||||
walkable = false,
|
walkable = false,
|
||||||
pointable = false,
|
pointable = false,
|
||||||
diggable = false,
|
diggable = false,
|
||||||
buildable_to = true,
|
buildable_to = true,
|
||||||
air_equivalent = true,
|
air_equivalent = true,
|
||||||
drop = "",
|
drop = "",
|
||||||
groups = {not_in_creative_inventory=1},
|
groups = {not_in_creative_inventory=1},
|
||||||
})
|
})
|
||||||
|
|
||||||
multicraft.register_node(":ignore", {
|
core.register_node(":ignore", {
|
||||||
description = "Ignore (you hacker you!)",
|
description = "Ignore (you hacker you!)",
|
||||||
inventory_image = "unknown_node.png",
|
inventory_image = "unknown_node.png",
|
||||||
wield_image = "unknown_node.png",
|
wield_image = "unknown_node.png",
|
||||||
drawtype = "airlike",
|
drawtype = "airlike",
|
||||||
paramtype = "none",
|
paramtype = "none",
|
||||||
sunlight_propagates = false,
|
sunlight_propagates = false,
|
||||||
walkable = false,
|
walkable = false,
|
||||||
pointable = false,
|
pointable = false,
|
||||||
diggable = false,
|
diggable = false,
|
||||||
buildable_to = true, -- A way to remove accidentally placed ignores
|
buildable_to = true, -- A way to remove accidentally placed ignores
|
||||||
air_equivalent = true,
|
air_equivalent = true,
|
||||||
drop = "",
|
drop = "",
|
||||||
groups = {not_in_creative_inventory=1},
|
groups = {not_in_creative_inventory=1},
|
||||||
})
|
})
|
||||||
|
|
||||||
-- The hand (bare definition)
|
-- The hand (bare definition)
|
||||||
multicraft.register_item(":", {
|
core.register_item(":", {
|
||||||
type = "none",
|
type = "none",
|
||||||
groups = {not_in_creative_inventory=1},
|
groups = {not_in_creative_inventory=1},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
function multicraft.override_item(name, redefinition)
|
function core.override_item(name, redefinition)
|
||||||
if redefinition.name ~= nil then
|
if redefinition.name ~= nil then
|
||||||
error("Attempt to redefine name of "..name.." to "..dump(redefinition.name), 2)
|
error("Attempt to redefine name of "..name.." to "..dump(redefinition.name), 2)
|
||||||
end
|
end
|
||||||
if redefinition.type ~= nil then
|
if redefinition.type ~= nil then
|
||||||
error("Attempt to redefine type of "..name.." to "..dump(redefinition.type), 2)
|
error("Attempt to redefine type of "..name.." to "..dump(redefinition.type), 2)
|
||||||
end
|
end
|
||||||
local item = multicraft.registered_items[name]
|
local item = core.registered_items[name]
|
||||||
if not item then
|
if not item then
|
||||||
error("Attempt to override non-existent item "..name, 2)
|
error("Attempt to override non-existent item "..name, 2)
|
||||||
end
|
end
|
||||||
for k, v in pairs(redefinition) do
|
for k, v in pairs(redefinition) do
|
||||||
rawset(item, k, v)
|
rawset(item, k, v)
|
||||||
end
|
end
|
||||||
register_item_raw(item)
|
register_item_raw(item)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function multicraft.run_callbacks(callbacks, mode, ...)
|
function core.run_callbacks(callbacks, mode, ...)
|
||||||
assert(type(callbacks) == "table")
|
assert(type(callbacks) == "table")
|
||||||
local cb_len = #callbacks
|
local cb_len = #callbacks
|
||||||
if cb_len == 0 then
|
if cb_len == 0 then
|
||||||
if mode == 2 or mode == 3 then
|
if mode == 2 or mode == 3 then
|
||||||
return true
|
return true
|
||||||
elseif mode == 4 or mode == 5 then
|
elseif mode == 4 or mode == 5 then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
local ret = nil
|
local ret = nil
|
||||||
for i = 1, cb_len do
|
for i = 1, cb_len do
|
||||||
local cb_ret = callbacks[i](...)
|
local cb_ret = callbacks[i](...)
|
||||||
|
|
||||||
if mode == 0 and i == 1 then
|
if mode == 0 and i == 1 then
|
||||||
ret = cb_ret
|
ret = cb_ret
|
||||||
elseif mode == 1 and i == cb_len then
|
elseif mode == 1 and i == cb_len then
|
||||||
ret = cb_ret
|
ret = cb_ret
|
||||||
elseif mode == 2 then
|
elseif mode == 2 then
|
||||||
if not cb_ret or i == 1 then
|
if not cb_ret or i == 1 then
|
||||||
ret = cb_ret
|
ret = cb_ret
|
||||||
end
|
end
|
||||||
elseif mode == 3 then
|
elseif mode == 3 then
|
||||||
if cb_ret then
|
if cb_ret then
|
||||||
return cb_ret
|
return cb_ret
|
||||||
end
|
end
|
||||||
ret = cb_ret
|
ret = cb_ret
|
||||||
elseif mode == 4 then
|
elseif mode == 4 then
|
||||||
if (cb_ret and not ret) or i == 1 then
|
if (cb_ret and not ret) or i == 1 then
|
||||||
ret = cb_ret
|
ret = cb_ret
|
||||||
end
|
end
|
||||||
elseif mode == 5 and cb_ret then
|
elseif mode == 5 and cb_ret then
|
||||||
return cb_ret
|
return cb_ret
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return ret
|
return ret
|
||||||
end
|
end
|
||||||
|
|
||||||
--
|
--
|
||||||
|
@ -372,104 +369,73 @@ end
|
||||||
--
|
--
|
||||||
|
|
||||||
local function make_registration()
|
local function make_registration()
|
||||||
local t = {}
|
local t = {}
|
||||||
local registerfunc = function(func) table.insert(t, func) end
|
local registerfunc = function(func) table.insert(t, func) end
|
||||||
return t, registerfunc
|
return t, registerfunc
|
||||||
end
|
end
|
||||||
|
|
||||||
local function make_registration_reverse()
|
local function make_registration_reverse()
|
||||||
local t = {}
|
local t = {}
|
||||||
local registerfunc = function(func) table.insert(t, 1, func) end
|
local registerfunc = function(func) table.insert(t, 1, func) end
|
||||||
return t, registerfunc
|
return t, registerfunc
|
||||||
end
|
end
|
||||||
|
|
||||||
local function make_registration_wrap(reg_fn_name, clear_fn_name)
|
local function make_registration_wrap(reg_fn_name, clear_fn_name)
|
||||||
local list = {}
|
local list = {}
|
||||||
|
|
||||||
local orig_reg_fn = core[reg_fn_name]
|
local orig_reg_fn = core[reg_fn_name]
|
||||||
core[reg_fn_name] = function(def)
|
core[reg_fn_name] = function(def)
|
||||||
local retval = orig_reg_fn(def)
|
local retval = orig_reg_fn(def)
|
||||||
if retval ~= nil then
|
if retval ~= nil then
|
||||||
if def.name ~= nil then
|
if def.name ~= nil then
|
||||||
list[def.name] = def
|
list[def.name] = def
|
||||||
else
|
else
|
||||||
list[retval] = def
|
list[retval] = def
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return retval
|
return retval
|
||||||
end
|
end
|
||||||
|
|
||||||
local orig_clear_fn = core[clear_fn_name]
|
local orig_clear_fn = core[clear_fn_name]
|
||||||
core[clear_fn_name] = function()
|
core[clear_fn_name] = function()
|
||||||
list = {}
|
for k in pairs(list) do
|
||||||
return orig_clear_fn()
|
list[k] = nil
|
||||||
end
|
end
|
||||||
|
return orig_clear_fn()
|
||||||
|
end
|
||||||
|
|
||||||
return list
|
return list
|
||||||
end
|
end
|
||||||
|
|
||||||
multicraft.registered_biomes = make_registration_wrap("register_biome", "clear_registered_biomes")
|
core.registered_biomes = make_registration_wrap("register_biome", "clear_registered_biomes")
|
||||||
multicraft.registered_ores = make_registration_wrap("register_ore", "clear_registered_ores")
|
core.registered_ores = make_registration_wrap("register_ore", "clear_registered_ores")
|
||||||
multicraft.registered_decorations = make_registration_wrap("register_decoration", "clear_registered_decorations")
|
core.registered_decorations = make_registration_wrap("register_decoration", "clear_registered_decorations")
|
||||||
|
|
||||||
multicraft.registered_on_chat_messages, multicraft.register_on_chat_message = make_registration()
|
core.registered_on_chat_messages, core.register_on_chat_message = make_registration()
|
||||||
multicraft.registered_globalsteps, multicraft.register_globalstep = make_registration()
|
core.registered_globalsteps, core.register_globalstep = make_registration()
|
||||||
multicraft.registered_playerevents, multicraft.register_playerevent = make_registration()
|
core.registered_playerevents, core.register_playerevent = make_registration()
|
||||||
multicraft.registered_on_shutdown, multicraft.register_on_shutdown = make_registration()
|
core.registered_on_shutdown, core.register_on_shutdown = make_registration()
|
||||||
multicraft.registered_on_punchnodes, multicraft.register_on_punchnode = make_registration()
|
core.registered_on_punchnodes, core.register_on_punchnode = make_registration()
|
||||||
multicraft.registered_on_placenodes, multicraft.register_on_placenode = make_registration()
|
core.registered_on_placenodes, core.register_on_placenode = make_registration()
|
||||||
multicraft.registered_on_dignodes, multicraft.register_on_dignode = make_registration()
|
core.registered_on_dignodes, core.register_on_dignode = make_registration()
|
||||||
multicraft.registered_on_generateds, multicraft.register_on_generated = make_registration()
|
core.registered_on_generateds, core.register_on_generated = make_registration()
|
||||||
multicraft.registered_on_newplayers, multicraft.register_on_newplayer = make_registration()
|
core.registered_on_newplayers, core.register_on_newplayer = make_registration()
|
||||||
multicraft.registered_on_open_inventories, multicraft.register_on_open_inventory = make_registration()
|
core.registered_on_dieplayers, core.register_on_dieplayer = make_registration()
|
||||||
multicraft.registered_on_dieplayers, multicraft.register_on_dieplayer = make_registration()
|
core.registered_on_respawnplayers, core.register_on_respawnplayer = make_registration()
|
||||||
multicraft.registered_on_respawnplayers, multicraft.register_on_respawnplayer = make_registration()
|
core.registered_on_prejoinplayers, core.register_on_prejoinplayer = make_registration()
|
||||||
multicraft.registered_on_prejoinplayers, multicraft.register_on_prejoinplayer = make_registration()
|
core.registered_on_joinplayers, core.register_on_joinplayer = make_registration()
|
||||||
multicraft.registered_on_joinplayers, multicraft.register_on_joinplayer = make_registration()
|
core.registered_on_leaveplayers, core.register_on_leaveplayer = make_registration()
|
||||||
multicraft.registered_on_leaveplayers, multicraft.register_on_leaveplayer = make_registration()
|
core.registered_on_player_receive_fields, core.register_on_player_receive_fields = make_registration_reverse()
|
||||||
multicraft.registered_on_player_receive_fields, multicraft.register_on_player_receive_fields = make_registration_reverse()
|
core.registered_on_cheats, core.register_on_cheat = make_registration()
|
||||||
multicraft.registered_on_cheats, multicraft.register_on_cheat = make_registration()
|
core.registered_on_crafts, core.register_on_craft = make_registration()
|
||||||
multicraft.registered_on_crafts, multicraft.register_on_craft = make_registration()
|
core.registered_craft_predicts, core.register_craft_predict = make_registration()
|
||||||
multicraft.registered_craft_predicts, multicraft.register_craft_predict = make_registration()
|
core.registered_on_protection_violation, core.register_on_protection_violation = make_registration()
|
||||||
multicraft.registered_on_protection_violation, multicraft.register_on_protection_violation = make_registration()
|
core.registered_on_item_eats, core.register_on_item_eat = make_registration()
|
||||||
multicraft.registered_on_item_eats, multicraft.register_on_item_eat = make_registration()
|
core.registered_on_punchplayers, core.register_on_punchplayer = make_registration()
|
||||||
multicraft.registered_on_punchplayers, multicraft.register_on_punchplayer = make_registration()
|
|
||||||
|
|
||||||
multicraft.register_on_joinplayer(function(player)
|
|
||||||
if multicraft.is_singleplayer() then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
local player_name = player:get_player_name()
|
|
||||||
multicraft.chat_send_all("*** " .. player_name .. " joined the game.")
|
|
||||||
end)
|
|
||||||
|
|
||||||
multicraft.register_on_dieplayer(function(player)
|
|
||||||
local player_name = player:get_player_name()
|
|
||||||
if multicraft.is_singleplayer() then
|
|
||||||
player_name = "You"
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Idea from https://github.com/4Evergreen4/death_messages
|
|
||||||
-- Death by lava
|
|
||||||
local nodename = multicraft.get_node(player:getpos()).name
|
|
||||||
if nodename == "default:lava_source" or nodename == "default:lava_flowing" then
|
|
||||||
multicraft.chat_send_all(player_name .. " melted into a ball of fire.")
|
|
||||||
-- Death by drowning
|
|
||||||
elseif nodename == "default:water_source" or nodename == "default:water_flowing" then
|
|
||||||
multicraft.chat_send_all(player_name .. " ran out of air.")
|
|
||||||
--Death by fire
|
|
||||||
elseif nodename == "fire:basic_flame" then
|
|
||||||
multicraft.chat_send_all(player_name .. " burned up.")
|
|
||||||
--Death by something else
|
|
||||||
else
|
|
||||||
multicraft.chat_send_all(player_name .. " died.")
|
|
||||||
end
|
|
||||||
|
|
||||||
end)
|
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Compatibility for on_mapgen_init()
|
-- Compatibility for on_mapgen_init()
|
||||||
--
|
--
|
||||||
|
|
||||||
multicraft.register_on_mapgen_init = function(func) func(multicraft.get_mapgen_params()) end
|
core.register_on_mapgen_init = function(func) func(core.get_mapgen_params()) end
|
||||||
|
|
||||||
|
|
|
@ -1,75 +0,0 @@
|
||||||
-- TODO: move this function to builtin/common/misc_helpers.lua
|
|
||||||
--
|
|
||||||
-- Formats numbers according to SI multiplies and
|
|
||||||
-- appends a correspending prefix symbol (e.g. 1234000 -> 1.234 M)
|
|
||||||
function string.number_to_si(value, precision)
|
|
||||||
precision = precision or 3
|
|
||||||
local symbol = { "Y", "Z", "E", "P", "T", "G", "M", "k" }
|
|
||||||
local multiplies = { 10^24, 10^21, 10^18, 10^15, 10^12, 10^9, 10^6, 10^3 }
|
|
||||||
|
|
||||||
local abs_value = math.abs(value)
|
|
||||||
for k,v in ipairs(multiplies) do
|
|
||||||
if abs_value >= v then
|
|
||||||
return string.format("%."..precision.."f "..symbol[k], value / v)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return math.ceil(value)
|
|
||||||
end
|
|
||||||
|
|
||||||
-- returns formspec with table of stats
|
|
||||||
function multicraft.stat_formspec(name)
|
|
||||||
local stat_table = {
|
|
||||||
chat = "Messages",
|
|
||||||
craft = "Crafted",
|
|
||||||
damage = "Damage",
|
|
||||||
die = "Deaths",
|
|
||||||
dig = "Digged",
|
|
||||||
drop = "Dropped",
|
|
||||||
join = "Join",
|
|
||||||
move = "Traveled",
|
|
||||||
place = "Placed",
|
|
||||||
punch = "Punches",
|
|
||||||
use = "Uses",
|
|
||||||
}
|
|
||||||
|
|
||||||
local formspec
|
|
||||||
local y = -.1
|
|
||||||
|
|
||||||
if multicraft.is_singleplayer() then
|
|
||||||
-- collumns
|
|
||||||
local x = { .25, 1.8 }
|
|
||||||
formspec = "size[3.2,4.6]"
|
|
||||||
.."label["..x[1]..","..y..";Stat]"
|
|
||||||
.."label["..x[2]..","..y..";Value]"
|
|
||||||
.."label[-.25,"..(y+0.1)..";"..string.rep("_", 45).."]"
|
|
||||||
y = y + 0.2
|
|
||||||
for key, eng_name in pairs(stat_table) do
|
|
||||||
-- leading
|
|
||||||
y = y + 0.4
|
|
||||||
formspec = formspec
|
|
||||||
.."label["..x[1]..","..y..";"..eng_name.."]"
|
|
||||||
.."label["..x[2]..","..y..";"
|
|
||||||
..string.number_to_si(multicraft.stat_get("player|"..key.."|"..name)).."]"
|
|
||||||
end
|
|
||||||
else
|
|
||||||
-- collumns
|
|
||||||
local x = { .25, 1.8, 3.5 }
|
|
||||||
formspec = "size[4.9,4.6]"
|
|
||||||
.."label["..x[1]..","..y..";Stat]"
|
|
||||||
.."label["..x[2]..","..y..";Player]"
|
|
||||||
.."label["..x[3]..","..y..";Total]"
|
|
||||||
.."label[-.25,"..(y+0.1)..";"..string.rep("_", 60).."]"
|
|
||||||
y = y + 0.2
|
|
||||||
for key, eng_name in pairs(stat_table) do
|
|
||||||
-- leading
|
|
||||||
y = y + 0.4
|
|
||||||
formspec = formspec
|
|
||||||
.."label["..x[1]..","..y..";"..eng_name.."]"
|
|
||||||
.."label["..x[2]..","..y..";"
|
|
||||||
..string.number_to_si(multicraft.stat_get("player|"..key.."|"..name)).."]"
|
|
||||||
.."label["..x[3]..","..y..";"
|
|
||||||
..string.number_to_si(multicraft.stat_get("total|"..key), 4).."]"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return formspec
|
|
||||||
end
|
|
|
@ -43,7 +43,7 @@ local function initialize_builtin_statbars(player)
|
||||||
end
|
end
|
||||||
|
|
||||||
if player:hud_get_flags().healthbar and
|
if player:hud_get_flags().healthbar and
|
||||||
multicraft.is_yes(multicraft.setting_get("enable_damage")) then
|
core.is_yes(core.setting_get("enable_damage")) then
|
||||||
if hud_ids[name].id_healthbar == nil then
|
if hud_ids[name].id_healthbar == nil then
|
||||||
health_bar_definition.number = player:get_hp()
|
health_bar_definition.number = player:get_hp()
|
||||||
hud_ids[name].id_healthbar = player:hud_add(health_bar_definition)
|
hud_ids[name].id_healthbar = player:hud_add(health_bar_definition)
|
||||||
|
@ -57,7 +57,7 @@ local function initialize_builtin_statbars(player)
|
||||||
|
|
||||||
if (player:get_breath() < 11) then
|
if (player:get_breath() < 11) then
|
||||||
if player:hud_get_flags().breathbar and
|
if player:hud_get_flags().breathbar and
|
||||||
multicraft.is_yes(multicraft.setting_get("enable_damage")) then
|
core.is_yes(core.setting_get("enable_damage")) then
|
||||||
if hud_ids[name].id_breathbar == nil then
|
if hud_ids[name].id_breathbar == nil then
|
||||||
hud_ids[name].id_breathbar = player:hud_add(breath_bar_definition)
|
hud_ids[name].id_breathbar = player:hud_add(breath_bar_definition)
|
||||||
end
|
end
|
||||||
|
@ -123,7 +123,7 @@ local function player_event_handler(player,eventname)
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
function multicraft.hud_replace_builtin(name, definition)
|
function core.hud_replace_builtin(name, definition)
|
||||||
|
|
||||||
if definition == nil or
|
if definition == nil or
|
||||||
type(definition) ~= "table" or
|
type(definition) ~= "table" or
|
||||||
|
@ -135,7 +135,7 @@ function multicraft.hud_replace_builtin(name, definition)
|
||||||
health_bar_definition = definition
|
health_bar_definition = definition
|
||||||
|
|
||||||
for name,ids in pairs(hud_ids) do
|
for name,ids in pairs(hud_ids) do
|
||||||
local player = multicraft.get_player_by_name(name)
|
local player = core.get_player_by_name(name)
|
||||||
if player and hud_ids[name].id_healthbar then
|
if player and hud_ids[name].id_healthbar then
|
||||||
player:hud_remove(hud_ids[name].id_healthbar)
|
player:hud_remove(hud_ids[name].id_healthbar)
|
||||||
initialize_builtin_statbars(player)
|
initialize_builtin_statbars(player)
|
||||||
|
@ -148,7 +148,7 @@ function multicraft.hud_replace_builtin(name, definition)
|
||||||
breath_bar_definition = definition
|
breath_bar_definition = definition
|
||||||
|
|
||||||
for name,ids in pairs(hud_ids) do
|
for name,ids in pairs(hud_ids) do
|
||||||
local player = multicraft.get_player_by_name(name)
|
local player = core.get_player_by_name(name)
|
||||||
if player and hud_ids[name].id_breathbar then
|
if player and hud_ids[name].id_breathbar then
|
||||||
player:hud_remove(hud_ids[name].id_breathbar)
|
player:hud_remove(hud_ids[name].id_breathbar)
|
||||||
initialize_builtin_statbars(player)
|
initialize_builtin_statbars(player)
|
||||||
|
@ -160,6 +160,6 @@ function multicraft.hud_replace_builtin(name, definition)
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
multicraft.register_on_joinplayer(initialize_builtin_statbars)
|
core.register_on_joinplayer(initialize_builtin_statbars)
|
||||||
multicraft.register_on_leaveplayer(cleanup_builtin_statbars)
|
core.register_on_leaveplayer(cleanup_builtin_statbars)
|
||||||
multicraft.register_playerevent(player_event_handler)
|
core.register_playerevent(player_event_handler)
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
-- Minetest: builtin/static_spawn.lua
|
-- Minetest: builtin/static_spawn.lua
|
||||||
|
|
||||||
local function warn_invalid_static_spawnpoint()
|
local function warn_invalid_static_spawnpoint()
|
||||||
if multicraft.setting_get("static_spawnpoint") and
|
if core.setting_get("static_spawnpoint") and
|
||||||
not multicraft.setting_get_pos("static_spawnpoint") then
|
not core.setting_get_pos("static_spawnpoint") then
|
||||||
multicraft.log('error', "The static_spawnpoint setting is invalid: \""..
|
core.log('error', "The static_spawnpoint setting is invalid: \""..
|
||||||
multicraft.setting_get("static_spawnpoint").."\"")
|
core.setting_get("static_spawnpoint").."\"")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -12,22 +12,22 @@ warn_invalid_static_spawnpoint()
|
||||||
|
|
||||||
local function put_player_in_spawn(obj)
|
local function put_player_in_spawn(obj)
|
||||||
warn_invalid_static_spawnpoint()
|
warn_invalid_static_spawnpoint()
|
||||||
local static_spawnpoint = multicraft.setting_get_pos("static_spawnpoint")
|
local static_spawnpoint = core.setting_get_pos("static_spawnpoint")
|
||||||
if not static_spawnpoint then
|
if not static_spawnpoint then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
multicraft.log('action', "Moving "..obj:get_player_name()..
|
core.log('action', "Moving "..obj:get_player_name()..
|
||||||
" to static spawnpoint at "..
|
" to static spawnpoint at "..
|
||||||
multicraft.pos_to_string(static_spawnpoint))
|
core.pos_to_string(static_spawnpoint))
|
||||||
obj:setpos(static_spawnpoint)
|
obj:setpos(static_spawnpoint)
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
multicraft.register_on_newplayer(function(obj)
|
core.register_on_newplayer(function(obj)
|
||||||
put_player_in_spawn(obj)
|
put_player_in_spawn(obj)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
multicraft.register_on_respawnplayer(function(obj)
|
core.register_on_respawnplayer(function(obj)
|
||||||
return put_player_in_spawn(obj)
|
return put_player_in_spawn(obj)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|
|
@ -6,35 +6,29 @@
|
||||||
--
|
--
|
||||||
|
|
||||||
-- Initialize some very basic things
|
-- Initialize some very basic things
|
||||||
multicraft = core
|
print = core.debug
|
||||||
minetest = core
|
|
||||||
print = multicraft.debug
|
|
||||||
math.randomseed(os.time())
|
math.randomseed(os.time())
|
||||||
os.setlocale("C", "numeric")
|
os.setlocale("C", "numeric")
|
||||||
|
minetest = core
|
||||||
|
|
||||||
-- Load other files
|
-- Load other files
|
||||||
local scriptdir = multicraft.get_builtin_path()..DIR_DELIM
|
local scriptdir = core.get_builtin_path()..DIR_DELIM
|
||||||
local gamepath = scriptdir.."game"..DIR_DELIM
|
local gamepath = scriptdir.."game"..DIR_DELIM
|
||||||
local commonpath = scriptdir.."common"..DIR_DELIM
|
local commonpath = scriptdir.."common"..DIR_DELIM
|
||||||
local asyncpath = scriptdir.."async"..DIR_DELIM
|
local asyncpath = scriptdir.."async"..DIR_DELIM
|
||||||
|
|
||||||
--dofile(scriptdir.."profiler.lua") --TODO: repair me
|
|
||||||
--[[ too buggy
|
|
||||||
dofile(commonpath.."strict.lua")
|
dofile(commonpath.."strict.lua")
|
||||||
]]
|
|
||||||
dofile(commonpath.."serialize.lua")
|
dofile(commonpath.."serialize.lua")
|
||||||
dofile(commonpath.."misc_helpers.lua")
|
dofile(commonpath.."misc_helpers.lua")
|
||||||
|
|
||||||
dofile(scriptdir.."key_value_storage.lua")
|
|
||||||
|
|
||||||
if INIT == "game" then
|
if INIT == "game" then
|
||||||
dofile(gamepath.."init.lua")
|
dofile(gamepath.."init.lua")
|
||||||
elseif INIT == "mainmenu" then
|
elseif INIT == "mainmenu" then
|
||||||
local mainmenuscript = multicraft.setting_get("main_menu_script")
|
local mainmenuscript = core.setting_get("main_menu_script")
|
||||||
if mainmenuscript ~= nil and mainmenuscript ~= "" then
|
if mainmenuscript ~= nil and mainmenuscript ~= "" then
|
||||||
dofile(mainmenuscript)
|
dofile(mainmenuscript)
|
||||||
else
|
else
|
||||||
dofile(multicraft.get_mainmenu_path()..DIR_DELIM.."init.lua")
|
dofile(core.get_mainmenu_path()..DIR_DELIM.."init.lua")
|
||||||
end
|
end
|
||||||
elseif INIT == "async" then
|
elseif INIT == "async" then
|
||||||
dofile(asyncpath.."init.lua")
|
dofile(asyncpath.."init.lua")
|
||||||
|
|
|
@ -1,26 +0,0 @@
|
||||||
--
|
|
||||||
-- Key-value storage stuff
|
|
||||||
--
|
|
||||||
|
|
||||||
function multicraft.kv_put(key, data)
|
|
||||||
local json = multicraft.write_json(data)
|
|
||||||
if not json then
|
|
||||||
multicraft.log("error", "kv_put: Error in json serialize key=".. key .. " luaized_data=" .. multicraft.serialize(data))
|
|
||||||
return
|
|
||||||
end
|
|
||||||
return multicraft.kv_put_string(key, json)
|
|
||||||
end
|
|
||||||
|
|
||||||
function multicraft.kv_get(key)
|
|
||||||
local data = multicraft.kv_get_string(key)
|
|
||||||
if data ~= nil then
|
|
||||||
data = multicraft.parse_json(data)
|
|
||||||
end
|
|
||||||
return data
|
|
||||||
end
|
|
||||||
|
|
||||||
function multicraft.kv_rename(key1, key2)
|
|
||||||
local data = multicraft.kv_get_string(key1)
|
|
||||||
multicraft.kv_delete(key1)
|
|
||||||
multicraft.kv_put_string(key2, data)
|
|
||||||
end
|
|
|
@ -3,7 +3,7 @@
|
||||||
--
|
--
|
||||||
--This program is free software; you can redistribute it and/or modify
|
--This program is free software; you can redistribute it and/or modify
|
||||||
--it under the terms of the GNU Lesser General Public License as published by
|
--it under the terms of the GNU Lesser General Public License as published by
|
||||||
--the Free Software Foundation; either version 3.0 of the License, or
|
--the Free Software Foundation; either version 2.1 of the License, or
|
||||||
--(at your option) any later version.
|
--(at your option) any later version.
|
||||||
--
|
--
|
||||||
--This program is distributed in the hope that it will be useful,
|
--This program is distributed in the hope that it will be useful,
|
||||||
|
@ -16,206 +16,277 @@
|
||||||
--51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
--51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
-- Global menu data
|
-- Global menu data
|
||||||
---------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
menudata = {}
|
menudata = {}
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
-- Local cached values
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
local min_supp_proto = core.get_min_supp_proto()
|
||||||
|
local max_supp_proto = core.get_max_supp_proto()
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
-- Menu helper functions
|
-- Menu helper functions
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
local function render_client_count(n)
|
local function render_client_count(n)
|
||||||
if tonumber(n) > 99 then
|
if n > 99 then
|
||||||
return '99+'
|
return '99+'
|
||||||
elseif tonumber(n) >= 0 then
|
elseif n >= 0 then
|
||||||
return tostring(n)
|
return tostring(n)
|
||||||
else
|
else
|
||||||
return '?'
|
return '?'
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function configure_selected_world_params(idx)
|
||||||
|
local worldconfig = modmgr.get_worldconfig(
|
||||||
|
menudata.worldlist:get_list()[idx].path)
|
||||||
|
|
||||||
|
if worldconfig.creative_mode ~= nil then
|
||||||
|
core.setting_set("creative_mode", worldconfig.creative_mode)
|
||||||
|
end
|
||||||
|
if worldconfig.enable_damage ~= nil then
|
||||||
|
core.setting_set("enable_damage", worldconfig.enable_damage)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
function image_column(tooltip, flagname)
|
||||||
|
return "image," ..
|
||||||
|
"tooltip=" .. core.formspec_escape(tooltip) .. "," ..
|
||||||
|
"0=" .. core.formspec_escape(defaulttexturedir .. "blank.png") .. "," ..
|
||||||
|
"1=" .. core.formspec_escape(defaulttexturedir .. "server_flags_" .. flagname .. ".png")
|
||||||
|
end
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
function order_favorite_list(list)
|
||||||
|
local res = {}
|
||||||
|
--orders the favorite list after support
|
||||||
|
for i=1,#list,1 do
|
||||||
|
local fav = list[i]
|
||||||
|
if is_server_protocol_compat(fav.proto_min, fav.proto_max) then
|
||||||
|
table.insert(res, fav)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
for i=1,#list,1 do
|
||||||
|
local fav = list[i]
|
||||||
|
if not is_server_protocol_compat(fav.proto_min, fav.proto_max) then
|
||||||
|
table.insert(res, fav)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return res
|
||||||
end
|
end
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
function render_favorite(spec,render_details)
|
function render_favorite(spec,render_details)
|
||||||
local text = ""
|
local text = ""
|
||||||
|
|
||||||
if spec.name ~= nil then
|
if spec.name ~= nil then
|
||||||
text = text .. multicraft.formspec_escape(spec.name:trim())
|
text = text .. core.formspec_escape(spec.name:trim())
|
||||||
|
|
||||||
-- if spec.description ~= nil and
|
-- if spec.description ~= nil and
|
||||||
-- multicraft.formspec_escape(spec.description):trim() ~= "" then
|
-- core.formspec_escape(spec.description):trim() ~= "" then
|
||||||
-- text = text .. " (" .. multicraft.formspec_escape(spec.description) .. ")"
|
-- text = text .. " (" .. core.formspec_escape(spec.description) .. ")"
|
||||||
-- end
|
-- end
|
||||||
else
|
else
|
||||||
if spec.address ~= nil then
|
if spec.address ~= nil then
|
||||||
text = text .. spec.address:trim()
|
text = text .. spec.address:trim()
|
||||||
|
|
||||||
if spec.port ~= nil then
|
if spec.port ~= nil then
|
||||||
text = text .. ":" .. spec.port
|
text = text .. ":" .. spec.port
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local details = ""
|
if not render_details then
|
||||||
|
return text
|
||||||
|
end
|
||||||
|
|
||||||
if spec.clients ~= nil and spec.clients_max ~= nil then
|
local details = ""
|
||||||
local clients_color = ''
|
local grey_out = not is_server_protocol_compat(spec.proto_max, spec.proto_min)
|
||||||
local clients_percent = 100 * spec.clients / spec.clients_max
|
|
||||||
|
|
||||||
-- Choose a color depending on how many clients are connected
|
if spec.clients ~= nil and spec.clients_max ~= nil then
|
||||||
-- (relatively to clients_max)
|
local clients_color = ''
|
||||||
if spec.clients == 0 then
|
local clients_percent = 100 * spec.clients / spec.clients_max
|
||||||
clients_color = '' -- 0 players: default/white
|
|
||||||
elseif spec.clients == spec.clients_max then
|
|
||||||
clients_color = '#dd5b5b' -- full server: red (darker)
|
|
||||||
elseif clients_percent <= 60 then
|
|
||||||
clients_color = '#a1e587' -- 0-60%: green
|
|
||||||
elseif clients_percent <= 90 then
|
|
||||||
clients_color = '#ffdc97' -- 60-90%: yellow
|
|
||||||
else
|
|
||||||
clients_color = '#ffba97' -- 90-100%: orange
|
|
||||||
end
|
|
||||||
|
|
||||||
details = details ..
|
-- Choose a color depending on how many clients are connected
|
||||||
clients_color .. ',' ..
|
-- (relatively to clients_max)
|
||||||
render_client_count(spec.clients) .. ',' ..
|
if spec.clients == 0 then
|
||||||
'/,' ..
|
clients_color = '' -- 0 players: default/white
|
||||||
render_client_count(spec.clients_max) .. ','
|
elseif spec.clients == spec.clients_max then
|
||||||
else
|
clients_color = '#dd5b5b' -- full server: red (darker)
|
||||||
details = details .. ',?,/,?,'
|
elseif clients_percent <= 60 then
|
||||||
end
|
clients_color = '#a1e587' -- 0-60%: green
|
||||||
|
elseif clients_percent <= 90 then
|
||||||
|
clients_color = '#ffdc97' -- 60-90%: yellow
|
||||||
|
else
|
||||||
|
clients_color = '#ffba97' -- 90-100%: orange
|
||||||
|
end
|
||||||
|
|
||||||
if spec.creative then
|
if grey_out then
|
||||||
details = details .. "1,"
|
clients_color = '#aaaaaa'
|
||||||
else
|
end
|
||||||
details = details .. "0,"
|
|
||||||
end
|
|
||||||
|
|
||||||
if spec.damage then
|
details = details ..
|
||||||
details = details .. "1,"
|
clients_color .. ',' ..
|
||||||
else
|
render_client_count(spec.clients) .. ',' ..
|
||||||
details = details .. "0,"
|
'/,' ..
|
||||||
end
|
render_client_count(spec.clients_max) .. ','
|
||||||
|
elseif grey_out then
|
||||||
|
details = details .. '#aaaaaa,?,/,?,'
|
||||||
|
else
|
||||||
|
details = details .. ',?,/,?,'
|
||||||
|
end
|
||||||
|
|
||||||
if spec.pvp then
|
if spec.creative then
|
||||||
details = details .. "1,"
|
details = details .. "1,"
|
||||||
else
|
else
|
||||||
details = details .. "0,"
|
details = details .. "0,"
|
||||||
end
|
end
|
||||||
|
|
||||||
details = details .. text
|
if spec.damage then
|
||||||
return details
|
details = details .. "1,"
|
||||||
|
else
|
||||||
|
details = details .. "0,"
|
||||||
|
end
|
||||||
|
|
||||||
|
if spec.pvp then
|
||||||
|
details = details .. "1,"
|
||||||
|
else
|
||||||
|
details = details .. "0,"
|
||||||
|
end
|
||||||
|
|
||||||
|
return details .. (grey_out and '#aaaaaa,' or ',') .. text
|
||||||
end
|
end
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
os.tempfolder = function()
|
os.tempfolder = function()
|
||||||
if multicraft.setting_get("TMPFolder") then
|
if core.setting_get("TMPFolder") then
|
||||||
return multicraft.setting_get("TMPFolder") .. DIR_DELIM .. "MT_" .. math.random(0,10000)
|
return core.setting_get("TMPFolder") .. DIR_DELIM .. "MT_" .. math.random(0,10000)
|
||||||
end
|
end
|
||||||
|
|
||||||
local filetocheck = os.tmpname()
|
local filetocheck = os.tmpname()
|
||||||
os.remove(filetocheck)
|
os.remove(filetocheck)
|
||||||
|
|
||||||
local randname = "MTTempModFolder_" .. math.random(0,10000)
|
local randname = "MTTempModFolder_" .. math.random(0,10000)
|
||||||
if DIR_DELIM == "\\" then
|
if DIR_DELIM == "\\" then
|
||||||
local tempfolder = os.getenv("TEMP")
|
local tempfolder = os.getenv("TEMP")
|
||||||
return tempfolder .. filetocheck
|
return tempfolder .. filetocheck
|
||||||
else
|
else
|
||||||
local backstring = filetocheck:reverse()
|
local backstring = filetocheck:reverse()
|
||||||
return filetocheck:sub(0,filetocheck:len()-backstring:find(DIR_DELIM)+1) ..randname
|
return filetocheck:sub(0,filetocheck:len()-backstring:find(DIR_DELIM)+1) ..randname
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
function menu_render_worldlist()
|
function menu_render_worldlist()
|
||||||
local retval = ""
|
local retval = ""
|
||||||
|
|
||||||
local current_worldlist = menudata.worldlist:get_list()
|
local current_worldlist = menudata.worldlist:get_list()
|
||||||
|
|
||||||
for i,v in ipairs(current_worldlist) do
|
for i,v in ipairs(current_worldlist) do
|
||||||
if retval ~= "" then
|
if retval ~= "" then
|
||||||
retval = retval ..","
|
retval = retval ..","
|
||||||
end
|
end
|
||||||
|
|
||||||
retval = retval .. multicraft.formspec_escape(v.name) ..
|
retval = retval .. core.formspec_escape(v.name) ..
|
||||||
" \\[" .. multicraft.formspec_escape(v.gameid) .. "\\]"
|
" \\[" .. core.formspec_escape(v.gameid) .. "\\]"
|
||||||
end
|
end
|
||||||
|
|
||||||
return retval
|
return retval
|
||||||
end
|
end
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
function menu_handle_key_up_down(fields,textlist,settingname)
|
function menu_handle_key_up_down(fields,textlist,settingname)
|
||||||
|
if fields["key_up"] then
|
||||||
|
local oldidx = core.get_textlist_index(textlist)
|
||||||
|
|
||||||
if fields["key_up"] then
|
if oldidx ~= nil and oldidx > 1 then
|
||||||
local oldidx = multicraft.get_textlist_index(textlist)
|
local newidx = oldidx -1
|
||||||
|
core.setting_set(settingname,
|
||||||
|
menudata.worldlist:get_raw_index(newidx))
|
||||||
|
|
||||||
if oldidx ~= nil and oldidx > 1 then
|
configure_selected_world_params(newidx)
|
||||||
local newidx = oldidx -1
|
end
|
||||||
multicraft.setting_set(settingname,
|
return true
|
||||||
menudata.worldlist:get_raw_index(newidx))
|
end
|
||||||
end
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
if fields["key_down"] then
|
if fields["key_down"] then
|
||||||
local oldidx = multicraft.get_textlist_index(textlist)
|
local oldidx = core.get_textlist_index(textlist)
|
||||||
|
|
||||||
if oldidx ~= nil and oldidx < menudata.worldlist:size() then
|
if oldidx ~= nil and oldidx < menudata.worldlist:size() then
|
||||||
local newidx = oldidx + 1
|
local newidx = oldidx + 1
|
||||||
multicraft.setting_set(settingname,
|
core.setting_set(settingname,
|
||||||
menudata.worldlist:get_raw_index(newidx))
|
menudata.worldlist:get_raw_index(newidx))
|
||||||
end
|
|
||||||
|
|
||||||
return true
|
configure_selected_world_params(newidx)
|
||||||
end
|
end
|
||||||
|
|
||||||
return false
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
function asyncOnlineFavourites()
|
function asyncOnlineFavourites()
|
||||||
|
|
||||||
menudata.favorites = {}
|
menudata.favorites = {}
|
||||||
multicraft.handle_async(
|
core.handle_async(
|
||||||
function(param)
|
function(param)
|
||||||
local ret = multicraft.get_favorites("online")
|
return core.get_favorites("online")
|
||||||
local num = multicraft.get_favorites("local")
|
end,
|
||||||
local cou = 0
|
nil,
|
||||||
for k,v in ipairs(multicraft.get_favorites("local")) do
|
function(result)
|
||||||
cou = cou+1
|
if core.setting_getbool("public_serverlist") then
|
||||||
table.insert(ret,cou,v)
|
menudata.favorites = order_favorite_list(result)
|
||||||
end
|
core.event_handler("Refresh")
|
||||||
return ret
|
end
|
||||||
end,
|
end
|
||||||
nil,
|
)
|
||||||
function(result)
|
|
||||||
menudata.favorites = result
|
|
||||||
multicraft.event_handler("Refresh")
|
|
||||||
end
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
function text2textlist(xpos,ypos,width,height,tl_name,textlen,text,transparency)
|
function text2textlist(xpos,ypos,width,height,tl_name,textlen,text,transparency)
|
||||||
local textlines = multicraft.splittext(text,textlen)
|
local textlines = core.splittext(text,textlen)
|
||||||
|
|
||||||
|
local retval = "textlist[" .. xpos .. "," .. ypos .. ";"
|
||||||
|
.. width .. "," .. height .. ";"
|
||||||
|
.. tl_name .. ";"
|
||||||
|
|
||||||
|
for i=1, #textlines, 1 do
|
||||||
|
textlines[i] = textlines[i]:gsub("\r","")
|
||||||
|
retval = retval .. core.formspec_escape(textlines[i]) .. ","
|
||||||
|
end
|
||||||
|
|
||||||
|
retval = retval .. ";0;"
|
||||||
|
|
||||||
|
if transparency then
|
||||||
|
retval = retval .. "true"
|
||||||
|
end
|
||||||
|
|
||||||
|
retval = retval .. "]"
|
||||||
|
|
||||||
local retval = "textlist[" .. xpos .. "," .. ypos .. ";"
|
return retval
|
||||||
.. width .. "," .. height .. ";"
|
end
|
||||||
.. tl_name .. ";"
|
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
for i=1, #textlines, 1 do
|
function is_server_protocol_compat(proto_min, proto_max)
|
||||||
textlines[i] = textlines[i]:gsub("\r","")
|
return not ((min_supp_proto > (proto_max or 24)) or (max_supp_proto < (proto_min or 13)))
|
||||||
retval = retval .. multicraft.formspec_escape(textlines[i]) .. ","
|
end
|
||||||
end
|
--------------------------------------------------------------------------------
|
||||||
|
function is_server_protocol_compat_or_error(proto_min, proto_max)
|
||||||
retval = retval .. ";0;"
|
if not is_server_protocol_compat(proto_min, proto_max) then
|
||||||
|
gamedata.errormessage = fgettext_ne("Protocol version mismatch, server " ..
|
||||||
if transparency then
|
((proto_min ~= proto_max) and "supports protocols between $1 and $2" or "enforces protocol version $1") ..
|
||||||
retval = retval .. "true"
|
", we " ..
|
||||||
end
|
((min_supp_proto ~= max_supp_proto) and "support protocols between version $3 and $4." or "only support protocol version $3"),
|
||||||
|
proto_min or 13, proto_max or 24, min_supp_proto, max_supp_proto)
|
||||||
retval = retval .. "]"
|
return false
|
||||||
|
end
|
||||||
return retval
|
|
||||||
|
return true
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,112 +0,0 @@
|
||||||
--Minetest
|
|
||||||
--Copyright (C) 2014 sapier
|
|
||||||
--
|
|
||||||
--This program is free software; you can redistribute it and/or modify
|
|
||||||
--it under the terms of the GNU Lesser General Public License as published by
|
|
||||||
--the Free Software Foundation; either version 3.0 of the License, or
|
|
||||||
--(at your option) any later version.
|
|
||||||
--
|
|
||||||
--This program is distributed in the hope that it will be useful,
|
|
||||||
--but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
--MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
--GNU Lesser General Public License for more details.
|
|
||||||
--
|
|
||||||
--You should have received a copy of the GNU Lesser General Public License along
|
|
||||||
--with this program; if not, write to the Free Software Foundation, Inc.,
|
|
||||||
--51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
||||||
|
|
||||||
local function add_server_formspec(dialogdata)
|
|
||||||
local retval =
|
|
||||||
"size[16,11]"..
|
|
||||||
"bgcolor[#00000070;true]"..
|
|
||||||
"box[-100,8.5;200,10;#999999]" ..
|
|
||||||
"box[-100,-10;200,12;#999999]" ..
|
|
||||||
|
|
||||||
"label[4,3;" .. fgettext("Name") .. "]"..
|
|
||||||
"field[6.5,3.4;6,0.5;servername;;]" ..
|
|
||||||
|
|
||||||
"label[4,4;" .. fgettext("Address") .. "]"..
|
|
||||||
"field[6.5,4.4;6,0.5;address;;]" ..
|
|
||||||
|
|
||||||
"label[4,5;" .. fgettext("Port") .. "]"..
|
|
||||||
"field[6.5,5.4;6,0.5;port;;30000]" ..
|
|
||||||
|
|
||||||
"label[4,6;" .. fgettext("Description") .. "]"..
|
|
||||||
"field[6.5,6.4;6,0.5;desc;;Added on ".. os.date() .."]" ..
|
|
||||||
|
|
||||||
|
|
||||||
"image_button[8,9.54;3.95,0.8;"..multicraft.formspec_escape(mm_texture.basetexturedir).."menu_button.png;server_add_confirm;".. fgettext("Add") .. ";true;true;"..multicraft.formspec_escape(mm_texture.basetexturedir).."menu_button_b.png]"..
|
|
||||||
"image_button[12,9.55;4,0.8;"..multicraft.formspec_escape(mm_texture.basetexturedir).."menu_button.png;server_add_cancel;".. fgettext("Cancel") .. ";true;true;"..multicraft.formspec_escape(mm_texture.basetexturedir).."menu_button_b.png]"
|
|
||||||
|
|
||||||
return retval
|
|
||||||
end
|
|
||||||
|
|
||||||
local function add_server_buttonhandler(this, fields)
|
|
||||||
multicraft.set_clouds(false)
|
|
||||||
|
|
||||||
if fields["server_add_cancel"] then
|
|
||||||
this:delete()
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
if fields["server_add_confirm"]
|
|
||||||
or fields["key_enter"] then
|
|
||||||
if fields["address"] and fields["port"] then
|
|
||||||
|
|
||||||
----------------------
|
|
||||||
local path = multicraft.get_modpath('')..'/../client/'..multicraft.formspec_escape(multicraft.setting_get("serverlist_file"))
|
|
||||||
local favourites
|
|
||||||
if path then
|
|
||||||
local input = io.open(path, "r")
|
|
||||||
if input then
|
|
||||||
favourites = input:read("*all")
|
|
||||||
io.close(input)
|
|
||||||
--else
|
|
||||||
--gamedata.errormessage = fgettext("Can't find serverlist_file! ("..path..')')
|
|
||||||
end
|
|
||||||
if favourites then
|
|
||||||
favourites = multicraft.parse_json(favourites)
|
|
||||||
else
|
|
||||||
favourites = {["list"]={},}
|
|
||||||
end
|
|
||||||
|
|
||||||
table.insert(favourites.list,{
|
|
||||||
["address"] = fields["te_address"],
|
|
||||||
["description"] = "Saved at ".. os.date(),
|
|
||||||
["name"] = fields["te_address"],
|
|
||||||
["playername"] = fields["te_name"],
|
|
||||||
["playerpassword"] = fields["te_pwd"],
|
|
||||||
["port"] = fields["te_port"],
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
favourites = multicraft.write_json(favourites)
|
|
||||||
|
|
||||||
--print(path)
|
|
||||||
local output = io.open(path, "w")
|
|
||||||
if output then
|
|
||||||
output:write(favourites or '')
|
|
||||||
io.close(output)
|
|
||||||
else
|
|
||||||
gamedata.errormessage = err..' ('..errcode..')'
|
|
||||||
end
|
|
||||||
end
|
|
||||||
----------------------
|
|
||||||
|
|
||||||
asyncOnlineFavourites()
|
|
||||||
this:delete()
|
|
||||||
end
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
function create_add_server_dlg(update_worldlistfilter)
|
|
||||||
local retval = dialog_create("add_server_dlg",
|
|
||||||
add_server_formspec,
|
|
||||||
add_server_buttonhandler,
|
|
||||||
nil)
|
|
||||||
return retval
|
|
||||||
end
|
|
|
@ -3,7 +3,7 @@
|
||||||
--
|
--
|
||||||
--This program is free software; you can redistribute it and/or modify
|
--This program is free software; you can redistribute it and/or modify
|
||||||
--it under the terms of the GNU Lesser General Public License as published by
|
--it under the terms of the GNU Lesser General Public License as published by
|
||||||
--the Free Software Foundation; either version 3.0 of the License, or
|
--the Free Software Foundation; either version 2.1 of the License, or
|
||||||
--(at your option) any later version.
|
--(at your option) any later version.
|
||||||
--
|
--
|
||||||
--This program is distributed in the hope that it will be useful,
|
--This program is distributed in the hope that it will be useful,
|
||||||
|
@ -16,296 +16,296 @@
|
||||||
--51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
--51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
local function modname_valid(name)
|
||||||
|
return not name:find("[^a-z0-9_]")
|
||||||
|
end
|
||||||
|
|
||||||
local function get_formspec(data)
|
local function get_formspec(data)
|
||||||
|
|
||||||
local mod = data.list:get_list()[data.selected_mod]
|
local mod = data.list:get_list()[data.selected_mod]
|
||||||
|
|
||||||
local retval =
|
local retval =
|
||||||
"size[16,11]"..
|
"size[11,6.5,true]" ..
|
||||||
"bgcolor[#00000070;true]"..
|
"label[0.5,-0.25;" .. fgettext("World:") .. "]" ..
|
||||||
"box[-100,8.5;200,10;#999999]" ..
|
"label[1.75,-0.25;" .. data.worldspec.name .. "]"
|
||||||
"box[-100,-10;200,12;#999999]" ..
|
|
||||||
|
|
||||||
"label[1, 2.5;" .. fgettext("World:") .. "]" ..
|
if data.hide_gamemods then
|
||||||
"label[2.75,2.5;" .. data.worldspec.name .. "]"
|
retval = retval .. "checkbox[0,5.75;cb_hide_gamemods;" .. fgettext("Hide Game") .. ";true]"
|
||||||
|
else
|
||||||
|
retval = retval .. "checkbox[0,5.75;cb_hide_gamemods;" .. fgettext("Hide Game") .. ";false]"
|
||||||
|
end
|
||||||
|
|
||||||
if data.hide_gamemods then
|
if data.hide_modpackcontents then
|
||||||
retval = retval .. "checkbox[1,7.55;cb_hide_gamemods;" .. fgettext("Hide Game") .. ";true]"
|
retval = retval .. "checkbox[2,5.75;cb_hide_mpcontent;" .. fgettext("Hide mp content") .. ";true]"
|
||||||
else
|
else
|
||||||
retval = retval .. "checkbox[1,7.55;cb_hide_gamemods;" .. fgettext("Hide Game") .. ";false]"
|
retval = retval .. "checkbox[2,5.75;cb_hide_mpcontent;" .. fgettext("Hide mp content") .. ";false]"
|
||||||
end
|
end
|
||||||
|
|
||||||
if data.hide_modpackcontents then
|
if mod == nil then
|
||||||
retval = retval .. "checkbox[4,7.55;cb_hide_mpcontent;" .. fgettext("Hide mp content") .. ";true]"
|
mod = {name=""}
|
||||||
else
|
end
|
||||||
retval = retval .. "checkbox[4,7.55;cb_hide_mpcontent;" .. fgettext("Hide mp content") .. ";false]"
|
|
||||||
end
|
retval = retval ..
|
||||||
|
"label[0,0.45;" .. fgettext("Mod:") .. "]" ..
|
||||||
|
"label[0.75,0.45;" .. mod.name .. "]" ..
|
||||||
|
"label[0,1;" .. fgettext("Depends:") .. "]" ..
|
||||||
|
"textlist[0,1.5;5,4.25;world_config_depends;" ..
|
||||||
|
modmgr.get_dependencies(mod.path) .. ";0]" ..
|
||||||
|
"button[9.25,6.35;2,0.5;btn_config_world_save;" .. fgettext("Save") .. "]" ..
|
||||||
|
"button[7.4,6.35;2,0.5;btn_config_world_cancel;" .. fgettext("Cancel") .. "]"
|
||||||
|
|
||||||
if mod == nil then
|
if mod ~= nil and mod.name ~= "" and mod.typ ~= "game_mod" then
|
||||||
mod = {name=""}
|
if mod.is_modpack then
|
||||||
end
|
local rawlist = data.list:get_raw_list()
|
||||||
|
|
||||||
retval = retval ..
|
local all_enabled = true
|
||||||
"label[1,3;" .. fgettext("Mod:") .. "]" ..
|
for j=1,#rawlist,1 do
|
||||||
"label[2.75,3;" .. mod.name .. "]" ..
|
if rawlist[j].modpack == mod.name and
|
||||||
"label[8,3;" .. fgettext("Depends:") .. "]" ..
|
rawlist[j].enabled ~= true then
|
||||||
"textlist[8,3.5;7,4.0;world_config_depends;" ..
|
all_enabled = false
|
||||||
modmgr.get_dependencies(mod.path) .. ";0]" ..
|
break
|
||||||
"image_button[8,9.55;3.95,0.8;"..multicraft.formspec_escape(mm_texture.basetexturedir).."menu_button.png;btn_config_world_save;" .. fgettext("Save") .. ";true;true;"..multicraft.formspec_escape(mm_texture.basetexturedir).."menu_button_b.png]"..
|
end
|
||||||
"image_button[12,9.55;4,0.8;"..multicraft.formspec_escape(mm_texture.basetexturedir).."menu_button.png;btn_config_world_cancel;".. fgettext("Cancel") .. ";true;true;"..multicraft.formspec_escape(mm_texture.basetexturedir).."menu_button_b.png]"
|
end
|
||||||
|
|
||||||
if mod ~= nil and mod.name ~= "" and mod.typ ~= "game_mod" then
|
if all_enabled == false then
|
||||||
if mod.is_modpack then
|
retval = retval .. "button[5.5,-0.125;2,0.5;btn_mp_enable;" .. fgettext("Enable MP") .. "]"
|
||||||
local rawlist = data.list:get_raw_list()
|
else
|
||||||
|
retval = retval .. "button[5.5,-0.125;2,0.5;btn_mp_disable;" .. fgettext("Disable MP") .. "]"
|
||||||
|
end
|
||||||
|
else
|
||||||
|
if mod.enabled then
|
||||||
|
retval = retval .. "checkbox[5.5,-0.375;cb_mod_enable;" .. fgettext("enabled") .. ";true]"
|
||||||
|
else
|
||||||
|
retval = retval .. "checkbox[5.5,-0.375;cb_mod_enable;" .. fgettext("enabled") .. ";false]"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
local all_enabled = true
|
retval = retval ..
|
||||||
for j=1,#rawlist,1 do
|
"button[8.5,-0.125;2.5,0.5;btn_all_mods;" .. fgettext("Enable all") .. "]" ..
|
||||||
if rawlist[j].modpack == mod.name and
|
"textlist[5.5,0.5;5.5,5.75;world_config_modlist;"
|
||||||
rawlist[j].enabled ~= true then
|
|
||||||
all_enabled = false
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if all_enabled == false then
|
retval = retval .. modmgr.render_modlist(data.list)
|
||||||
retval = retval .. "image_button[8,7.55;3.5,0.8;"..multicraft.formspec_escape(mm_texture.basetexturedir).."menu_button.png;btn_mp_enable;" .. fgettext("Enable MP") .. ";true;true;"..multicraft.formspec_escape(mm_texture.basetexturedir).."menu_button_b.png]"
|
retval = retval .. ";" .. data.selected_mod .."]"
|
||||||
else
|
|
||||||
retval = retval .. "image_button[8,7.85;3.5,0.8;"..multicraft.formspec_escape(mm_texture.basetexturedir).."menu_button.png;btn_mp_disable;" .. fgettext("Disable MP") .. ";true;true;"..multicraft.formspec_escape(mm_texture.basetexturedir).."menu_button_b.png]"
|
|
||||||
end
|
|
||||||
else
|
|
||||||
if mod.enabled then
|
|
||||||
retval = retval .. "checkbox[8.25,7.55;cb_mod_enable;" .. fgettext("enabled") .. ";true]"
|
|
||||||
else
|
|
||||||
retval = retval .. "checkbox[8.25,7.55;cb_mod_enable;" .. fgettext("enabled") .. ";false]"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
retval = retval ..
|
return retval
|
||||||
"image_button[11.75,7.55;3.5,0.8;"..multicraft.formspec_escape(mm_texture.basetexturedir).."menu_button.png;btn_all_mods;" .. fgettext("Enable all") .. ";true;true;"..multicraft.formspec_escape(mm_texture.basetexturedir).."menu_button_b.png]"..
|
|
||||||
"textlist[1,3.5;6,4.0;world_config_modlist;"
|
|
||||||
--"textlist[5.5,0.5;5.5,5.75;world_config_modlist;"
|
|
||||||
|
|
||||||
retval = retval .. modmgr.render_modlist(data.list)
|
|
||||||
retval = retval .. ";" .. data.selected_mod .."]"
|
|
||||||
|
|
||||||
return retval
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local function enable_mod(this, toset)
|
local function enable_mod(this, toset)
|
||||||
local mod = this.data.list:get_list()[this.data.selected_mod]
|
local mod = this.data.list:get_list()[this.data.selected_mod]
|
||||||
|
|
||||||
if mod.typ == "game_mod" then
|
if mod.typ == "game_mod" then
|
||||||
-- game mods can't be enabled or disabled
|
-- game mods can't be enabled or disabled
|
||||||
elseif not mod.is_modpack then
|
elseif not mod.is_modpack then
|
||||||
if toset == nil then
|
if toset == nil then
|
||||||
mod.enabled = not mod.enabled
|
mod.enabled = not mod.enabled
|
||||||
else
|
else
|
||||||
mod.enabled = toset
|
mod.enabled = toset
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
local list = this.data.list:get_raw_list()
|
local list = this.data.list:get_raw_list()
|
||||||
for i=1,#list,1 do
|
for i=1,#list,1 do
|
||||||
if list[i].modpack == mod.name then
|
if list[i].modpack == mod.name then
|
||||||
if toset == nil then
|
if toset == nil then
|
||||||
toset = not list[i].enabled
|
toset = not list[i].enabled
|
||||||
end
|
end
|
||||||
list[i].enabled = toset
|
list[i].enabled = toset
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
local function handle_buttons(this, fields)
|
local function handle_buttons(this, fields)
|
||||||
multicraft.set_clouds(false)
|
|
||||||
if fields["world_config_modlist"] ~= nil then
|
|
||||||
local event = multicraft.explode_textlist_event(fields["world_config_modlist"])
|
|
||||||
this.data.selected_mod = event.index
|
|
||||||
multicraft.setting_set("world_config_selected_mod", event.index)
|
|
||||||
|
|
||||||
if event.type == "DCL" then
|
if fields["world_config_modlist"] ~= nil then
|
||||||
enable_mod(this)
|
local event = core.explode_textlist_event(fields["world_config_modlist"])
|
||||||
end
|
this.data.selected_mod = event.index
|
||||||
|
core.setting_set("world_config_selected_mod", event.index)
|
||||||
|
|
||||||
return true
|
if event.type == "DCL" then
|
||||||
end
|
enable_mod(this)
|
||||||
|
end
|
||||||
|
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
if fields["key_enter"] ~= nil then
|
if fields["key_enter"] ~= nil then
|
||||||
enable_mod(this)
|
enable_mod(this)
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
if fields["cb_mod_enable"] ~= nil then
|
if fields["cb_mod_enable"] ~= nil then
|
||||||
local toset = multicraft.is_yes(fields["cb_mod_enable"])
|
local toset = core.is_yes(fields["cb_mod_enable"])
|
||||||
enable_mod(this,toset)
|
enable_mod(this,toset)
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
if fields["btn_mp_enable"] ~= nil or
|
if fields["btn_mp_enable"] ~= nil or
|
||||||
fields["btn_mp_disable"] then
|
fields["btn_mp_disable"] then
|
||||||
local toset = (fields["btn_mp_enable"] ~= nil)
|
local toset = (fields["btn_mp_enable"] ~= nil)
|
||||||
enable_mod(this,toset)
|
enable_mod(this,toset)
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
if fields["cb_hide_gamemods"] ~= nil or
|
if fields["cb_hide_gamemods"] ~= nil or
|
||||||
fields["cb_hide_mpcontent"] ~= nil then
|
fields["cb_hide_mpcontent"] ~= nil then
|
||||||
local current = this.data.list:get_filtercriteria()
|
local current = this.data.list:get_filtercriteria()
|
||||||
|
|
||||||
if current == nil then
|
if current == nil then
|
||||||
current = {}
|
current = {}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if fields["cb_hide_gamemods"] ~= nil then
|
||||||
|
if core.is_yes(fields["cb_hide_gamemods"]) then
|
||||||
|
current.hide_game = true
|
||||||
|
this.data.hide_gamemods = true
|
||||||
|
core.setting_set("world_config_hide_gamemods", "true")
|
||||||
|
else
|
||||||
|
current.hide_game = false
|
||||||
|
this.data.hide_gamemods = false
|
||||||
|
core.setting_set("world_config_hide_gamemods", "false")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
if fields["cb_hide_gamemods"] ~= nil then
|
if fields["cb_hide_mpcontent"] ~= nil then
|
||||||
if multicraft.is_yes(fields["cb_hide_gamemods"]) then
|
if core.is_yes(fields["cb_hide_mpcontent"]) then
|
||||||
current.hide_game = true
|
current.hide_modpackcontents = true
|
||||||
this.data.hide_gamemods = true
|
this.data.hide_modpackcontents = true
|
||||||
multicraft.setting_set("world_config_hide_gamemods", "true")
|
core.setting_set("world_config_hide_modpackcontents", "true")
|
||||||
else
|
else
|
||||||
current.hide_game = false
|
current.hide_modpackcontents = false
|
||||||
this.data.hide_gamemods = false
|
this.data.hide_modpackcontents = false
|
||||||
multicraft.setting_set("world_config_hide_gamemods", "false")
|
core.setting_set("world_config_hide_modpackcontents", "false")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if fields["cb_hide_mpcontent"] ~= nil then
|
this.data.list:set_filtercriteria(current)
|
||||||
if multicraft.is_yes(fields["cb_hide_mpcontent"]) then
|
return true
|
||||||
current.hide_modpackcontents = true
|
end
|
||||||
this.data.hide_modpackcontents = true
|
|
||||||
multicraft.setting_set("world_config_hide_modpackcontents", "true")
|
|
||||||
else
|
|
||||||
current.hide_modpackcontents = false
|
|
||||||
this.data.hide_modpackcontents = false
|
|
||||||
multicraft.setting_set("world_config_hide_modpackcontents", "false")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
this.data.list:set_filtercriteria(current)
|
if fields["btn_config_world_save"] then
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
if fields["btn_config_world_save"] then
|
local filename = this.data.worldspec.path ..
|
||||||
|
DIR_DELIM .. "world.mt"
|
||||||
|
|
||||||
local filename = this.data.worldspec.path ..
|
local worldfile = Settings(filename)
|
||||||
DIR_DELIM .. "world.mt"
|
local mods = worldfile:to_table()
|
||||||
|
|
||||||
local worldfile = Settings(filename)
|
local rawlist = this.data.list:get_raw_list()
|
||||||
local mods = worldfile:to_table()
|
|
||||||
|
|
||||||
local rawlist = this.data.list:get_raw_list()
|
local i,mod
|
||||||
|
for i,mod in ipairs(rawlist) do
|
||||||
|
if not mod.is_modpack and
|
||||||
|
mod.typ ~= "game_mod" then
|
||||||
|
if modname_valid(mod.name) then
|
||||||
|
worldfile:set("load_mod_"..mod.name, tostring(mod.enabled))
|
||||||
|
else
|
||||||
|
if mod.enabled then
|
||||||
|
gamedata.errormessage = fgettext_ne("Failed to enable mod \"$1\" as it contains disallowed characters. Only chararacters [a-z0-9_] are allowed.", mod.name)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
mods["load_mod_"..mod.name] = nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
local i,mod
|
-- Remove mods that are not present anymore
|
||||||
for i,mod in ipairs(rawlist) do
|
for key,value in pairs(mods) do
|
||||||
if not mod.is_modpack and
|
if key:sub(1,9) == "load_mod_" then
|
||||||
mod.typ ~= "game_mod" then
|
worldfile:remove(key)
|
||||||
if mod.enabled then
|
end
|
||||||
worldfile:set("load_mod_"..mod.name, "true")
|
end
|
||||||
else
|
|
||||||
worldfile:set("load_mod_"..mod.name, "false")
|
|
||||||
end
|
|
||||||
mods["load_mod_"..mod.name] = nil
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Remove mods that are not present anymore
|
if not worldfile:write() then
|
||||||
for key,value in pairs(mods) do
|
core.log("error", "Failed to write world config file")
|
||||||
if key:sub(1,9) == "load_mod_" then
|
end
|
||||||
worldfile:remove(key)
|
|
||||||
end
|
this:delete()
|
||||||
end
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
if not worldfile:write() then
|
if fields["btn_config_world_cancel"] then
|
||||||
multicraft.log("error", "Failed to write world config file")
|
this:delete()
|
||||||
end
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
this:delete()
|
if fields["btn_all_mods"] then
|
||||||
return true
|
local list = this.data.list:get_raw_list()
|
||||||
end
|
|
||||||
|
|
||||||
if fields["btn_config_world_cancel"] then
|
for i=1,#list,1 do
|
||||||
this:delete()
|
if list[i].typ ~= "game_mod" and
|
||||||
return true
|
not list[i].is_modpack then
|
||||||
end
|
list[i].enabled = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
if fields["btn_all_mods"] then
|
return false
|
||||||
local list = this.data.list:get_raw_list()
|
|
||||||
|
|
||||||
for i=1,#list,1 do
|
|
||||||
if list[i].typ ~= "game_mod" and
|
|
||||||
not list[i].is_modpack then
|
|
||||||
list[i].enabled = true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
return false
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function create_configure_world_dlg(worldidx)
|
function create_configure_world_dlg(worldidx)
|
||||||
|
|
||||||
local dlg = dialog_create("sp_config_world",
|
local dlg = dialog_create("sp_config_world",
|
||||||
get_formspec,
|
get_formspec,
|
||||||
handle_buttons,
|
handle_buttons,
|
||||||
nil)
|
nil)
|
||||||
|
|
||||||
dlg.data.hide_gamemods = multicraft.setting_getbool("world_config_hide_gamemods")
|
dlg.data.hide_gamemods = core.setting_getbool("world_config_hide_gamemods")
|
||||||
dlg.data.hide_modpackcontents = multicraft.setting_getbool("world_config_hide_modpackcontents")
|
dlg.data.hide_modpackcontents = core.setting_getbool("world_config_hide_modpackcontents")
|
||||||
dlg.data.selected_mod = tonumber(multicraft.setting_get("world_config_selected_mod"))
|
dlg.data.selected_mod = tonumber(core.setting_get("world_config_selected_mod"))
|
||||||
if dlg.data.selected_mod == nil then
|
if dlg.data.selected_mod == nil then
|
||||||
dlg.data.selected_mod = 0
|
dlg.data.selected_mod = 0
|
||||||
end
|
end
|
||||||
|
|
||||||
dlg.data.worldspec = multicraft.get_worlds()[worldidx]
|
dlg.data.worldspec = core.get_worlds()[worldidx]
|
||||||
if dlg.data.worldspec == nil then dlg:delete() return nil end
|
if dlg.data.worldspec == nil then dlg:delete() return nil end
|
||||||
|
|
||||||
dlg.data.worldconfig = modmgr.get_worldconfig(dlg.data.worldspec.path)
|
dlg.data.worldconfig = modmgr.get_worldconfig(dlg.data.worldspec.path)
|
||||||
|
|
||||||
|
if dlg.data.worldconfig == nil or dlg.data.worldconfig.id == nil or
|
||||||
|
dlg.data.worldconfig.id == "" then
|
||||||
|
|
||||||
if dlg.data.worldconfig == nil or dlg.data.worldconfig.id == nil or
|
dlg:delete()
|
||||||
dlg.data.worldconfig.id == "" then
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
|
dlg.data.list = filterlist.create(
|
||||||
|
modmgr.preparemodlist, --refresh
|
||||||
|
modmgr.comparemod, --compare
|
||||||
|
function(element,uid) --uid match
|
||||||
|
if element.name == uid then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
function(element,criteria)
|
||||||
|
if criteria.hide_game and
|
||||||
|
element.typ == "game_mod" then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
dlg:delete()
|
if criteria.hide_modpackcontents and
|
||||||
return nil
|
element.modpack ~= nil then
|
||||||
end
|
return false
|
||||||
|
end
|
||||||
dlg.data.list = filterlist.create(
|
return true
|
||||||
modmgr.preparemodlist, --refresh
|
end, --filter
|
||||||
modmgr.comparemod, --compare
|
{ worldpath= dlg.data.worldspec.path,
|
||||||
function(element,uid) --uid match
|
gameid = dlg.data.worldspec.gameid }
|
||||||
if element.name == uid then
|
)
|
||||||
return true
|
|
||||||
end
|
|
||||||
end,
|
|
||||||
function(element,criteria)
|
|
||||||
if criteria.hide_game and
|
|
||||||
element.typ == "game_mod" then
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
|
||||||
if criteria.hide_modpackcontents and
|
|
||||||
element.modpack ~= nil then
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
return true
|
|
||||||
end, --filter
|
|
||||||
{ worldpath= dlg.data.worldspec.path,
|
|
||||||
gameid = dlg.data.worldspec.gameid }
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
if dlg.data.selected_mod > dlg.data.list:size() then
|
if dlg.data.selected_mod > dlg.data.list:size() then
|
||||||
dlg.data.selected_mod = 0
|
dlg.data.selected_mod = 0
|
||||||
end
|
end
|
||||||
|
|
||||||
dlg.data.list:set_filtercriteria(
|
dlg.data.list:set_filtercriteria(
|
||||||
{
|
{
|
||||||
hide_game=dlg.data.hide_gamemods,
|
hide_game=dlg.data.hide_gamemods,
|
||||||
hide_modpackcontents= dlg.data.hide_modpackcontents
|
hide_modpackcontents= dlg.data.hide_modpackcontents
|
||||||
})
|
})
|
||||||
dlg.data.list:add_sort_mechanism("alphabetic", sort_mod_list)
|
dlg.data.list:add_sort_mechanism("alphabetic", sort_mod_list)
|
||||||
dlg.data.list:set_sortmode("alphabetic")
|
dlg.data.list:set_sortmode("alphabetic")
|
||||||
|
|
||||||
return dlg
|
return dlg
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
--
|
--
|
||||||
--This program is free software; you can redistribute it and/or modify
|
--This program is free software; you can redistribute it and/or modify
|
||||||
--it under the terms of the GNU Lesser General Public License as published by
|
--it under the terms of the GNU Lesser General Public License as published by
|
||||||
--the Free Software Foundation; either version 3.0 of the License, or
|
--the Free Software Foundation; either version 2.1 of the License, or
|
||||||
--(at your option) any later version.
|
--(at your option) any later version.
|
||||||
--
|
--
|
||||||
--This program is distributed in the hope that it will be useful,
|
--This program is distributed in the hope that it will be useful,
|
||||||
|
@ -16,138 +16,128 @@
|
||||||
--51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
--51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
|
||||||
local function create_world_formspec(dialogdata)
|
local function create_world_formspec(dialogdata)
|
||||||
local mapgens = core.get_mapgen_names()
|
local mapgens = core.get_mapgen_names()
|
||||||
|
|
||||||
local current_seed = core.setting_get("fixed_map_seed") or ""
|
local current_seed = core.setting_get("fixed_map_seed") or ""
|
||||||
local current_mg = core.setting_get("mg_name")
|
local current_mg = core.setting_get("mg_name")
|
||||||
|
|
||||||
local mglist = ""
|
local mglist = ""
|
||||||
local selindex = 1
|
local selindex = 1
|
||||||
local i = 1
|
local i = 1
|
||||||
for k,v in pairs(mapgens) do
|
for k,v in pairs(mapgens) do
|
||||||
if current_mg == v then
|
if current_mg == v then
|
||||||
selindex = i
|
selindex = i
|
||||||
end
|
end
|
||||||
i = i + 1
|
i = i + 1
|
||||||
mglist = mglist .. v .. ","
|
mglist = mglist .. v .. ","
|
||||||
end
|
end
|
||||||
mglist = mglist:sub(1, -2)
|
mglist = mglist:sub(1, -2)
|
||||||
|
|
||||||
|
local gameid = core.setting_get("menu_last_game")
|
||||||
|
|
||||||
|
local game, gameidx = nil , 0
|
||||||
|
if gameid ~= nil then
|
||||||
|
game, gameidx = gamemgr.find_by_gameid(gameid)
|
||||||
|
|
||||||
|
if gameidx == nil then
|
||||||
|
gameidx = 0
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
local gameid = core.setting_get("menu_last_game")
|
current_seed = core.formspec_escape(current_seed)
|
||||||
|
local retval =
|
||||||
|
"size[12,6,true]" ..
|
||||||
|
"label[2,0;" .. fgettext("World name") .. "]"..
|
||||||
|
"field[4.5,0.4;6,0.5;te_world_name;;]" ..
|
||||||
|
|
||||||
local game, gameidx = nil , 0
|
"label[2,1;" .. fgettext("Seed") .. "]"..
|
||||||
if gameid ~= nil then
|
"field[4.5,1.4;6,0.5;te_seed;;".. current_seed .. "]" ..
|
||||||
game, gameidx = gamemgr.find_by_gameid(gameid)
|
|
||||||
|
|
||||||
if gameidx == nil then
|
"label[2,2;" .. fgettext("Mapgen") .. "]"..
|
||||||
gameidx = 1
|
"dropdown[4.2,2;6.3;dd_mapgen;" .. mglist .. ";" .. selindex .. "]" ..
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
current_seed = core.formspec_escape(current_seed)
|
"label[2,3;" .. fgettext("Game") .. "]"..
|
||||||
local retval =
|
"textlist[4.2,3;5.8,2.3;games;" .. gamemgr.gamelist() ..
|
||||||
"size[16,11]"..
|
";" .. gameidx .. ";true]" ..
|
||||||
"bgcolor[#00000070;true]"..
|
|
||||||
"box[-100,8.5;200,10;#999999]" ..
|
|
||||||
"box[-100,-10;200,12;#999999]" ..
|
|
||||||
|
|
||||||
"label[4,4;" .. fgettext("World name") .. "]"..
|
"button[5,5.5;2.6,0.5;world_create_confirm;" .. fgettext("Create") .. "]" ..
|
||||||
"field[6.5,4.4;6,0.5;te_world_name;;]" ..
|
"button[7.5,5.5;2.8,0.5;world_create_cancel;" .. fgettext("Cancel") .. "]"
|
||||||
|
|
||||||
|
if #gamemgr.games == 0 then
|
||||||
|
retval = retval .. "box[2,4;8,1;#ff8800]label[2.25,4;" ..
|
||||||
|
fgettext("You have no subgames installed.") .. "]label[2.25,4.4;" ..
|
||||||
|
fgettext("Download one from minetest.net") .. "]"
|
||||||
|
elseif #gamemgr.games == 1 and gamemgr.games[1].id == "minimal" then
|
||||||
|
retval = retval .. "box[1.75,4;8.7,1;#ff8800]label[2,4;" ..
|
||||||
|
fgettext("Warning: The minimal development test is meant for developers.") .. "]label[2,4.4;" ..
|
||||||
|
fgettext("Download a subgame, such as minetest_game, from minetest.net") .. "]"
|
||||||
|
end
|
||||||
|
|
||||||
"label[4,5;" .. fgettext("Seed") .. "]"..
|
return retval
|
||||||
"field[6.5,5.4;6,0.5;te_seed;;".. current_seed .. "]" ..
|
|
||||||
|
|
||||||
-- "label[4,5;" .. fgettext("Mapgen") .. "]"..
|
|
||||||
-- "dropdown[6.2,5;6.3;dd_mapgen;" .. mglist .. ";" .. selindex .. "]" ..
|
|
||||||
|
|
||||||
-- "label[4,6;" .. fgettext("Game") .. "]"..
|
|
||||||
"dropdown[6000.2,6;6.3;games;" .. gamemgr.gamelist() ..
|
|
||||||
";1]" ..
|
|
||||||
|
|
||||||
|
|
||||||
"image_button[8,9.55;3.95,0.8;"..core.formspec_escape(mm_texture.basetexturedir).."menu_button.png;world_create_confirm;".. fgettext("Create") .. ";true;true;"..core.formspec_escape(mm_texture.basetexturedir).."menu_button_b.png]"..
|
|
||||||
"image_button[12,9.55;4,0.8;"..core.formspec_escape(mm_texture.basetexturedir).."menu_button.png;world_create_cancel;".. fgettext("Cancel") .. ";true;true;"..core.formspec_escape(mm_texture.basetexturedir).."menu_button_b.png]"
|
|
||||||
|
|
||||||
if #gamemgr.games == 0 then
|
|
||||||
retval = retval .. "box[4,7;8,1;#ff8800]label[4.25,7;" ..
|
|
||||||
fgettext("You have no subgames installed.") .. "]label[4.25,7.4;" ..
|
|
||||||
fgettext("Download one from minetest.net") .. "]"
|
|
||||||
elseif #gamemgr.games == 1 and gamemgr.games[1].id == "minimal" then
|
|
||||||
retval = retval .. "box[3.50,7;9,1;#ff8800]label[3.75,7;" ..
|
|
||||||
fgettext("Warning: The minimal development test is meant for developers.") .. "]label[3.75,7.4;" ..
|
|
||||||
fgettext("Download a subgame, such as minetest_game, from minetest.net") .. "]"
|
|
||||||
end
|
|
||||||
|
|
||||||
return retval
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local function create_world_buttonhandler(this, fields)
|
local function create_world_buttonhandler(this, fields)
|
||||||
core.set_clouds(false)
|
|
||||||
|
|
||||||
if fields["world_create_cancel"] then
|
if fields["world_create_confirm"] or
|
||||||
this:delete()
|
fields["key_enter"] then
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
if fields["world_create_confirm"] or
|
local worldname = fields["te_world_name"]
|
||||||
fields["key_enter"] then
|
local gameindex = core.get_textlist_index("games")
|
||||||
|
|
||||||
local worldname = fields["te_world_name"]
|
if gameindex ~= nil and
|
||||||
local gameindex
|
worldname ~= "" then
|
||||||
for i,item in ipairs(gamemgr.games) do
|
|
||||||
if item.name == fields["games"] then
|
|
||||||
gameindex = i
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if gameindex ~= nil and
|
|
||||||
worldname ~= "" then
|
|
||||||
|
|
||||||
local message = nil
|
local message = nil
|
||||||
|
|
||||||
if not menudata.worldlist:uid_exists_raw(worldname) then
|
core.setting_set("fixed_map_seed", fields["te_seed"])
|
||||||
core.setting_set("mg_name","v6")
|
|
||||||
message = core.create_world(worldname,gameindex)
|
|
||||||
else
|
|
||||||
message = fgettext("A world named \"$1\" already exists", worldname)
|
|
||||||
end
|
|
||||||
|
|
||||||
core.setting_set("fixed_map_seed", fields["te_seed"])
|
if not menudata.worldlist:uid_exists_raw(worldname) then
|
||||||
|
core.setting_set("mg_name",fields["dd_mapgen"])
|
||||||
|
message = core.create_world(worldname,gameindex)
|
||||||
|
else
|
||||||
|
message = fgettext("A world named \"$1\" already exists", worldname)
|
||||||
|
end
|
||||||
|
|
||||||
if message ~= nil then
|
if message ~= nil then
|
||||||
gamedata.errormessage = message
|
gamedata.errormessage = message
|
||||||
else
|
else
|
||||||
core.setting_set("menu_last_game",gamemgr.games[gameindex].id)
|
core.setting_set("menu_last_game",gamemgr.games[gameindex].id)
|
||||||
if this.data.update_worldlist_filter then
|
if this.data.update_worldlist_filter then
|
||||||
menudata.worldlist:set_filtercriteria(gamemgr.games[gameindex].id)
|
menudata.worldlist:set_filtercriteria(gamemgr.games[gameindex].id)
|
||||||
-- mm_texture.update("singleplayer", gamemgr.games[gameindex].id)
|
mm_texture.update("singleplayer", gamemgr.games[gameindex].id)
|
||||||
end
|
end
|
||||||
menudata.worldlist:refresh()
|
menudata.worldlist:refresh()
|
||||||
core.setting_set("mainmenu_last_selected_world",
|
core.setting_set("mainmenu_last_selected_world",
|
||||||
menudata.worldlist:raw_index_by_uid(worldname))
|
menudata.worldlist:raw_index_by_uid(worldname))
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
gamedata.errormessage =
|
gamedata.errormessage =
|
||||||
fgettext("No worldname given or no game selected")
|
fgettext("No worldname given or no game selected")
|
||||||
end
|
end
|
||||||
this:delete()
|
this:delete()
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
if fields["games"] then
|
if fields["games"] then
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if fields["world_create_cancel"] then
|
||||||
|
this:delete()
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function create_create_world_dlg(update_worldlistfilter)
|
function create_create_world_dlg(update_worldlistfilter)
|
||||||
local retval = dialog_create("sp_create_world",
|
local retval = dialog_create("sp_create_world",
|
||||||
create_world_formspec,
|
create_world_formspec,
|
||||||
create_world_buttonhandler,
|
create_world_buttonhandler,
|
||||||
nil)
|
nil)
|
||||||
retval.update_worldlist_filter = update_worldlistfilter
|
retval.update_worldlist_filter = update_worldlistfilter
|
||||||
|
|
||||||
return retval
|
return retval
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
--
|
--
|
||||||
--This program is free software; you can redistribute it and/or modify
|
--This program is free software; you can redistribute it and/or modify
|
||||||
--it under the terms of the GNU Lesser General Public License as published by
|
--it under the terms of the GNU Lesser General Public License as published by
|
||||||
--the Free Software Foundation; either version 3.0 of the License, or
|
--the Free Software Foundation; either version 2.1 of the License, or
|
||||||
--(at your option) any later version.
|
--(at your option) any later version.
|
||||||
--
|
--
|
||||||
--This program is distributed in the hope that it will be useful,
|
--This program is distributed in the hope that it will be useful,
|
||||||
|
@ -18,56 +18,51 @@
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
local function delete_mod_formspec(dialogdata)
|
local function delete_mod_formspec(dialogdata)
|
||||||
|
|
||||||
|
dialogdata.mod = modmgr.global_mods:get_list()[dialogdata.selected]
|
||||||
|
|
||||||
dialogdata.mod = modmgr.global_mods:get_list()[dialogdata.selected]
|
local retval =
|
||||||
|
"size[12.4,5,true]" ..
|
||||||
local retval =
|
"field[1.75,1;10,3;;" .. fgettext("Are you sure you want to delete \"$1\"?", dialogdata.mod.name) .. ";]"..
|
||||||
"size[16,11]"..
|
"button[4,4.2;1,0.5;dlg_delete_mod_confirm;" .. fgettext("Yes") .. "]" ..
|
||||||
"bgcolor[#00000070;true]"..
|
"button[6.5,4.2;3,0.5;dlg_delete_mod_cancel;" .. fgettext("No of course not!") .. "]"
|
||||||
"box[-100,8.5;200,10;#999999]" ..
|
|
||||||
"box[-100,-10;200,12;#999999]" ..
|
return retval
|
||||||
"label[6.5,4.5;" ..
|
|
||||||
fgettext("Are you sure you want to delete \"$1\"?", dialogdata.mod.name) .. ";]"..
|
|
||||||
"image_button[4,5.7;4,0.8;"..multicraft.formspec_escape(mm_texture.basetexturedir).."menu_button.png;dlg_delete_mod_confirm;" .. fgettext("Yes").. ";true;true;"..multicraft.formspec_escape(mm_texture.basetexturedir).."menu_button_b.png]"..
|
|
||||||
"image_button[8,5.7;4,0.8;"..multicraft.formspec_escape(mm_texture.basetexturedir).."menu_button.png;dlg_delete_mod_cancel;" .. fgettext("No") .. ";true;true;"..multicraft.formspec_escape(mm_texture.basetexturedir).."menu_button_b.png]"
|
|
||||||
return retval
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
local function delete_mod_buttonhandler(this, fields)
|
local function delete_mod_buttonhandler(this, fields)
|
||||||
multicraft.set_clouds(false)
|
if fields["dlg_delete_mod_confirm"] ~= nil then
|
||||||
|
|
||||||
if fields["dlg_delete_mod_confirm"] ~= nil then
|
if this.data.mod.path ~= nil and
|
||||||
|
this.data.mod.path ~= "" and
|
||||||
|
this.data.mod.path ~= core.get_modpath() then
|
||||||
|
if not core.delete_dir(this.data.mod.path) then
|
||||||
|
gamedata.errormessage = fgettext("Modmgr: failed to delete \"$1\"", this.data.mod.path)
|
||||||
|
end
|
||||||
|
modmgr.refresh_globals()
|
||||||
|
else
|
||||||
|
gamedata.errormessage = fgettext("Modmgr: invalid modpath \"$1\"", this.data.mod.path)
|
||||||
|
end
|
||||||
|
this:delete()
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
if fields["dlg_delete_mod_cancel"] then
|
||||||
|
this:delete()
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
if this.data.mod.path ~= nil and
|
return false
|
||||||
this.data.mod.path ~= "" and
|
|
||||||
this.data.mod.path ~= multicraft.get_modpath() then
|
|
||||||
if not multicraft.delete_dir(this.data.mod.path) then
|
|
||||||
gamedata.errormessage = fgettext("Modmgr: failed to delete \"$1\"", this.data.mod.path)
|
|
||||||
end
|
|
||||||
modmgr.refresh_globals()
|
|
||||||
else
|
|
||||||
gamedata.errormessage = fgettext("Modmgr: invalid modpath \"$1\"", this.data.mod.path)
|
|
||||||
end
|
|
||||||
this:delete()
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
if fields["dlg_delete_mod_cancel"] then
|
|
||||||
this:delete()
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
return false
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
function create_delete_mod_dlg(selected_index)
|
function create_delete_mod_dlg(selected_index)
|
||||||
|
|
||||||
local retval = dialog_create("dlg_delete_mod",
|
local retval = dialog_create("dlg_delete_mod",
|
||||||
delete_mod_formspec,
|
delete_mod_formspec,
|
||||||
delete_mod_buttonhandler,
|
delete_mod_buttonhandler,
|
||||||
nil)
|
nil)
|
||||||
retval.data.selected = selected_index
|
retval.data.selected = selected_index
|
||||||
return retval
|
return retval
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
--
|
--
|
||||||
--This program is free software; you can redistribute it and/or modify
|
--This program is free software; you can redistribute it and/or modify
|
||||||
--it under the terms of the GNU Lesser General Public License as published by
|
--it under the terms of the GNU Lesser General Public License as published by
|
||||||
--the Free Software Foundation; either version 3.0 of the License, or
|
--the Free Software Foundation; either version 2.1 of the License, or
|
||||||
--(at your option) any later version.
|
--(at your option) any later version.
|
||||||
--
|
--
|
||||||
--This program is distributed in the hope that it will be useful,
|
--This program is distributed in the hope that it will be useful,
|
||||||
|
@ -18,49 +18,47 @@
|
||||||
|
|
||||||
local function delete_world_formspec(dialogdata)
|
local function delete_world_formspec(dialogdata)
|
||||||
|
|
||||||
local retval =
|
local retval =
|
||||||
"size[16,11]"..
|
"size[12,6,true]" ..
|
||||||
"bgcolor[#00000070;true]"..
|
"label[2,2;" ..
|
||||||
"box[-100,8.5;200,10;#999999]" ..
|
fgettext("Delete World \"$1\"?", dialogdata.delete_name) .. "]"..
|
||||||
"box[-100,-10;200,12;#999999]" ..
|
"button[3.5,4.2;2.6,0.5;world_delete_confirm;" .. fgettext("Yes").. "]" ..
|
||||||
"label[6.5,4.5;" ..
|
"button[6,4.2;2.8,0.5;world_delete_cancel;" .. fgettext("No") .. "]"
|
||||||
fgettext("Delete World \"$1\"?", dialogdata.delete_name) .. "]"..
|
return retval
|
||||||
"image_button[4,5.7;4,0.8;"..multicraft.formspec_escape(mm_texture.basetexturedir).."menu_button.png;world_delete_confirm;" .. fgettext("Yes").. ";true;true;"..multicraft.formspec_escape(mm_texture.basetexturedir).."menu_button_b.png]"..
|
|
||||||
"image_button[8,5.7;4,0.8;"..multicraft.formspec_escape(mm_texture.basetexturedir).."menu_button.png;world_delete_cancel;" .. fgettext("No") .. ";true;true;"..multicraft.formspec_escape(mm_texture.basetexturedir).."menu_button_b.png]"
|
|
||||||
return retval
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local function delete_world_buttonhandler(this, fields)
|
local function delete_world_buttonhandler(this, fields)
|
||||||
multicraft.set_clouds(false)
|
if fields["world_delete_confirm"] then
|
||||||
if fields["world_delete_confirm"] then
|
|
||||||
if this.data.delete_index > 0 and
|
|
||||||
this.data.delete_index <= #menudata.worldlist:get_raw_list() then
|
|
||||||
multicraft.delete_world(this.data.delete_index)
|
|
||||||
menudata.worldlist:refresh()
|
|
||||||
end
|
|
||||||
this:delete()
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
if fields["world_delete_cancel"] then
|
if this.data.delete_index > 0 and
|
||||||
this:delete()
|
this.data.delete_index <= #menudata.worldlist:get_raw_list() then
|
||||||
return true
|
core.delete_world(this.data.delete_index)
|
||||||
end
|
menudata.worldlist:refresh()
|
||||||
return false
|
end
|
||||||
|
this:delete()
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
if fields["world_delete_cancel"] then
|
||||||
|
this:delete()
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function create_delete_world_dlg(name_to_del,index_to_del)
|
function create_delete_world_dlg(name_to_del,index_to_del)
|
||||||
|
|
||||||
assert(name_to_del ~= nil and type(name_to_del) == "string" and name_to_del ~= "")
|
assert(name_to_del ~= nil and type(name_to_del) == "string" and name_to_del ~= "")
|
||||||
assert(index_to_del ~= nil and type(index_to_del) == "number")
|
assert(index_to_del ~= nil and type(index_to_del) == "number")
|
||||||
|
|
||||||
local retval = dialog_create("delete_world",
|
local retval = dialog_create("delete_world",
|
||||||
delete_world_formspec,
|
delete_world_formspec,
|
||||||
delete_world_buttonhandler,
|
delete_world_buttonhandler,
|
||||||
nil)
|
nil)
|
||||||
retval.data.delete_name = name_to_del
|
retval.data.delete_name = name_to_del
|
||||||
retval.data.delete_index = index_to_del
|
retval.data.delete_index = index_to_del
|
||||||
|
|
||||||
return retval
|
return retval
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
--
|
--
|
||||||
--This program is free software; you can redistribute it and/or modify
|
--This program is free software; you can redistribute it and/or modify
|
||||||
--it under the terms of the GNU Lesser General Public License as published by
|
--it under the terms of the GNU Lesser General Public License as published by
|
||||||
--the Free Software Foundation; either version 3.0 of the License, or
|
--the Free Software Foundation; either version 2.1 of the License, or
|
||||||
--(at your option) any later version.
|
--(at your option) any later version.
|
||||||
--
|
--
|
||||||
--This program is distributed in the hope that it will be useful,
|
--This program is distributed in the hope that it will be useful,
|
||||||
|
@ -18,54 +18,52 @@
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
local function rename_modpack_formspec(dialogdata)
|
local function rename_modpack_formspec(dialogdata)
|
||||||
|
|
||||||
|
dialogdata.mod = modmgr.global_mods:get_list()[dialogdata.selected]
|
||||||
|
|
||||||
dialogdata.mod = modmgr.global_mods:get_list()[dialogdata.selected]
|
local retval =
|
||||||
|
"size[12.4,5,true]" ..
|
||||||
local retval =
|
"label[1.75,1;".. fgettext("Rename Modpack:") .. "]"..
|
||||||
"size[12.4,5,true]" ..
|
"field[4.5,1.4;6,0.5;te_modpack_name;;" ..
|
||||||
"label[1.75,1;".. fgettext("Rename Modpack:") .. "]"..
|
dialogdata.mod.name ..
|
||||||
"field[4.5,1.4;6,0.5;te_modpack_name;;" ..
|
"]" ..
|
||||||
dialogdata.mod.name ..
|
"button[5,4.2;2.6,0.5;dlg_rename_modpack_confirm;"..
|
||||||
"]" ..
|
fgettext("Accept") .. "]" ..
|
||||||
"image_button[5,4.2;2.6,0.8;"..multicraft.formspec_escape(mm_texture.basetexturedir).."menu_button.png;dlg_rename_modpack_confirm;"..
|
"button[7.5,4.2;2.8,0.5;dlg_rename_modpack_cancel;"..
|
||||||
fgettext("Accept") .. ";true;true;"..multicraft.formspec_escape(mm_texture.basetexturedir).."menu_button_b.png]"..
|
fgettext("Cancel") .. "]"
|
||||||
"image_button[7.5,4.2;2.8,0.8;"..multicraft.formspec_escape(mm_texture.basetexturedir).."menu_button.png;dlg_rename_modpack_cancel;"..
|
|
||||||
fgettext("Cancel") .. ";true;true;"..multicraft.formspec_escape(mm_texture.basetexturedir).."menu_button_b.png]"
|
return retval
|
||||||
|
|
||||||
return retval
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
local function rename_modpack_buttonhandler(this, fields)
|
local function rename_modpack_buttonhandler(this, fields)
|
||||||
multicraft.set_clouds(false)
|
if fields["dlg_rename_modpack_confirm"] ~= nil then
|
||||||
|
local oldpath = core.get_modpath() .. DIR_DELIM .. this.data.mod.name
|
||||||
|
local targetpath = core.get_modpath() .. DIR_DELIM .. fields["te_modpack_name"]
|
||||||
|
core.copy_dir(oldpath,targetpath,false)
|
||||||
|
modmgr.refresh_globals()
|
||||||
|
modmgr.selected_mod = modmgr.global_mods:get_current_index(
|
||||||
|
modmgr.global_mods:raw_index_by_uid(fields["te_modpack_name"]))
|
||||||
|
|
||||||
|
this:delete()
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
if fields["dlg_rename_modpack_cancel"] then
|
||||||
|
this:delete()
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
if fields["dlg_rename_modpack_confirm"] ~= nil then
|
return false
|
||||||
local oldpath = multicraft.get_modpath() .. DIR_DELIM .. this.data.mod.name
|
|
||||||
local targetpath = multicraft.get_modpath() .. DIR_DELIM .. fields["te_modpack_name"]
|
|
||||||
multicraft.copy_dir(oldpath,targetpath,false)
|
|
||||||
modmgr.refresh_globals()
|
|
||||||
modmgr.selected_mod = modmgr.global_mods:get_current_index(
|
|
||||||
modmgr.global_mods:raw_index_by_uid(fields["te_modpack_name"]))
|
|
||||||
|
|
||||||
this:delete()
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
if fields["dlg_rename_modpack_cancel"] then
|
|
||||||
this:delete()
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
return false
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
function create_rename_modpack_dlg(selected_index)
|
function create_rename_modpack_dlg(selected_index)
|
||||||
|
|
||||||
local retval = dialog_create("dlg_delete_mod",
|
local retval = dialog_create("dlg_delete_mod",
|
||||||
rename_modpack_formspec,
|
rename_modpack_formspec,
|
||||||
rename_modpack_buttonhandler,
|
rename_modpack_buttonhandler,
|
||||||
nil)
|
nil)
|
||||||
retval.data.selected = selected_index
|
retval.data.selected = selected_index
|
||||||
return retval
|
return retval
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
--
|
--
|
||||||
--This program is free software; you can redistribute it and/or modify
|
--This program is free software; you can redistribute it and/or modify
|
||||||
--it under the terms of the GNU Lesser General Public License as published by
|
--it under the terms of the GNU Lesser General Public License as published by
|
||||||
--the Free Software Foundation; either version 3.0 of the License, or
|
--the Free Software Foundation; either version 2.1 of the License, or
|
||||||
--(at your option) any later version.
|
--(at your option) any later version.
|
||||||
--
|
--
|
||||||
--This program is distributed in the hope that it will be useful,
|
--This program is distributed in the hope that it will be useful,
|
||||||
|
@ -61,7 +61,7 @@ end
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
function gamemgr.update_gamelist()
|
function gamemgr.update_gamelist()
|
||||||
gamemgr.games = multicraft.get_games()
|
gamemgr.games = core.get_games()
|
||||||
end
|
end
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
--
|
--
|
||||||
--This program is free software; you can redistribute it and/or modify
|
--This program is free software; you can redistribute it and/or modify
|
||||||
--it under the terms of the GNU Lesser General Public License as published by
|
--it under the terms of the GNU Lesser General Public License as published by
|
||||||
--the Free Software Foundation; either version 3.0 of the License, or
|
--the Free Software Foundation; either version 2.1 of the License, or
|
||||||
--(at your option) any later version.
|
--(at your option) any later version.
|
||||||
--
|
--
|
||||||
--This program is distributed in the hope that it will be useful,
|
--This program is distributed in the hope that it will be useful,
|
||||||
|
@ -22,10 +22,10 @@ mt_color_dark_green = "#003300"
|
||||||
|
|
||||||
--for all other colors ask sfan5 to complete his work!
|
--for all other colors ask sfan5 to complete his work!
|
||||||
|
|
||||||
local menupath = multicraft.get_mainmenu_path()
|
local menupath = core.get_mainmenu_path()
|
||||||
local basepath = multicraft.get_builtin_path()
|
local basepath = core.get_builtin_path()
|
||||||
defaulttexturedir = multicraft.get_texturepath_share() .. DIR_DELIM .. "base" ..
|
defaulttexturedir = core.get_texturepath_share() .. DIR_DELIM .. "base" ..
|
||||||
DIR_DELIM .. "pack" .. DIR_DELIM
|
DIR_DELIM .. "pack" .. DIR_DELIM
|
||||||
|
|
||||||
dofile(basepath .. DIR_DELIM .. "common" .. DIR_DELIM .. "async_event.lua")
|
dofile(basepath .. DIR_DELIM .. "common" .. DIR_DELIM .. "async_event.lua")
|
||||||
dofile(basepath .. DIR_DELIM .. "common" .. DIR_DELIM .. "filterlist.lua")
|
dofile(basepath .. DIR_DELIM .. "common" .. DIR_DELIM .. "filterlist.lua")
|
||||||
|
@ -41,156 +41,124 @@ dofile(menupath .. DIR_DELIM .. "dlg_config_world.lua")
|
||||||
dofile(menupath .. DIR_DELIM .. "tab_credits.lua")
|
dofile(menupath .. DIR_DELIM .. "tab_credits.lua")
|
||||||
dofile(menupath .. DIR_DELIM .. "tab_mods.lua")
|
dofile(menupath .. DIR_DELIM .. "tab_mods.lua")
|
||||||
dofile(menupath .. DIR_DELIM .. "tab_settings.lua")
|
dofile(menupath .. DIR_DELIM .. "tab_settings.lua")
|
||||||
--dofile(menupath .. DIR_DELIM .. "tab_help.lua")
|
if PLATFORM ~= "Android" then
|
||||||
dofile(menupath .. DIR_DELIM .. "dlg_create_world.lua")
|
dofile(menupath .. DIR_DELIM .. "dlg_create_world.lua")
|
||||||
dofile(menupath .. DIR_DELIM .. "dlg_delete_mod.lua")
|
dofile(menupath .. DIR_DELIM .. "dlg_delete_mod.lua")
|
||||||
dofile(menupath .. DIR_DELIM .. "dlg_delete_world.lua")
|
dofile(menupath .. DIR_DELIM .. "dlg_delete_world.lua")
|
||||||
dofile(menupath .. DIR_DELIM .. "dlg_rename_modpack.lua")
|
dofile(menupath .. DIR_DELIM .. "dlg_rename_modpack.lua")
|
||||||
dofile(menupath .. DIR_DELIM .. "dlg_add_server.lua")
|
dofile(menupath .. DIR_DELIM .. "tab_multiplayer.lua")
|
||||||
dofile(menupath .. DIR_DELIM .. "tab_multiplayer.lua")
|
dofile(menupath .. DIR_DELIM .. "tab_server.lua")
|
||||||
dofile(menupath .. DIR_DELIM .. "tab_server.lua")
|
dofile(menupath .. DIR_DELIM .. "tab_singleplayer.lua")
|
||||||
dofile(menupath .. DIR_DELIM .. "tab_singleplayer.lua")
|
dofile(menupath .. DIR_DELIM .. "tab_texturepacks.lua")
|
||||||
dofile(menupath .. DIR_DELIM .. "tab_texturepacks.lua")
|
dofile(menupath .. DIR_DELIM .. "textures.lua")
|
||||||
dofile(menupath .. DIR_DELIM .. "textures.lua")
|
else
|
||||||
|
dofile(menupath .. DIR_DELIM .. "tab_simple_main.lua")
|
||||||
|
end
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
local function main_event_handler(tabview, event)
|
local function main_event_handler(tabview, event)
|
||||||
if event == "MenuQuit" then
|
if event == "MenuQuit" then
|
||||||
multicraft.close()
|
core.close()
|
||||||
end
|
end
|
||||||
|
return true
|
||||||
return true
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
local function get_formspec2(tabview, name, tabdata)
|
|
||||||
math.randomseed(os.time())
|
|
||||||
local retval = ""
|
|
||||||
retval = retval .. "bgcolor[#00000000;false]"
|
|
||||||
retval = retval .. "image_button[2.5,3.4;7,1;"..multicraft.formspec_escape(mm_texture.basetexturedir) .. "menu_button.png;btn_show_multiplayer;" .. fgettext("Multiplayer") .. ";true;true;" .. multicraft.formspec_escape(mm_texture.basetexturedir).."menu_button_b.png]"
|
|
||||||
retval = retval .. "image_button[2.5,4.8;7,1;"..multicraft.formspec_escape(mm_texture.basetexturedir).."menu_button.png;btn_show_options;".. fgettext("Options") .. ";true;true;"..multicraft.formspec_escape(mm_texture.basetexturedir).."menu_button_b.png]"
|
|
||||||
--retval = retval .. "image_button[8.5,4.8;1,1;"..multicraft.formspec_escape(mm_texture.basetexturedir).."menu_button.png;btn_show_help;?;true;true;"..multicraft.formspec_escape(mm_texture.basetexturedir).."menu_button_b.png]"
|
|
||||||
retval = retval .. "image_button[2.5,6.2;7,1;"..multicraft.formspec_escape(mm_texture.basetexturedir).."menu_button.png;btn_exit;".. fgettext("Exit") .. ";true;true;"..multicraft.formspec_escape(mm_texture.basetexturedir).."menu_button_b.png]"
|
|
||||||
retval = retval .. 'image_button[0,-2;6.5,3;'..multicraft.formspec_escape(mm_texture.basetexturedir)..'ad_label'..tostring(math.random(1,11))..".png;btn_ad;;true;false]"
|
|
||||||
retval = retval .. "image_button[2.5,2.0;7,1;"..multicraft.formspec_escape(mm_texture.basetexturedir).."menu_button.png;btn_show_singleplayer;".. fgettext("Singleplayer") .. ";true;true;"..multicraft.formspec_escape(mm_texture.basetexturedir).."menu_button_b.png]"
|
|
||||||
return retval
|
|
||||||
end
|
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
local function main_button_handler2(tabview, fields, name, tabdata)
|
|
||||||
local index = ''
|
|
||||||
if fields["btn_show_singleplayer"] then index = "singleplayer" end
|
|
||||||
if fields["btn_show_multiplayer"] then index = "multiplayer" end
|
|
||||||
if fields["btn_show_options"] then index = "settings" end
|
|
||||||
--if fields["btn_show_help"] then index = "help" end
|
|
||||||
if fields["btn_exit"] then multicraft.close() end
|
|
||||||
|
|
||||||
if index == '' then return end
|
|
||||||
for name,def in pairs(tabview.tablist) do
|
|
||||||
if index == def.name then
|
|
||||||
local get_fs = function()
|
|
||||||
local retval = def.get_formspec(tabview, name, tabdata)
|
|
||||||
retval = 'size[12,5.2]'..retval
|
|
||||||
return retval
|
|
||||||
end
|
|
||||||
local dlg = dialog_create(def.name, get_fs, def.button_handler, def.on_change)
|
|
||||||
dlg:set_parent(tabview)
|
|
||||||
tabview:hide()
|
|
||||||
dlg:show()
|
|
||||||
return dlg
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
local function on_activate2(type,old_tab,new_tab)
|
|
||||||
if type == "LEAVE" then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
if multicraft.setting_getbool("public_serverlist") then
|
|
||||||
asyncOnlineFavourites()
|
|
||||||
else
|
|
||||||
menudata.favorites = multicraft.get_favorites("local")
|
|
||||||
end
|
|
||||||
mm_texture.clear("header")
|
|
||||||
mm_texture.clear("footer")
|
|
||||||
multicraft.set_clouds(false)
|
|
||||||
multicraft.set_background("background",multicraft.formspec_escape(mm_texture.basetexturedir)..'background.jpeg')
|
|
||||||
multicraft.set_background("header",multicraft.formspec_escape(mm_texture.basetexturedir)..'header.png')
|
|
||||||
end
|
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
tab_main = {
|
|
||||||
name = "main",
|
|
||||||
caption = fgettext("Main"),
|
|
||||||
cbf_formspec = get_formspec2,
|
|
||||||
cbf_button_handler = main_button_handler2,
|
|
||||||
on_change = on_activate2
|
|
||||||
}
|
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
local function init_globals()
|
local function init_globals()
|
||||||
-- Init gamedata
|
-- Init gamedata
|
||||||
gamedata.worldindex = 0
|
gamedata.worldindex = 0
|
||||||
|
|
||||||
menudata.worldlist = filterlist.create(
|
|
||||||
multicraft.get_worlds,
|
|
||||||
compare_worlds,
|
|
||||||
-- Unique id comparison function
|
|
||||||
function(element, uid)
|
|
||||||
return element.name == uid
|
|
||||||
end,
|
|
||||||
-- Filter function
|
|
||||||
function(element, gameid)
|
|
||||||
return element.gameid == gameid
|
|
||||||
end
|
|
||||||
)
|
|
||||||
|
|
||||||
menudata.worldlist:add_sort_mechanism("alphabetic", sort_worlds_alphabetic)
|
|
||||||
menudata.worldlist:set_sortmode("alphabetic")
|
|
||||||
|
|
||||||
if not multicraft.setting_get("menu_last_game") then
|
|
||||||
local default_game = multicraft.setting_get("default_game") or "magichet"
|
|
||||||
multicraft.setting_set("menu_last_game", default_game )
|
|
||||||
end
|
|
||||||
|
|
||||||
mm_texture.init()
|
|
||||||
|
|
||||||
|
|
||||||
-- Create main tabview
|
if PLATFORM ~= "Android" then
|
||||||
local tv_main = tabview_create("maintab",{x=12,y=5.2},{x=0,y=0})
|
menudata.worldlist = filterlist.create(
|
||||||
|
core.get_worlds,
|
||||||
|
compare_worlds,
|
||||||
|
-- Unique id comparison function
|
||||||
|
function(element, uid)
|
||||||
|
return element.name == uid
|
||||||
|
end,
|
||||||
|
-- Filter function
|
||||||
|
function(element, gameid)
|
||||||
|
return element.gameid == gameid
|
||||||
|
end
|
||||||
|
)
|
||||||
|
|
||||||
tv_main:set_autosave_tab(false)
|
menudata.worldlist:add_sort_mechanism("alphabetic", sort_worlds_alphabetic)
|
||||||
--tv_main:add(tab_simple_main)
|
menudata.worldlist:set_sortmode("alphabetic")
|
||||||
tv_main:add(tab_main)
|
|
||||||
tv_main:add(tab_singleplayer)
|
|
||||||
tv_main:add(tab_multiplayer)
|
|
||||||
tv_main:add(tab_server)
|
|
||||||
tv_main:add(tab_settings)
|
|
||||||
tv_main:add(tab_texturepacks)
|
|
||||||
tv_main:add(tab_mods)
|
|
||||||
--tv_main:add(tab_help)
|
|
||||||
tv_main:add(tab_credits)
|
|
||||||
|
|
||||||
tv_main:set_global_event_handler(main_event_handler)
|
if not core.setting_get("menu_last_game") then
|
||||||
tv_main:set_fixed_size(false)
|
local default_game = core.setting_get("default_game") or "minetest"
|
||||||
ui.set_default("main")
|
core.setting_set("menu_last_game", default_game )
|
||||||
|
end
|
||||||
|
|
||||||
tv_main:show()
|
mm_texture.init()
|
||||||
|
else
|
||||||
|
local world_list = core.get_worlds()
|
||||||
|
|
||||||
-- Create modstore ui
|
local found_singleplayerworld = false
|
||||||
if PLATFORM == "Android" then
|
|
||||||
modstore.init({x=12, y=6}, 3, 2)
|
|
||||||
else
|
|
||||||
modstore.init({x=12, y=8}, 4, 3)
|
|
||||||
end
|
|
||||||
|
|
||||||
ui.update()
|
for i,world in pairs(world_list) do
|
||||||
|
if world.name == "singleplayerworld" then
|
||||||
|
found_singleplayerworld = true
|
||||||
|
gamedata.worldindex = i
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
multicraft.sound_play("main_menu", true)
|
if not found_singleplayerworld then
|
||||||
|
core.create_world("singleplayerworld", 1)
|
||||||
|
|
||||||
|
local world_list = core.get_worlds()
|
||||||
|
|
||||||
|
for i,world in pairs(world_list) do
|
||||||
|
if world.name == "singleplayerworld" then
|
||||||
|
gamedata.worldindex = i
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Create main tabview
|
||||||
|
local tv_main = tabview_create("maintab",{x=12,y=5.2},{x=0,y=0})
|
||||||
|
if PLATFORM ~= "Android" then
|
||||||
|
tv_main:set_autosave_tab(true)
|
||||||
|
end
|
||||||
|
if PLATFORM ~= "Android" then
|
||||||
|
tv_main:add(tab_singleplayer)
|
||||||
|
tv_main:add(tab_multiplayer)
|
||||||
|
tv_main:add(tab_server)
|
||||||
|
else
|
||||||
|
tv_main:add(tab_simple_main)
|
||||||
|
end
|
||||||
|
tv_main:add(tab_settings)
|
||||||
|
if PLATFORM ~= "Android" then
|
||||||
|
tv_main:add(tab_texturepacks)
|
||||||
|
end
|
||||||
|
tv_main:add(tab_mods)
|
||||||
|
tv_main:add(tab_credits)
|
||||||
|
|
||||||
|
tv_main:set_global_event_handler(main_event_handler)
|
||||||
|
|
||||||
|
tv_main:set_fixed_size(false)
|
||||||
|
|
||||||
|
if not (PLATFORM == "Android") then
|
||||||
|
tv_main:set_tab(core.setting_get("maintab_LAST"))
|
||||||
|
end
|
||||||
|
ui.set_default("maintab")
|
||||||
|
tv_main:show()
|
||||||
|
|
||||||
|
-- Create modstore ui
|
||||||
|
if PLATFORM == "Android" then
|
||||||
|
modstore.init({x=12, y=6}, 3, 2)
|
||||||
|
else
|
||||||
|
modstore.init({x=12, y=8}, 4, 3)
|
||||||
|
end
|
||||||
|
|
||||||
|
ui.update()
|
||||||
|
|
||||||
|
core.sound_play("main_menu", true)
|
||||||
end
|
end
|
||||||
|
|
||||||
init_globals()
|
init_globals()
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
-- helper file to be able to debug the simple menu on PC
|
||||||
|
-- without messing around with actual menu code!
|
||||||
|
PLATFORM="Android"
|
||||||
|
dofile("builtin/mainmenu/init.lua")
|
|
@ -1,80 +0,0 @@
|
||||||
--Minetest
|
|
||||||
--Copyright (C) 2013 sapier
|
|
||||||
--
|
|
||||||
--This program is free software; you can redistribute it and/or modify
|
|
||||||
--it under the terms of the GNU Lesser General Public License as published by
|
|
||||||
--the Free Software Foundation; either version 3.0 of the License, or
|
|
||||||
--(at your option) any later version.
|
|
||||||
--
|
|
||||||
--This program is distributed in the hope that it will be useful,
|
|
||||||
--but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
--MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
--GNU Lesser General Public License for more details.
|
|
||||||
--
|
|
||||||
--You should have received a copy of the GNU Lesser General Public License along
|
|
||||||
--with this program; if not, write to the Free Software Foundation, Inc.,
|
|
||||||
--51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
||||||
|
|
||||||
menubar = {}
|
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
function menubar.handle_buttons(fields)
|
|
||||||
for i=1,#menubar.buttons,1 do
|
|
||||||
if fields[menubar.buttons[i].btn_name] ~= nil then
|
|
||||||
menu.last_game = menubar.buttons[i].index
|
|
||||||
multicraft.setting_set("main_menu_last_game_idx",menu.last_game)
|
|
||||||
menu.update_gametype()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
function menubar.refresh()
|
|
||||||
|
|
||||||
menubar.formspec = "box[-0.3,5.625;12.4,1.2;#000000]" ..
|
|
||||||
"box[-0.3,5.6;12.4,0.05;#FFFFFF]"
|
|
||||||
menubar.buttons = {}
|
|
||||||
|
|
||||||
local button_base = -0.08
|
|
||||||
|
|
||||||
local maxbuttons = #gamemgr.games
|
|
||||||
|
|
||||||
if maxbuttons > 11 then
|
|
||||||
maxbuttons = 11
|
|
||||||
end
|
|
||||||
|
|
||||||
for i=1,maxbuttons,1 do
|
|
||||||
|
|
||||||
local btn_name = "menubar_btn_" .. gamemgr.games[i].id
|
|
||||||
local buttonpos = button_base + (i-1) * 1.1
|
|
||||||
if gamemgr.games[i].menuicon_path ~= nil and
|
|
||||||
gamemgr.games[i].menuicon_path ~= "" then
|
|
||||||
|
|
||||||
menubar.formspec = menubar.formspec ..
|
|
||||||
"image_button[" .. buttonpos .. ",11.2;1.165,1.175;" ..
|
|
||||||
multicraft.formspec_escape(gamemgr.games[i].menuicon_path) .. ";" ..
|
|
||||||
btn_name .. ";;true;false]"
|
|
||||||
else
|
|
||||||
|
|
||||||
local part1 = gamemgr.games[i].id:sub(1,5)
|
|
||||||
local part2 = gamemgr.games[i].id:sub(6,10)
|
|
||||||
local part3 = gamemgr.games[i].id:sub(11)
|
|
||||||
|
|
||||||
local text = part1 .. "\n" .. part2
|
|
||||||
if part3 ~= nil and
|
|
||||||
part3 ~= "" then
|
|
||||||
text = text .. "\n" .. part3
|
|
||||||
end
|
|
||||||
menubar.formspec = menubar.formspec ..
|
|
||||||
"image_button[" .. buttonpos .. ",5.72;1.165,1.175;;" ..btn_name ..
|
|
||||||
";" .. text .. ";true;true]"
|
|
||||||
end
|
|
||||||
|
|
||||||
local toadd = {
|
|
||||||
btn_name = btn_name,
|
|
||||||
index = i,
|
|
||||||
}
|
|
||||||
|
|
||||||
table.insert(menubar.buttons,toadd)
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -3,7 +3,7 @@
|
||||||
--
|
--
|
||||||
--This program is free software; you can redistribute it and/or modify
|
--This program is free software; you can redistribute it and/or modify
|
||||||
--it under the terms of the GNU Lesser General Public License as published by
|
--it under the terms of the GNU Lesser General Public License as published by
|
||||||
--the Free Software Foundation; either version 3.0 of the License, or
|
--the Free Software Foundation; either version 2.1 of the License, or
|
||||||
--(at your option) any later version.
|
--(at your option) any later version.
|
||||||
--
|
--
|
||||||
--This program is distributed in the hope that it will be useful,
|
--This program is distributed in the hope that it will be useful,
|
||||||
|
@ -17,7 +17,7 @@
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
function get_mods(path,retval,modpack)
|
function get_mods(path,retval,modpack)
|
||||||
local mods = multicraft.get_dir_list(path, true)
|
local mods = core.get_dir_list(path, true)
|
||||||
|
|
||||||
for i=1, #mods, 1 do
|
for i=1, #mods, 1 do
|
||||||
if mods[i]:sub(1,1) ~= "." then
|
if mods[i]:sub(1,1) ~= "." then
|
||||||
|
@ -52,22 +52,23 @@ modmgr = {}
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
function modmgr.extract(modfile)
|
function modmgr.extract(modfile)
|
||||||
if modfile.type == "zip" then
|
if modfile.type == "zip" then
|
||||||
local tempfolder = os.tempfolder()
|
local tempfolder = os.tempfolder()
|
||||||
|
|
||||||
if tempfolder ~= nil and
|
if tempfolder ~= nil and
|
||||||
tempfolder ~= "" then
|
tempfolder ~= "" then
|
||||||
multicraft.create_dir(tempfolder)
|
core.create_dir(tempfolder)
|
||||||
if multicraft.extract_zip(modfile.name,tempfolder) then
|
if core.extract_zip(modfile.name,tempfolder) then
|
||||||
return tempfolder
|
return tempfolder
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
function modmgr.getbasefolder(temppath)
|
function modmgr.getbasefolder(temppath)
|
||||||
|
|
||||||
if temppath == nil then
|
if temppath == nil then
|
||||||
return {
|
return {
|
||||||
type = "invalid",
|
type = "invalid",
|
||||||
|
@ -93,7 +94,7 @@ function modmgr.getbasefolder(temppath)
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
local subdirs = multicraft.get_dir_list(temppath, true)
|
local subdirs = core.get_dir_list(temppath, true)
|
||||||
|
|
||||||
--only single mod or modpack allowed
|
--only single mod or modpack allowed
|
||||||
if #subdirs ~= 1 then
|
if #subdirs ~= 1 then
|
||||||
|
@ -131,433 +132,435 @@ end
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
function modmgr.isValidModname(modpath)
|
function modmgr.isValidModname(modpath)
|
||||||
if modpath:find("-") ~= nil then
|
if modpath:find("-") ~= nil then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
function modmgr.parse_register_line(line)
|
function modmgr.parse_register_line(line)
|
||||||
local pos1 = line:find("\"")
|
local pos1 = line:find("\"")
|
||||||
local pos2 = nil
|
local pos2 = nil
|
||||||
if pos1 ~= nil then
|
if pos1 ~= nil then
|
||||||
pos2 = line:find("\"",pos1+1)
|
pos2 = line:find("\"",pos1+1)
|
||||||
end
|
end
|
||||||
|
|
||||||
if pos1 ~= nil and pos2 ~= nil then
|
if pos1 ~= nil and pos2 ~= nil then
|
||||||
local item = line:sub(pos1+1,pos2-1)
|
local item = line:sub(pos1+1,pos2-1)
|
||||||
|
|
||||||
if item ~= nil and
|
if item ~= nil and
|
||||||
item ~= "" then
|
item ~= "" then
|
||||||
local pos3 = item:find(":")
|
local pos3 = item:find(":")
|
||||||
|
|
||||||
if pos3 ~= nil then
|
if pos3 ~= nil then
|
||||||
local retval = item:sub(1,pos3-1)
|
local retval = item:sub(1,pos3-1)
|
||||||
if retval ~= nil and
|
if retval ~= nil and
|
||||||
retval ~= "" then
|
retval ~= "" then
|
||||||
return retval
|
return retval
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
function modmgr.parse_dofile_line(modpath,line)
|
function modmgr.parse_dofile_line(modpath,line)
|
||||||
local pos1 = line:find("\"")
|
local pos1 = line:find("\"")
|
||||||
local pos2 = nil
|
local pos2 = nil
|
||||||
if pos1 ~= nil then
|
if pos1 ~= nil then
|
||||||
pos2 = line:find("\"",pos1+1)
|
pos2 = line:find("\"",pos1+1)
|
||||||
end
|
end
|
||||||
|
|
||||||
if pos1 ~= nil and pos2 ~= nil then
|
if pos1 ~= nil and pos2 ~= nil then
|
||||||
local filename = line:sub(pos1+1,pos2-1)
|
local filename = line:sub(pos1+1,pos2-1)
|
||||||
|
|
||||||
if filename ~= nil and
|
if filename ~= nil and
|
||||||
filename ~= "" and
|
filename ~= "" and
|
||||||
filename:find(".lua") then
|
filename:find(".lua") then
|
||||||
return modmgr.identify_modname(modpath,filename)
|
return modmgr.identify_modname(modpath,filename)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
function modmgr.identify_modname(modpath,filename)
|
function modmgr.identify_modname(modpath,filename)
|
||||||
local testfile = io.open(modpath .. DIR_DELIM .. filename,"r")
|
local testfile = io.open(modpath .. DIR_DELIM .. filename,"r")
|
||||||
if testfile ~= nil then
|
if testfile ~= nil then
|
||||||
local line = testfile:read()
|
local line = testfile:read()
|
||||||
|
|
||||||
while line~= nil do
|
while line~= nil do
|
||||||
local modname = nil
|
local modname = nil
|
||||||
|
|
||||||
if line:find("multicraft.register_tool") then
|
if line:find("minetest.register_tool") then
|
||||||
modname = modmgr.parse_register_line(line)
|
modname = modmgr.parse_register_line(line)
|
||||||
end
|
end
|
||||||
|
|
||||||
if line:find("multicraft.register_craftitem") then
|
if line:find("minetest.register_craftitem") then
|
||||||
modname = modmgr.parse_register_line(line)
|
modname = modmgr.parse_register_line(line)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
if line:find("multicraft.register_node") then
|
if line:find("minetest.register_node") then
|
||||||
modname = modmgr.parse_register_line(line)
|
modname = modmgr.parse_register_line(line)
|
||||||
end
|
end
|
||||||
|
|
||||||
if line:find("dofile") then
|
if line:find("dofile") then
|
||||||
modname = modmgr.parse_dofile_line(modpath,line)
|
modname = modmgr.parse_dofile_line(modpath,line)
|
||||||
end
|
end
|
||||||
|
|
||||||
if modname ~= nil then
|
if modname ~= nil then
|
||||||
testfile:close()
|
testfile:close()
|
||||||
return modname
|
return modname
|
||||||
end
|
end
|
||||||
|
|
||||||
line = testfile:read()
|
line = testfile:read()
|
||||||
end
|
end
|
||||||
testfile:close()
|
testfile:close()
|
||||||
end
|
end
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
function modmgr.render_modlist(render_list)
|
function modmgr.render_modlist(render_list)
|
||||||
local retval = ""
|
local retval = ""
|
||||||
|
|
||||||
if render_list == nil then
|
if render_list == nil then
|
||||||
if modmgr.global_mods == nil then
|
if modmgr.global_mods == nil then
|
||||||
modmgr.refresh_globals()
|
modmgr.refresh_globals()
|
||||||
end
|
end
|
||||||
render_list = modmgr.global_mods
|
render_list = modmgr.global_mods
|
||||||
end
|
end
|
||||||
|
|
||||||
local list = render_list:get_list()
|
local list = render_list:get_list()
|
||||||
local last_modpack = nil
|
local last_modpack = nil
|
||||||
|
|
||||||
for i,v in ipairs(list) do
|
for i,v in ipairs(list) do
|
||||||
if retval ~= "" then
|
if retval ~= "" then
|
||||||
retval = retval ..","
|
retval = retval ..","
|
||||||
end
|
end
|
||||||
|
|
||||||
local color = ""
|
local color = ""
|
||||||
|
|
||||||
if v.is_modpack then
|
if v.is_modpack then
|
||||||
local rawlist = render_list:get_raw_list()
|
local rawlist = render_list:get_raw_list()
|
||||||
|
|
||||||
local all_enabled = true
|
local all_enabled = true
|
||||||
for j=1,#rawlist,1 do
|
for j=1,#rawlist,1 do
|
||||||
if rawlist[j].modpack == list[i].name and
|
if rawlist[j].modpack == list[i].name and
|
||||||
rawlist[j].enabled ~= true then
|
rawlist[j].enabled ~= true then
|
||||||
all_enabled = false
|
all_enabled = false
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if all_enabled == false then
|
if all_enabled == false then
|
||||||
color = mt_color_grey
|
color = mt_color_grey
|
||||||
else
|
else
|
||||||
color = mt_color_dark_green
|
color = mt_color_dark_green
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if v.typ == "game_mod" then
|
if v.typ == "game_mod" then
|
||||||
color = mt_color_blue
|
color = mt_color_blue
|
||||||
else
|
else
|
||||||
if v.enabled then
|
if v.enabled then
|
||||||
color = mt_color_green
|
color = mt_color_green
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
retval = retval .. color
|
retval = retval .. color
|
||||||
if v.modpack ~= nil then
|
if v.modpack ~= nil then
|
||||||
retval = retval .. " "
|
retval = retval .. " "
|
||||||
end
|
end
|
||||||
retval = retval .. v.name
|
retval = retval .. v.name
|
||||||
end
|
end
|
||||||
|
|
||||||
return retval
|
return retval
|
||||||
end
|
end
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
function modmgr.get_dependencies(modfolder)
|
function modmgr.get_dependencies(modfolder)
|
||||||
local toadd = ""
|
local toadd = ""
|
||||||
if modfolder ~= nil then
|
if modfolder ~= nil then
|
||||||
local filename = modfolder ..
|
local filename = modfolder ..
|
||||||
DIR_DELIM .. "depends.txt"
|
DIR_DELIM .. "depends.txt"
|
||||||
|
|
||||||
local dependencyfile = io.open(filename,"r")
|
local dependencyfile = io.open(filename,"r")
|
||||||
|
|
||||||
if dependencyfile then
|
if dependencyfile then
|
||||||
local dependency = dependencyfile:read("*l")
|
local dependency = dependencyfile:read("*l")
|
||||||
while dependency do
|
while dependency do
|
||||||
if toadd ~= "" then
|
if toadd ~= "" then
|
||||||
toadd = toadd .. ","
|
toadd = toadd .. ","
|
||||||
end
|
end
|
||||||
toadd = toadd .. dependency
|
toadd = toadd .. dependency
|
||||||
dependency = dependencyfile:read()
|
dependency = dependencyfile:read()
|
||||||
end
|
end
|
||||||
dependencyfile:close()
|
dependencyfile:close()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return toadd
|
return toadd
|
||||||
end
|
end
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
function modmgr.get_worldconfig(worldpath)
|
function modmgr.get_worldconfig(worldpath)
|
||||||
local filename = worldpath ..
|
local filename = worldpath ..
|
||||||
DIR_DELIM .. "world.mt"
|
DIR_DELIM .. "world.mt"
|
||||||
|
|
||||||
local worldfile = Settings(filename)
|
local worldfile = Settings(filename)
|
||||||
|
|
||||||
local worldconfig = {}
|
local worldconfig = {}
|
||||||
worldconfig.global_mods = {}
|
worldconfig.global_mods = {}
|
||||||
worldconfig.game_mods = {}
|
worldconfig.game_mods = {}
|
||||||
|
|
||||||
for key,value in pairs(worldfile:to_table()) do
|
for key,value in pairs(worldfile:to_table()) do
|
||||||
if key == "gameid" then
|
if key == "gameid" then
|
||||||
worldconfig.id = value
|
worldconfig.id = value
|
||||||
else
|
elseif key:sub(0, 9) == "load_mod_" then
|
||||||
worldconfig.global_mods[key] = multicraft.is_yes(value)
|
worldconfig.global_mods[key] = core.is_yes(value)
|
||||||
end
|
else
|
||||||
end
|
worldconfig[key] = value
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
--read gamemods
|
--read gamemods
|
||||||
local gamespec = gamemgr.find_by_gameid(worldconfig.id)
|
local gamespec = gamemgr.find_by_gameid(worldconfig.id)
|
||||||
gamemgr.get_game_mods(gamespec, worldconfig.game_mods)
|
gamemgr.get_game_mods(gamespec, worldconfig.game_mods)
|
||||||
|
|
||||||
return worldconfig
|
return worldconfig
|
||||||
end
|
end
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
function modmgr.installmod(modfilename,basename)
|
function modmgr.installmod(modfilename,basename)
|
||||||
local modfile = modmgr.identify_filetype(modfilename)
|
local modfile = modmgr.identify_filetype(modfilename)
|
||||||
local modpath = modmgr.extract(modfile)
|
local modpath = modmgr.extract(modfile)
|
||||||
|
|
||||||
if modpath == nil then
|
if modpath == nil then
|
||||||
gamedata.errormessage = fgettext("Install Mod: file: \"$1\"", modfile.name) ..
|
gamedata.errormessage = fgettext("Install Mod: file: \"$1\"", modfile.name) ..
|
||||||
fgettext("\nInstall Mod: unsupported filetype \"$1\" or broken archive", modfile.type)
|
fgettext("\nInstall Mod: unsupported filetype \"$1\" or broken archive", modfile.type)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local basefolder = modmgr.getbasefolder(modpath)
|
local basefolder = modmgr.getbasefolder(modpath)
|
||||||
|
|
||||||
if basefolder.type == "modpack" then
|
if basefolder.type == "modpack" then
|
||||||
local clean_path = nil
|
local clean_path = nil
|
||||||
|
|
||||||
if basename ~= nil then
|
if basename ~= nil then
|
||||||
clean_path = "mp_" .. basename
|
clean_path = "mp_" .. basename
|
||||||
end
|
end
|
||||||
|
|
||||||
if clean_path == nil then
|
if clean_path == nil then
|
||||||
clean_path = get_last_folder(cleanup_path(basefolder.path))
|
clean_path = get_last_folder(cleanup_path(basefolder.path))
|
||||||
end
|
end
|
||||||
|
|
||||||
if clean_path ~= nil then
|
if clean_path ~= nil then
|
||||||
local targetpath = multicraft.get_modpath() .. DIR_DELIM .. clean_path
|
local targetpath = core.get_modpath() .. DIR_DELIM .. clean_path
|
||||||
if not multicraft.copy_dir(basefolder.path,targetpath) then
|
if not core.copy_dir(basefolder.path,targetpath) then
|
||||||
gamedata.errormessage = fgettext("Failed to install $1 to $2", basename, targetpath)
|
gamedata.errormessage = fgettext("Failed to install $1 to $2", basename, targetpath)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
gamedata.errormessage = fgettext("Install Mod: unable to find suitable foldername for modpack $1", modfilename)
|
gamedata.errormessage = fgettext("Install Mod: unable to find suitable foldername for modpack $1", modfilename)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if basefolder.type == "mod" then
|
if basefolder.type == "mod" then
|
||||||
local targetfolder = basename
|
local targetfolder = basename
|
||||||
|
|
||||||
if targetfolder == nil then
|
if targetfolder == nil then
|
||||||
targetfolder = modmgr.identify_modname(basefolder.path,"init.lua")
|
targetfolder = modmgr.identify_modname(basefolder.path,"init.lua")
|
||||||
end
|
end
|
||||||
|
|
||||||
--if heuristic failed try to use current foldername
|
--if heuristic failed try to use current foldername
|
||||||
if targetfolder == nil then
|
if targetfolder == nil then
|
||||||
targetfolder = get_last_folder(basefolder.path)
|
targetfolder = get_last_folder(basefolder.path)
|
||||||
end
|
end
|
||||||
|
|
||||||
if targetfolder ~= nil and modmgr.isValidModname(targetfolder) then
|
if targetfolder ~= nil and modmgr.isValidModname(targetfolder) then
|
||||||
local targetpath = multicraft.get_modpath() .. DIR_DELIM .. targetfolder
|
local targetpath = core.get_modpath() .. DIR_DELIM .. targetfolder
|
||||||
multicraft.copy_dir(basefolder.path,targetpath)
|
core.copy_dir(basefolder.path,targetpath)
|
||||||
else
|
else
|
||||||
gamedata.errormessage = fgettext("Install Mod: unable to find real modname for: $1", modfilename)
|
gamedata.errormessage = fgettext("Install Mod: unable to find real modname for: $1", modfilename)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
multicraft.delete_dir(modpath)
|
core.delete_dir(modpath)
|
||||||
|
|
||||||
modmgr.refresh_globals()
|
modmgr.refresh_globals()
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
function modmgr.preparemodlist(data)
|
function modmgr.preparemodlist(data)
|
||||||
local retval = {}
|
local retval = {}
|
||||||
|
|
||||||
local global_mods = {}
|
local global_mods = {}
|
||||||
local game_mods = {}
|
local game_mods = {}
|
||||||
|
|
||||||
--read global mods
|
--read global mods
|
||||||
local modpath = multicraft.get_modpath()
|
local modpath = core.get_modpath()
|
||||||
|
|
||||||
if modpath ~= nil and
|
if modpath ~= nil and
|
||||||
modpath ~= "" then
|
modpath ~= "" then
|
||||||
get_mods(modpath,global_mods)
|
get_mods(modpath,global_mods)
|
||||||
end
|
end
|
||||||
|
|
||||||
for i=1,#global_mods,1 do
|
for i=1,#global_mods,1 do
|
||||||
global_mods[i].typ = "global_mod"
|
global_mods[i].typ = "global_mod"
|
||||||
table.insert(retval,global_mods[i])
|
table.insert(retval,global_mods[i])
|
||||||
end
|
end
|
||||||
|
|
||||||
--read game mods
|
--read game mods
|
||||||
local gamespec = gamemgr.find_by_gameid(data.gameid)
|
local gamespec = gamemgr.find_by_gameid(data.gameid)
|
||||||
gamemgr.get_game_mods(gamespec, game_mods)
|
gamemgr.get_game_mods(gamespec, game_mods)
|
||||||
|
|
||||||
for i=1,#game_mods,1 do
|
for i=1,#game_mods,1 do
|
||||||
game_mods[i].typ = "game_mod"
|
game_mods[i].typ = "game_mod"
|
||||||
table.insert(retval,game_mods[i])
|
table.insert(retval,game_mods[i])
|
||||||
end
|
end
|
||||||
|
|
||||||
if data.worldpath == nil then
|
if data.worldpath == nil then
|
||||||
return retval
|
return retval
|
||||||
end
|
end
|
||||||
|
|
||||||
--read world mod configuration
|
--read world mod configuration
|
||||||
local filename = data.worldpath ..
|
local filename = data.worldpath ..
|
||||||
DIR_DELIM .. "world.mt"
|
DIR_DELIM .. "world.mt"
|
||||||
|
|
||||||
local worldfile = Settings(filename)
|
local worldfile = Settings(filename)
|
||||||
|
|
||||||
for key,value in pairs(worldfile:to_table()) do
|
for key,value in pairs(worldfile:to_table()) do
|
||||||
if key:sub(1, 9) == "load_mod_" then
|
if key:sub(1, 9) == "load_mod_" then
|
||||||
key = key:sub(10)
|
key = key:sub(10)
|
||||||
local element = nil
|
local element = nil
|
||||||
for i=1,#retval,1 do
|
for i=1,#retval,1 do
|
||||||
if retval[i].name == key and
|
if retval[i].name == key and
|
||||||
not retval[i].is_modpack then
|
not retval[i].is_modpack then
|
||||||
element = retval[i]
|
element = retval[i]
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if element ~= nil then
|
if element ~= nil then
|
||||||
element.enabled = multicraft.is_yes(value)
|
element.enabled = core.is_yes(value)
|
||||||
else
|
else
|
||||||
multicraft.log("info", "Mod: " .. key .. " " .. dump(value) .. " but not found")
|
core.log("info", "Mod: " .. key .. " " .. dump(value) .. " but not found")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return retval
|
return retval
|
||||||
end
|
end
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
function modmgr.comparemod(elem1,elem2)
|
function modmgr.comparemod(elem1,elem2)
|
||||||
if elem1 == nil or elem2 == nil then
|
if elem1 == nil or elem2 == nil then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
if elem1.name ~= elem2.name then
|
if elem1.name ~= elem2.name then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
if elem1.is_modpack ~= elem2.is_modpack then
|
if elem1.is_modpack ~= elem2.is_modpack then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
if elem1.typ ~= elem2.typ then
|
if elem1.typ ~= elem2.typ then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
if elem1.modpack ~= elem2.modpack then
|
if elem1.modpack ~= elem2.modpack then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
if elem1.path ~= elem2.path then
|
if elem1.path ~= elem2.path then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
function modmgr.mod_exists(basename)
|
function modmgr.mod_exists(basename)
|
||||||
|
|
||||||
if modmgr.global_mods == nil then
|
if modmgr.global_mods == nil then
|
||||||
modmgr.refresh_globals()
|
modmgr.refresh_globals()
|
||||||
end
|
end
|
||||||
|
|
||||||
if modmgr.global_mods:raw_index_by_uid(basename) > 0 then
|
if modmgr.global_mods:raw_index_by_uid(basename) > 0 then
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
function modmgr.get_global_mod(idx)
|
function modmgr.get_global_mod(idx)
|
||||||
|
|
||||||
if modmgr.global_mods == nil then
|
if modmgr.global_mods == nil then
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
if idx == nil or idx < 1 or
|
if idx == nil or idx < 1 or
|
||||||
idx > modmgr.global_mods:size() then
|
idx > modmgr.global_mods:size() then
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
return modmgr.global_mods:get_list()[idx]
|
return modmgr.global_mods:get_list()[idx]
|
||||||
end
|
end
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
function modmgr.refresh_globals()
|
function modmgr.refresh_globals()
|
||||||
modmgr.global_mods = filterlist.create(
|
modmgr.global_mods = filterlist.create(
|
||||||
modmgr.preparemodlist, --refresh
|
modmgr.preparemodlist, --refresh
|
||||||
modmgr.comparemod, --compare
|
modmgr.comparemod, --compare
|
||||||
function(element,uid) --uid match
|
function(element,uid) --uid match
|
||||||
if element.name == uid then
|
if element.name == uid then
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
nil, --filter
|
nil, --filter
|
||||||
{}
|
{}
|
||||||
)
|
)
|
||||||
modmgr.global_mods:add_sort_mechanism("alphabetic", sort_mod_list)
|
modmgr.global_mods:add_sort_mechanism("alphabetic", sort_mod_list)
|
||||||
modmgr.global_mods:set_sortmode("alphabetic")
|
modmgr.global_mods:set_sortmode("alphabetic")
|
||||||
end
|
end
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
function modmgr.identify_filetype(name)
|
function modmgr.identify_filetype(name)
|
||||||
|
|
||||||
if name:sub(-3):lower() == "zip" then
|
if name:sub(-3):lower() == "zip" then
|
||||||
return {
|
return {
|
||||||
name = name,
|
name = name,
|
||||||
type = "zip"
|
type = "zip"
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
if name:sub(-6):lower() == "tar.gz" or
|
if name:sub(-6):lower() == "tar.gz" or
|
||||||
name:sub(-3):lower() == "tgz"then
|
name:sub(-3):lower() == "tgz"then
|
||||||
return {
|
return {
|
||||||
name = name,
|
name = name,
|
||||||
type = "tgz"
|
type = "tgz"
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
if name:sub(-6):lower() == "tar.bz2" then
|
if name:sub(-6):lower() == "tar.bz2" then
|
||||||
return {
|
return {
|
||||||
name = name,
|
name = name,
|
||||||
type = "tbz"
|
type = "tbz"
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
if name:sub(-2):lower() == "7z" then
|
if name:sub(-2):lower() == "7z" then
|
||||||
return {
|
return {
|
||||||
name = name,
|
name = name,
|
||||||
type = "7z"
|
type = "7z"
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
return {
|
return {
|
||||||
name = name,
|
name = name,
|
||||||
type = "ukn"
|
type = "ukn"
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,616 +0,0 @@
|
||||||
--Minetest
|
|
||||||
--Copyright (C) 2013 sapier
|
|
||||||
--
|
|
||||||
--This program is free software; you can redistribute it and/or modify
|
|
||||||
--it under the terms of the GNU Lesser General Public License as published by
|
|
||||||
--the Free Software Foundation; either version 3.0 of the License, or
|
|
||||||
--(at your option) any later version.
|
|
||||||
--
|
|
||||||
--This program is distributed in the hope that it will be useful,
|
|
||||||
--but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
--MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
--GNU Lesser General Public License for more details.
|
|
||||||
--
|
|
||||||
--You should have received a copy of the GNU Lesser General Public License along
|
|
||||||
--with this program; if not, write to the Free Software Foundation, Inc.,
|
|
||||||
--51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
--modstore implementation
|
|
||||||
modstore = {}
|
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
-- @function [parent=#modstore] init
|
|
||||||
function modstore.init()
|
|
||||||
modstore.tabnames = {}
|
|
||||||
|
|
||||||
table.insert(modstore.tabnames,"dialog_modstore_unsorted")
|
|
||||||
table.insert(modstore.tabnames,"dialog_modstore_search")
|
|
||||||
|
|
||||||
modstore.modsperpage = 5
|
|
||||||
|
|
||||||
modstore.basetexturedir = multicraft.get_texturepath() .. DIR_DELIM .. "base" ..
|
|
||||||
DIR_DELIM .. "pack" .. DIR_DELIM
|
|
||||||
|
|
||||||
modstore.lastmodtitle = ""
|
|
||||||
modstore.last_search = ""
|
|
||||||
|
|
||||||
modstore.searchlist = filterlist.create(
|
|
||||||
function()
|
|
||||||
if modstore.modlist_unsorted ~= nil and
|
|
||||||
modstore.modlist_unsorted.data ~= nil then
|
|
||||||
return modstore.modlist_unsorted.data
|
|
||||||
end
|
|
||||||
return {}
|
|
||||||
end,
|
|
||||||
function(element,modid)
|
|
||||||
if element.id == modid then
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
return false
|
|
||||||
end, --compare fct
|
|
||||||
nil, --uid match fct
|
|
||||||
function(element,substring)
|
|
||||||
if substring == nil or
|
|
||||||
substring == "" then
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
substring = substring:upper()
|
|
||||||
|
|
||||||
if element.title ~= nil and
|
|
||||||
element.title:upper():find(substring) ~= nil then
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
if element.details ~= nil and
|
|
||||||
element.details.author ~= nil and
|
|
||||||
element.details.author:upper():find(substring) ~= nil then
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
if element.details ~= nil and
|
|
||||||
element.details.description ~= nil and
|
|
||||||
element.details.description:upper():find(substring) ~= nil then
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
return false
|
|
||||||
end --filter fct
|
|
||||||
)
|
|
||||||
|
|
||||||
modstore.current_list = nil
|
|
||||||
end
|
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
-- @function [parent=#modstore] nametoindex
|
|
||||||
function modstore.nametoindex(name)
|
|
||||||
|
|
||||||
for i=1,#modstore.tabnames,1 do
|
|
||||||
if modstore.tabnames[i] == name then
|
|
||||||
return i
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
return 1
|
|
||||||
end
|
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
-- @function [parent=#modstore] getsuccessfuldialog
|
|
||||||
function modstore.getsuccessfuldialog()
|
|
||||||
local retval = ""
|
|
||||||
retval = retval .. "size[6,2,true]"
|
|
||||||
if modstore.lastmodentry ~= nil then
|
|
||||||
retval = retval .. "label[0,0.25;" .. fgettext("Successfully installed:") .. "]"
|
|
||||||
retval = retval .. "label[3,0.25;" .. modstore.lastmodentry.moddetails.title .. "]"
|
|
||||||
|
|
||||||
|
|
||||||
retval = retval .. "label[0,0.75;" .. fgettext("Shortname:") .. "]"
|
|
||||||
retval = retval .. "label[3,0.75;" .. multicraft.formspec_escape(modstore.lastmodentry.moddetails.basename) .. "]"
|
|
||||||
|
|
||||||
end
|
|
||||||
retval = retval .. "button[2.5,1.5;1,0.5;btn_confirm_mod_successfull;" .. fgettext("ok") .. "]"
|
|
||||||
|
|
||||||
|
|
||||||
return retval
|
|
||||||
end
|
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
-- @function [parent=#modstore] gettab
|
|
||||||
function modstore.gettab(tabname)
|
|
||||||
local retval = ""
|
|
||||||
|
|
||||||
local is_modstore_tab = false
|
|
||||||
|
|
||||||
if tabname == "dialog_modstore_unsorted" then
|
|
||||||
modstore.modsperpage = 5
|
|
||||||
retval = modstore.getmodlist(modstore.modlist_unsorted)
|
|
||||||
is_modstore_tab = true
|
|
||||||
end
|
|
||||||
|
|
||||||
if tabname == "dialog_modstore_search" then
|
|
||||||
retval = modstore.getsearchpage()
|
|
||||||
is_modstore_tab = true
|
|
||||||
end
|
|
||||||
|
|
||||||
if is_modstore_tab then
|
|
||||||
return modstore.tabheader(tabname) .. retval
|
|
||||||
end
|
|
||||||
|
|
||||||
if tabname == "modstore_mod_installed" then
|
|
||||||
return modstore.getsuccessfuldialog()
|
|
||||||
end
|
|
||||||
|
|
||||||
if tabname == "modstore_downloading" then
|
|
||||||
return "size[6,2]label[0.25,0.75;" .. fgettext("Downloading") ..
|
|
||||||
" " .. modstore.lastmodtitle .. " " ..
|
|
||||||
fgettext("please wait...") .. "]"
|
|
||||||
end
|
|
||||||
|
|
||||||
return ""
|
|
||||||
end
|
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
-- @function [parent=#modstore] tabheader
|
|
||||||
function modstore.tabheader(tabname)
|
|
||||||
local retval = "size[12,10.25,true]"
|
|
||||||
retval = retval .. "tabheader[-0.3,-0.99;modstore_tab;" ..
|
|
||||||
"Unsorted,Search;" ..
|
|
||||||
modstore.nametoindex(tabname) .. ";true;false]" ..
|
|
||||||
"button[4,9.9;4,0.5;btn_modstore_close;" ..
|
|
||||||
fgettext("Close modstore") .. "]"
|
|
||||||
|
|
||||||
return retval
|
|
||||||
end
|
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
-- @function [parent=#modstore] handle_buttons
|
|
||||||
function modstore.handle_buttons(current_tab,fields)
|
|
||||||
multicraft.set_clouds(false)
|
|
||||||
|
|
||||||
if fields["modstore_tab"] then
|
|
||||||
local index = tonumber(fields["modstore_tab"])
|
|
||||||
|
|
||||||
if index > 0 and
|
|
||||||
index <= #modstore.tabnames then
|
|
||||||
if modstore.tabnames[index] == "dialog_modstore_search" then
|
|
||||||
filterlist.set_filtercriteria(modstore.searchlist,modstore.last_search)
|
|
||||||
filterlist.refresh(modstore.searchlist)
|
|
||||||
modstore.modsperpage = 4
|
|
||||||
modstore.currentlist = {
|
|
||||||
page = 0,
|
|
||||||
pagecount =
|
|
||||||
math.ceil(filterlist.size(modstore.searchlist) / modstore.modsperpage),
|
|
||||||
data = filterlist.get_list(modstore.searchlist),
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
return {
|
|
||||||
current_tab = modstore.tabnames[index],
|
|
||||||
is_dialog = true,
|
|
||||||
show_buttons = false
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
if fields["btn_modstore_page_up"] then
|
|
||||||
if modstore.current_list ~= nil and modstore.current_list.page > 0 then
|
|
||||||
modstore.current_list.page = modstore.current_list.page - 1
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if fields["btn_modstore_page_down"] then
|
|
||||||
if modstore.current_list ~= nil and
|
|
||||||
modstore.current_list.page <modstore.current_list.pagecount-1 then
|
|
||||||
modstore.current_list.page = modstore.current_list.page +1
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if fields["btn_hidden_close_download"] ~= nil then
|
|
||||||
if fields["btn_hidden_close_download"].successfull then
|
|
||||||
modstore.lastmodentry = fields["btn_hidden_close_download"]
|
|
||||||
return {
|
|
||||||
current_tab = "modstore_mod_installed",
|
|
||||||
is_dialog = true,
|
|
||||||
show_buttons = false
|
|
||||||
}
|
|
||||||
else
|
|
||||||
modstore.lastmodtitle = ""
|
|
||||||
return {
|
|
||||||
current_tab = modstore.tabnames[1],
|
|
||||||
is_dialog = true,
|
|
||||||
show_buttons = false
|
|
||||||
}
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if fields["btn_confirm_mod_successfull"] then
|
|
||||||
modstore.lastmodentry = nil
|
|
||||||
modstore.lastmodtitle = ""
|
|
||||||
return {
|
|
||||||
current_tab = modstore.tabnames[1],
|
|
||||||
is_dialog = true,
|
|
||||||
show_buttons = false
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
if fields["btn_modstore_search"] or
|
|
||||||
(fields["key_enter"] and fields["te_modstore_search"] ~= nil) then
|
|
||||||
modstore.last_search = fields["te_modstore_search"]
|
|
||||||
filterlist.set_filtercriteria(modstore.searchlist,fields["te_modstore_search"])
|
|
||||||
filterlist.refresh(modstore.searchlist)
|
|
||||||
modstore.currentlist = {
|
|
||||||
page = 0,
|
|
||||||
pagecount = math.ceil(filterlist.size(modstore.searchlist) / modstore.modsperpage),
|
|
||||||
data = filterlist.get_list(modstore.searchlist),
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
if fields["btn_modstore_close"] then
|
|
||||||
return {
|
|
||||||
is_dialog = false,
|
|
||||||
show_buttons = true,
|
|
||||||
current_tab = multicraft.setting_get("main_menu_tab")
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
for key,value in pairs(fields) do
|
|
||||||
local foundat = key:find("btn_install_mod_")
|
|
||||||
if ( foundat == 1) then
|
|
||||||
local modid = tonumber(key:sub(17))
|
|
||||||
for i=1,#modstore.modlist_unsorted.data,1 do
|
|
||||||
if modstore.modlist_unsorted.data[i].id == modid then
|
|
||||||
local moddetails = modstore.modlist_unsorted.data[i].details
|
|
||||||
|
|
||||||
if modstore.lastmodtitle ~= "" then
|
|
||||||
modstore.lastmodtitle = modstore.lastmodtitle .. ", "
|
|
||||||
end
|
|
||||||
|
|
||||||
modstore.lastmodtitle = modstore.lastmodtitle .. moddetails.title
|
|
||||||
|
|
||||||
multicraft.handle_async(
|
|
||||||
function(param)
|
|
||||||
|
|
||||||
local fullurl = multicraft.setting_get("modstore_download_url") ..
|
|
||||||
param.moddetails.download_url
|
|
||||||
|
|
||||||
if param.version ~= nil then
|
|
||||||
local found = false
|
|
||||||
for i=1,#param.moddetails.versions, 1 do
|
|
||||||
if param.moddetails.versions[i].date:sub(1,10) == param.version then
|
|
||||||
fullurl = multicraft.setting_get("modstore_download_url") ..
|
|
||||||
param.moddetails.versions[i].download_url
|
|
||||||
found = true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if not found then
|
|
||||||
return {
|
|
||||||
moddetails = param.moddetails,
|
|
||||||
successfull = false
|
|
||||||
}
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if multicraft.download_file(fullurl,param.filename) then
|
|
||||||
return {
|
|
||||||
texturename = param.texturename,
|
|
||||||
moddetails = param.moddetails,
|
|
||||||
filename = param.filename,
|
|
||||||
successfull = true
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return {
|
|
||||||
moddetails = param.moddetails,
|
|
||||||
successfull = false
|
|
||||||
}
|
|
||||||
end
|
|
||||||
end,
|
|
||||||
{
|
|
||||||
moddetails = moddetails,
|
|
||||||
version = fields["dd_version" .. modid],
|
|
||||||
filename = os.tempfolder() .. "_MODNAME_" .. moddetails.basename .. ".zip",
|
|
||||||
texturename = modstore.modlist_unsorted.data[i].texturename
|
|
||||||
},
|
|
||||||
function(result)
|
|
||||||
if result.successfull then
|
|
||||||
modmgr.installmod(result.filename,result.moddetails.basename)
|
|
||||||
os.remove(result.filename)
|
|
||||||
else
|
|
||||||
gamedata.errormessage = "Failed to download " .. result.moddetails.title
|
|
||||||
end
|
|
||||||
|
|
||||||
if gamedata.errormessage == nil then
|
|
||||||
multicraft.button_handler({btn_hidden_close_download=result})
|
|
||||||
else
|
|
||||||
multicraft.button_handler({btn_hidden_close_download={successfull=false}})
|
|
||||||
end
|
|
||||||
end
|
|
||||||
)
|
|
||||||
|
|
||||||
return {
|
|
||||||
current_tab = "modstore_downloading",
|
|
||||||
is_dialog = true,
|
|
||||||
show_buttons = false,
|
|
||||||
ignore_menu_quit = true
|
|
||||||
}
|
|
||||||
end
|
|
||||||
end
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
-- @function [parent=#modstore] update_modlist
|
|
||||||
function modstore.update_modlist()
|
|
||||||
modstore.modlist_unsorted = {}
|
|
||||||
modstore.modlist_unsorted.data = {}
|
|
||||||
modstore.modlist_unsorted.pagecount = 1
|
|
||||||
modstore.modlist_unsorted.page = 0
|
|
||||||
|
|
||||||
multicraft.handle_async(
|
|
||||||
function(param)
|
|
||||||
return multicraft.get_modstore_list()
|
|
||||||
end,
|
|
||||||
nil,
|
|
||||||
function(result)
|
|
||||||
if result ~= nil then
|
|
||||||
modstore.modlist_unsorted = {}
|
|
||||||
modstore.modlist_unsorted.data = result
|
|
||||||
|
|
||||||
if modstore.modlist_unsorted.data ~= nil then
|
|
||||||
modstore.modlist_unsorted.pagecount =
|
|
||||||
math.ceil((#modstore.modlist_unsorted.data / modstore.modsperpage))
|
|
||||||
else
|
|
||||||
modstore.modlist_unsorted.data = {}
|
|
||||||
modstore.modlist_unsorted.pagecount = 1
|
|
||||||
end
|
|
||||||
modstore.modlist_unsorted.page = 0
|
|
||||||
modstore.fetchdetails()
|
|
||||||
multicraft.event_handler("Refresh")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
)
|
|
||||||
end
|
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
-- @function [parent=#modstore] fetchdetails
|
|
||||||
function modstore.fetchdetails()
|
|
||||||
|
|
||||||
for i=1,#modstore.modlist_unsorted.data,1 do
|
|
||||||
multicraft.handle_async(
|
|
||||||
function(param)
|
|
||||||
param.details = multicraft.get_modstore_details(tostring(param.modid))
|
|
||||||
return param
|
|
||||||
end,
|
|
||||||
{
|
|
||||||
modid=modstore.modlist_unsorted.data[i].id,
|
|
||||||
listindex=i
|
|
||||||
},
|
|
||||||
function(result)
|
|
||||||
if result ~= nil and
|
|
||||||
modstore.modlist_unsorted ~= nil
|
|
||||||
and modstore.modlist_unsorted.data ~= nil and
|
|
||||||
modstore.modlist_unsorted.data[result.listindex] ~= nil and
|
|
||||||
modstore.modlist_unsorted.data[result.listindex].id ~= nil then
|
|
||||||
|
|
||||||
modstore.modlist_unsorted.data[result.listindex].details = result.details
|
|
||||||
multicraft.event_handler("Refresh")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
-- @function [parent=#modstore] getscreenshot
|
|
||||||
function modstore.getscreenshot(ypos,listentry)
|
|
||||||
|
|
||||||
if listentry.details ~= nil and
|
|
||||||
(listentry.details.screenshot_url == nil or
|
|
||||||
listentry.details.screenshot_url == "") then
|
|
||||||
|
|
||||||
if listentry.texturename == nil then
|
|
||||||
listentry.texturename = modstore.basetexturedir .. "no_screenshot.png"
|
|
||||||
end
|
|
||||||
|
|
||||||
return "image[0,".. ypos .. ";3,2;" ..
|
|
||||||
multicraft.formspec_escape(listentry.texturename) .. "]"
|
|
||||||
end
|
|
||||||
|
|
||||||
if listentry.details ~= nil and
|
|
||||||
listentry.texturename == nil then
|
|
||||||
--make sure we don't download multiple times
|
|
||||||
listentry.texturename = "in progress"
|
|
||||||
|
|
||||||
--prepare url and filename
|
|
||||||
local fullurl = multicraft.setting_get("modstore_download_url") ..
|
|
||||||
listentry.details.screenshot_url
|
|
||||||
local filename = os.tempfolder() .. "_MID_" .. listentry.id
|
|
||||||
|
|
||||||
--trigger download
|
|
||||||
multicraft.handle_async(
|
|
||||||
--first param is downloadfct
|
|
||||||
function(param)
|
|
||||||
param.successfull = multicraft.download_file(param.fullurl,param.filename)
|
|
||||||
return param
|
|
||||||
end,
|
|
||||||
--second parameter is data passed to async job
|
|
||||||
{
|
|
||||||
fullurl = fullurl,
|
|
||||||
filename = filename,
|
|
||||||
modid = listentry.id
|
|
||||||
},
|
|
||||||
--integrate result to raw list
|
|
||||||
function(result)
|
|
||||||
if result.successfull then
|
|
||||||
local found = false
|
|
||||||
for i=1,#modstore.modlist_unsorted.data,1 do
|
|
||||||
if modstore.modlist_unsorted.data[i].id == result.modid then
|
|
||||||
found = true
|
|
||||||
modstore.modlist_unsorted.data[i].texturename = result.filename
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if found then
|
|
||||||
multicraft.event_handler("Refresh")
|
|
||||||
else
|
|
||||||
multicraft.log("error","got screenshot but didn't find matching mod: " .. result.modid)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
)
|
|
||||||
end
|
|
||||||
|
|
||||||
if listentry.texturename ~= nil and
|
|
||||||
listentry.texturename ~= "in progress" then
|
|
||||||
return "image[0,".. ypos .. ";3,2;" ..
|
|
||||||
multicraft.formspec_escape(listentry.texturename) .. "]"
|
|
||||||
end
|
|
||||||
|
|
||||||
return ""
|
|
||||||
end
|
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
--@function [parent=#modstore] getshortmodinfo
|
|
||||||
function modstore.getshortmodinfo(ypos,listentry,details)
|
|
||||||
local retval = ""
|
|
||||||
|
|
||||||
retval = retval .. "box[0," .. ypos .. ";11.4,1.75;#FFFFFF]"
|
|
||||||
|
|
||||||
--screenshot
|
|
||||||
retval = retval .. modstore.getscreenshot(ypos,listentry)
|
|
||||||
|
|
||||||
--title + author
|
|
||||||
retval = retval .."label[2.75," .. ypos .. ";" ..
|
|
||||||
multicraft.formspec_escape(details.title) .. " (" .. details.author .. ")]"
|
|
||||||
|
|
||||||
--description
|
|
||||||
local descriptiony = ypos + 0.5
|
|
||||||
retval = retval .. "textarea[3," .. descriptiony .. ";6.5,1.55;;" ..
|
|
||||||
multicraft.formspec_escape(details.description) .. ";]"
|
|
||||||
|
|
||||||
--rating
|
|
||||||
local ratingy = ypos
|
|
||||||
retval = retval .."label[7," .. ratingy .. ";" ..
|
|
||||||
fgettext("Rating") .. ":]"
|
|
||||||
retval = retval .. "label[8.7," .. ratingy .. ";" .. details.rating .."]"
|
|
||||||
|
|
||||||
--versions (IMPORTANT has to be defined AFTER rating)
|
|
||||||
if details.versions ~= nil and
|
|
||||||
#details.versions > 1 then
|
|
||||||
local versiony = ypos + 0.05
|
|
||||||
retval = retval .. "dropdown[9.1," .. versiony .. ";2.48,0.25;dd_version" .. details.id .. ";"
|
|
||||||
local versions = ""
|
|
||||||
for i=1,#details.versions , 1 do
|
|
||||||
if versions ~= "" then
|
|
||||||
versions = versions .. ","
|
|
||||||
end
|
|
||||||
|
|
||||||
versions = versions .. details.versions[i].date:sub(1,10)
|
|
||||||
end
|
|
||||||
retval = retval .. versions .. ";1]"
|
|
||||||
end
|
|
||||||
|
|
||||||
if details.basename then
|
|
||||||
--install button
|
|
||||||
local buttony = ypos + 1.2
|
|
||||||
retval = retval .."button[9.1," .. buttony .. ";2.5,0.5;btn_install_mod_" .. details.id .. ";"
|
|
||||||
|
|
||||||
if modmgr.mod_exists(details.basename) then
|
|
||||||
retval = retval .. fgettext("re-Install") .."]"
|
|
||||||
else
|
|
||||||
retval = retval .. fgettext("Install") .."]"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
return retval
|
|
||||||
end
|
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
--@function [parent=#modstore] getmodlist
|
|
||||||
function modstore.getmodlist(list,yoffset)
|
|
||||||
|
|
||||||
modstore.current_list = list
|
|
||||||
|
|
||||||
if #list.data == 0 then
|
|
||||||
return ""
|
|
||||||
end
|
|
||||||
|
|
||||||
if yoffset == nil then
|
|
||||||
yoffset = 0
|
|
||||||
end
|
|
||||||
|
|
||||||
local scrollbar = ""
|
|
||||||
scrollbar = scrollbar .. "label[0.1,9.5;"
|
|
||||||
.. fgettext("Page $1 of $2", list.page+1, list.pagecount) .. "]"
|
|
||||||
scrollbar = scrollbar .. "box[11.6," .. (yoffset + 0.35) .. ";0.28,"
|
|
||||||
.. (8.6 - yoffset) .. ";#000000]"
|
|
||||||
local scrollbarpos = (yoffset + 0.75) +
|
|
||||||
((7.7 -yoffset)/(list.pagecount-1)) * list.page
|
|
||||||
scrollbar = scrollbar .. "box[11.6," ..scrollbarpos .. ";0.28,0.5;#32CD32]"
|
|
||||||
scrollbar = scrollbar .. "button[11.6," .. (yoffset + (0.3))
|
|
||||||
.. ";0.5,0.5;btn_modstore_page_up;^]"
|
|
||||||
scrollbar = scrollbar .. "button[11.6," .. 9.0
|
|
||||||
.. ";0.5,0.5;btn_modstore_page_down;v]"
|
|
||||||
|
|
||||||
local retval = ""
|
|
||||||
|
|
||||||
local endmod = (list.page * modstore.modsperpage) + modstore.modsperpage
|
|
||||||
|
|
||||||
if (endmod > #list.data) then
|
|
||||||
endmod = #list.data
|
|
||||||
end
|
|
||||||
|
|
||||||
for i=(list.page * modstore.modsperpage) +1, endmod, 1 do
|
|
||||||
--getmoddetails
|
|
||||||
local details = list.data[i].details
|
|
||||||
|
|
||||||
if details == nil then
|
|
||||||
details = {}
|
|
||||||
details.title = list.data[i].title
|
|
||||||
details.author = ""
|
|
||||||
details.rating = -1
|
|
||||||
details.description = ""
|
|
||||||
end
|
|
||||||
|
|
||||||
if details ~= nil then
|
|
||||||
local screenshot_ypos =
|
|
||||||
yoffset +(i-1 - (list.page * modstore.modsperpage))*1.9 +0.2
|
|
||||||
|
|
||||||
retval = retval .. modstore.getshortmodinfo(screenshot_ypos,
|
|
||||||
list.data[i],
|
|
||||||
details)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
return retval .. scrollbar
|
|
||||||
end
|
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
--@function [parent=#modstore] getsearchpage
|
|
||||||
function modstore.getsearchpage()
|
|
||||||
local retval = ""
|
|
||||||
local search = ""
|
|
||||||
|
|
||||||
if modstore.last_search ~= nil then
|
|
||||||
search = modstore.last_search
|
|
||||||
end
|
|
||||||
|
|
||||||
retval = retval ..
|
|
||||||
"button[9.5,0.2;2.5,0.5;btn_modstore_search;".. fgettext("Search") .. "]" ..
|
|
||||||
"field[0.5,0.5;9,0.5;te_modstore_search;;" .. search .. "]"
|
|
||||||
|
|
||||||
|
|
||||||
--show 4 mods only
|
|
||||||
modstore.modsperpage = 4
|
|
||||||
retval = retval ..
|
|
||||||
modstore.getmodlist(
|
|
||||||
modstore.currentlist,
|
|
||||||
1.75)
|
|
||||||
|
|
||||||
return retval;
|
|
||||||
end
|
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -3,7 +3,7 @@
|
||||||
--
|
--
|
||||||
--This program is free software; you can redistribute it and/or modify
|
--This program is free software; you can redistribute it and/or modify
|
||||||
--it under the terms of the GNU Lesser General Public License as published by
|
--it under the terms of the GNU Lesser General Public License as published by
|
||||||
--the Free Software Foundation; either version 3.0 of the License, or
|
--the Free Software Foundation; either version 2.1 of the License, or
|
||||||
--(at your option) any later version.
|
--(at your option) any later version.
|
||||||
--
|
--
|
||||||
--This program is distributed in the hope that it will be useful,
|
--This program is distributed in the hope that it will be useful,
|
||||||
|
@ -18,78 +18,53 @@
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
tab_credits = {
|
tab_credits = {
|
||||||
name = "credits",
|
name = "credits",
|
||||||
caption = fgettext("Credits"),
|
caption = fgettext("Credits"),
|
||||||
cbf_formspec = function (tabview, name, tabdata)
|
cbf_formspec = function (tabview, name, tabdata)
|
||||||
local logofile = defaulttexturedir .. "logo.png"
|
local logofile = defaulttexturedir .. "logo.png"
|
||||||
return "size[16,11]"..
|
return "label[0.5,3.2;Minetest " .. core.get_version() .. "]" ..
|
||||||
"bgcolor[#00000070;true]"..
|
"label[0.5,3.5;http://minetest.net]" ..
|
||||||
"box[-100,8.5;200,10;#999999]" ..
|
"image[0.5,1;" .. core.formspec_escape(logofile) .. "]" ..
|
||||||
"box[-100,-10;200,12;#999999]" ..
|
"textlist[3.5,-0.25;8.5,5.8;list_credits;" ..
|
||||||
|
"#FFFF00" .. fgettext("Core Developers") .."," ..
|
||||||
"image_button[12,9.55;4,0.8;"..multicraft.formspec_escape(mm_texture.basetexturedir).."menu_button.png;btn_cancel;".. fgettext("OK") .. ";true;true;"..multicraft.formspec_escape(mm_texture.basetexturedir).."menu_button_b.png]"..
|
"Perttu Ahola (celeron55) <celeron55@gmail.com>,"..
|
||||||
"label[3.5,9.75;http://MultiCraft.mobi]" ..
|
"Ryan Kwolek (kwolekr) <kwolekr@minetest.net>,"..
|
||||||
-- "image[0.25,9;2,2;"..multicraft.formspec_escape(logofile).."]"..
|
"PilzAdam <pilzadam@minetest.net>," ..
|
||||||
"textlist[0,2.0;15.8,6.25;list_credits;" ..
|
"Lisa Milne (darkrose) <lisa@ltmnet.com>,"..
|
||||||
"#FFFF00" .. fgettext("MultiCraft Developers") .."," ..
|
"Maciej Kasatkin (RealBadAngel) <mk@realbadangel.pl>,"..
|
||||||
" Maksim Gamarnik (MoNTE48) <MoNTE48@mail.ua>,"..
|
"sfan5 <sfan5@live.de>,"..
|
||||||
" 4aiman Konsorumaniakku <4aiman@inbox.ru>,"..
|
"kahrl <kahrl@gmx.net>,"..
|
||||||
" OttoLidenbrock,"..
|
"sapier,"..
|
||||||
" bektur87 <defactum@gmail.com>,"..
|
"ShadowNinja <shadowninja@minetest.net>,"..
|
||||||
" Yaroslav Kulichkovskiy,"..
|
"Nathanael Courant (Nore/Novatux) <nore@mesecons.net>,"..
|
||||||
"#FFFF00" .. fgettext("Core Developers") .."," ..
|
"BlockMen,"..
|
||||||
",Perttu Ahola (celeron55) <celeron55@gmail.com>,"..
|
"Craig Robbins (Zeno),"..
|
||||||
",Ryan Kwolek (kwolekr) <kwolekr@minetest.net>,"..
|
"Loic Blot (nerzhul/nrz),"..
|
||||||
",PilzAdam <pilzadam@minetest.net>," ..
|
"paramat,"..
|
||||||
",Maciej Kasatkin (RealBadAngel) <mk@realbadangel.pl>,"..
|
","..
|
||||||
",sfan5 <sfan5@live.de>,"..
|
"#FFFF00" .. fgettext("Active Contributors") .. "," ..
|
||||||
",kahrl <kahrl@gmx.net>,"..
|
"SmallJoker <mk939@ymail.com>," ..
|
||||||
",sapier,"..
|
"est31 <MTest31@outlook.com>," ..
|
||||||
",ShadowNinja <shadowninja@minetest.net>,"..
|
"gregorycu,"..
|
||||||
",Nathanael Courant (Nore/Novatux) <nore@mesecons.net>,"..
|
"Andrew Ward (rubenwardy) <rubenwardy@gmail.com>," ..
|
||||||
",BlockMen,"..
|
"TriBlade9 <triblade9@mail.com>,"..
|
||||||
",Craig Robbins (Zeno),"..
|
"Zefram <zefram@fysh.org>,"..
|
||||||
",Loic Blot (nerzhul/nrz),"..
|
"," ..
|
||||||
",paramat,"..
|
"#FFFF00" .. fgettext("Previous Contributors") .. "," ..
|
||||||
",est31 <MTest31@outlook.com>," ..
|
"Vanessa Ezekowitz (VanessaE) <vanessaezekowitz@gmail.com>,"..
|
||||||
",,"..
|
"Jurgen Doser (doserj) <jurgen.doser@gmail.com>,"..
|
||||||
"#FFFF00," .. fgettext("Active Contributors") .. "," ..
|
"Jeija <jeija@mesecons.net>,"..
|
||||||
",SmallJoker <mk939@ymail.com>," ..
|
"MirceaKitsune <mirceakitsune@gmail.com>,"..
|
||||||
",gregorycu," ..
|
"dannydark <the_skeleton_of_a_child@yahoo.co.uk>,"..
|
||||||
",Andrew Ward (rubenwardy) <rubenwardy@gmail.com>," ..
|
"0gb.us <0gb.us@0gb.us>,"..
|
||||||
",Aaron Suen <warr1024@gmail.com>," ..
|
"proller <proler@gmail.com>,"..
|
||||||
",TeTpaAka," ..
|
"Ilya Zhuravlev (xyz) <xyz@minetest.net>,"..
|
||||||
",," ..
|
"Guiseppe Bilotta (Oblomov) <guiseppe.bilotta@gmail.com>,"..
|
||||||
"#FFFF00," .. fgettext("Previous Core Developers") .."," ..
|
"Jonathan Neuschafer <j.neuschaefer@gmx.net>,"..
|
||||||
",Lisa Milne (darkrose) <lisa@ltmnet.com>," ..
|
"Nils Dagsson Moskopp (erlehmann) <nils@dieweltistgarnichtso.net>,"..
|
||||||
",proller <proler@gmail.com>," ..
|
"Constantin Wenger (SpeedProg) <constantin.wenger@googlemail.com>,"..
|
||||||
",Ilya Zhuravlev (xyz) <xyz@minetest.net>," ..
|
"matttpt <matttpt@gmail.com>,"..
|
||||||
",," ..
|
"JacobF <queatz@gmail.com>,"..
|
||||||
"#FFFF00," .. fgettext("Previous Contributors") .. "," ..
|
";0;true]"
|
||||||
",Vanessa Ezekowitz (VanessaE) <vanessaezekowitz@gmail.com>,"..
|
end
|
||||||
",Jurgen Doser (doserj) <jurgen.doser@gmail.com>,"..
|
}
|
||||||
",Jeija <jeija@mesecons.net>,"..
|
|
||||||
",MirceaKitsune <mirceakitsune@gmail.com>,"..
|
|
||||||
",dannydark <the_skeleton_of_a_child@yahoo.co.uk>,"..
|
|
||||||
",0gb.us <0gb.us@0gb.us>,"..
|
|
||||||
",Guiseppe Bilotta (Oblomov) <guiseppe.bilotta@gmail.com>,"..
|
|
||||||
",Jonathan Neuschafer <j.neuschaefer@gmx.net>,"..
|
|
||||||
",Nils Dagsson Moskopp (erlehmann) <nils@dieweltistgarnichtso.net>,"..
|
|
||||||
",Constantin Wenger (SpeedProg) <constantin.wenger@googlemail.com>,"..
|
|
||||||
",matttpt <matttpt@gmail.com>,"..
|
|
||||||
",JacobF <queatz@gmail.com>,"..
|
|
||||||
",TriBlade9 <triblade9@mail.com>,"..
|
|
||||||
",Zefram <zefram@fysh.org>,"..
|
|
||||||
" ...,"..
|
|
||||||
";0;true]"
|
|
||||||
end,
|
|
||||||
cbf_button_handler = function(tabview, fields, name, tabdata)
|
|
||||||
multicraft.set_clouds(false)
|
|
||||||
if fields["btn_cancel"] ~= nil then
|
|
||||||
tabview:hide()
|
|
||||||
tabview.parent:show()
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
}
|
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
--
|
--
|
||||||
--This program is free software; you can redistribute it and/or modify
|
--This program is free software; you can redistribute it and/or modify
|
||||||
--it under the terms of the GNU Lesser General Public License as published by
|
--it under the terms of the GNU Lesser General Public License as published by
|
||||||
--the Free Software Foundation; either version 3.0 of the License, or
|
--the Free Software Foundation; either version 2.1 of the License, or
|
||||||
--(at your option) any later version.
|
--(at your option) any later version.
|
||||||
--
|
--
|
||||||
--This program is distributed in the hope that it will be useful,
|
--This program is distributed in the hope that it will be useful,
|
||||||
|
@ -18,154 +18,152 @@
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
local function get_formspec(tabview, name, tabdata)
|
local function get_formspec(tabview, name, tabdata)
|
||||||
|
|
||||||
if modmgr.global_mods == nil then
|
if modmgr.global_mods == nil then
|
||||||
modmgr.refresh_globals()
|
modmgr.refresh_globals()
|
||||||
end
|
end
|
||||||
|
|
||||||
if tabdata.selected_mod == nil then
|
if tabdata.selected_mod == nil then
|
||||||
tabdata.selected_mod = 1
|
tabdata.selected_mod = 1
|
||||||
end
|
end
|
||||||
|
|
||||||
local retval =
|
local retval =
|
||||||
"label[0.05,-0.25;".. fgettext("Installed Mods:") .. "]" ..
|
"label[0.05,-0.25;".. fgettext("Installed Mods:") .. "]" ..
|
||||||
"textlist[0,0.25;5.1,4.35;modlist;" ..
|
"textlist[0,0.25;5.1,4.35;modlist;" ..
|
||||||
modmgr.render_modlist(modmgr.global_mods) ..
|
modmgr.render_modlist(modmgr.global_mods) ..
|
||||||
";" .. tabdata.selected_mod .. "]"
|
";" .. tabdata.selected_mod .. "]"
|
||||||
|
|
||||||
retval = retval ..
|
retval = retval ..
|
||||||
-- "label[0.8,4.2;" .. fgettext("Add mod:") .. "]" ..
|
-- "label[0.8,4.2;" .. fgettext("Add mod:") .. "]" ..
|
||||||
-- TODO Disabled due to upcoming release 0.4.8 and irrlicht messing up localization
|
-- TODO Disabled due to upcoming release 0.4.8 and irrlicht messing up localization
|
||||||
-- "button[0.75,4.85;1.8,0.5;btn_mod_mgr_install_local;".. fgettext("Local install") .. "]" ..
|
-- "button[0.75,4.85;1.8,0.5;btn_mod_mgr_install_local;".. fgettext("Local install") .. "]" ..
|
||||||
"image_button[0,4.85;5.25,0.8;"..multicraft.formspec_escape(mm_texture.basetexturedir).."menu_button.png;btn_modstore;".. fgettext("Online mod repository") .. ";true;true;"..multicraft.formspec_escape(mm_texture.basetexturedir).."menu_button_b.png]"
|
"button[0,4.85;5.25,0.5;btn_modstore;".. fgettext("Online mod repository") .. "]"
|
||||||
|
|
||||||
local selected_mod = nil
|
local selected_mod = nil
|
||||||
|
|
||||||
if filterlist.size(modmgr.global_mods) >= tabdata.selected_mod then
|
if filterlist.size(modmgr.global_mods) >= tabdata.selected_mod then
|
||||||
selected_mod = modmgr.global_mods:get_list()[tabdata.selected_mod]
|
selected_mod = modmgr.global_mods:get_list()[tabdata.selected_mod]
|
||||||
end
|
end
|
||||||
|
|
||||||
if selected_mod ~= nil then
|
if selected_mod ~= nil then
|
||||||
local modscreenshot = nil
|
local modscreenshot = nil
|
||||||
|
|
||||||
--check for screenshot beeing available
|
--check for screenshot beeing available
|
||||||
local screenshotfilename = selected_mod.path .. DIR_DELIM .. "screenshot.png"
|
local screenshotfilename = selected_mod.path .. DIR_DELIM .. "screenshot.png"
|
||||||
local error = nil
|
local error = nil
|
||||||
local screenshotfile,error = io.open(screenshotfilename,"r")
|
local screenshotfile,error = io.open(screenshotfilename,"r")
|
||||||
if error == nil then
|
if error == nil then
|
||||||
screenshotfile:close()
|
screenshotfile:close()
|
||||||
modscreenshot = screenshotfilename
|
modscreenshot = screenshotfilename
|
||||||
end
|
end
|
||||||
|
|
||||||
if modscreenshot == nil then
|
if modscreenshot == nil then
|
||||||
modscreenshot = modstore.basetexturedir .. "no_screenshot.png"
|
modscreenshot = defaulttexturedir .. "no_screenshot.png"
|
||||||
end
|
end
|
||||||
|
|
||||||
retval = retval
|
retval = retval
|
||||||
.. "image[5.5,0;3,2;" .. multicraft.formspec_escape(modscreenshot) .. "]"
|
.. "image[5.5,0;3,2;" .. core.formspec_escape(modscreenshot) .. "]"
|
||||||
.. "label[8.25,0.6;" .. selected_mod.name .. "]"
|
.. "label[8.25,0.6;" .. selected_mod.name .. "]"
|
||||||
|
|
||||||
local descriptionlines = nil
|
local descriptionlines = nil
|
||||||
error = nil
|
error = nil
|
||||||
local descriptionfilename = selected_mod.path .. "description.txt"
|
local descriptionfilename = selected_mod.path .. "description.txt"
|
||||||
local descriptionfile,error = io.open(descriptionfilename,"r")
|
local descriptionfile,error = io.open(descriptionfilename,"r")
|
||||||
if error == nil then
|
if error == nil then
|
||||||
local descriptiontext = descriptionfile:read("*all")
|
local descriptiontext = descriptionfile:read("*all")
|
||||||
|
|
||||||
descriptionlines = multicraft.splittext(descriptiontext,42)
|
descriptionlines = core.splittext(descriptiontext,42)
|
||||||
descriptionfile:close()
|
descriptionfile:close()
|
||||||
else
|
else
|
||||||
descriptionlines = {}
|
descriptionlines = {}
|
||||||
table.insert(descriptionlines,fgettext("No mod description available"))
|
table.insert(descriptionlines,fgettext("No mod description available"))
|
||||||
end
|
end
|
||||||
|
|
||||||
retval = retval ..
|
retval = retval ..
|
||||||
"label[5.5,1.7;".. fgettext("Mod information:") .. "]" ..
|
"label[5.5,1.7;".. fgettext("Mod information:") .. "]" ..
|
||||||
"textlist[5.5,2.2;6.2,2.4;description;"
|
"textlist[5.5,2.2;6.2,2.4;description;"
|
||||||
|
|
||||||
for i=1,#descriptionlines,1 do
|
for i=1,#descriptionlines,1 do
|
||||||
retval = retval .. multicraft.formspec_escape(descriptionlines[i]) .. ","
|
retval = retval .. core.formspec_escape(descriptionlines[i]) .. ","
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
if selected_mod.is_modpack then
|
if selected_mod.is_modpack then
|
||||||
retval = retval .. ";0]" ..
|
retval = retval .. ";0]" ..
|
||||||
"image_button[10,4.85;2,0.8;"..multicraft.formspec_escape(mm_texture.basetexturedir).."menu_button.png;btn_mod_mgr_rename_modpack;" ..
|
"button[10,4.85;2,0.5;btn_mod_mgr_rename_modpack;" ..
|
||||||
fgettext("Rename") .. ";true;true;"..multicraft.formspec_escape(mm_texture.basetexturedir).."menu_button_b.png]"
|
fgettext("Rename") .. "]"
|
||||||
retval = retval .. "image_button[5.5,4.85;4.5,0.8;"..multicraft.formspec_escape(mm_texture.basetexturedir).."menu_button.png;btn_mod_mgr_delete_mod;"
|
retval = retval .. "button[5.5,4.85;4.5,0.5;btn_mod_mgr_delete_mod;"
|
||||||
.. fgettext("Uninstall selected modpack") .. ";true;true;"..multicraft.formspec_escape(mm_texture.basetexturedir).."menu_button_b.png]"
|
.. fgettext("Uninstall selected modpack") .. "]"
|
||||||
else
|
else
|
||||||
--show dependencies
|
--show dependencies
|
||||||
|
|
||||||
retval = retval .. ",Depends:,"
|
retval = retval .. "," .. fgettext("Depends:") .. ","
|
||||||
|
|
||||||
local toadd = modmgr.get_dependencies(selected_mod.path)
|
local toadd = modmgr.get_dependencies(selected_mod.path)
|
||||||
|
|
||||||
retval = retval .. toadd .. ";0]"
|
retval = retval .. toadd .. ";0]"
|
||||||
|
|
||||||
retval = retval .. "image_button[5.5,4.85;4.5,0.8;"..multicraft.formspec_escape(mm_texture.basetexturedir).."menu_button.png;btn_mod_mgr_delete_mod;"
|
retval = retval .. "button[5.5,4.85;4.5,0.5;btn_mod_mgr_delete_mod;"
|
||||||
.. fgettext("Uninstall selected mod") .. ";true;true;"..multicraft.formspec_escape(mm_texture.basetexturedir).."menu_button_b.png]"
|
.. fgettext("Uninstall selected mod") .. "]"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return retval
|
return retval
|
||||||
end
|
end
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
local function handle_buttons(tabview, fields, tabname, tabdata)
|
local function handle_buttons(tabview, fields, tabname, tabdata)
|
||||||
multicraft.set_clouds(false)
|
if fields["modlist"] ~= nil then
|
||||||
|
local event = core.explode_textlist_event(fields["modlist"])
|
||||||
|
tabdata.selected_mod = event.index
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
if fields["modlist"] ~= nil then
|
if fields["btn_mod_mgr_install_local"] ~= nil then
|
||||||
local event = multicraft.explode_textlist_event(fields["modlist"])
|
core.show_file_open_dialog("mod_mgt_open_dlg",fgettext("Select Mod File:"))
|
||||||
tabdata.selected_mod = event.index
|
return true
|
||||||
return true
|
end
|
||||||
end
|
|
||||||
|
|
||||||
if fields["btn_mod_mgr_install_local"] ~= nil then
|
if fields["btn_modstore"] ~= nil then
|
||||||
multicraft.show_file_open_dialog("mod_mgt_open_dlg",fgettext("Select Mod File:"))
|
local modstore_ui = ui.find_by_name("modstore")
|
||||||
return true
|
if modstore_ui ~= nil then
|
||||||
end
|
tabview:hide()
|
||||||
|
modstore.update_modlist()
|
||||||
|
modstore_ui:show()
|
||||||
|
else
|
||||||
|
print("modstore ui element not found")
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
if fields["btn_modstore"] ~= nil then
|
if fields["btn_mod_mgr_rename_modpack"] ~= nil then
|
||||||
local modstore_ui = ui.find_by_name("modstore")
|
local dlg_renamemp = create_rename_modpack_dlg(tabdata.selected_mod)
|
||||||
if modstore_ui ~= nil then
|
dlg_renamemp:set_parent(tabview)
|
||||||
tabview:hide()
|
tabview:hide()
|
||||||
modstore.update_modlist()
|
dlg_renamemp:show()
|
||||||
modstore_ui:show()
|
return true
|
||||||
else
|
end
|
||||||
print("modstore ui element not found")
|
|
||||||
end
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
if fields["btn_mod_mgr_rename_modpack"] ~= nil then
|
if fields["btn_mod_mgr_delete_mod"] ~= nil then
|
||||||
local dlg_renamemp = create_rename_modpack_dlg(tabdata.selected_mod)
|
local dlg_delmod = create_delete_mod_dlg(tabdata.selected_mod)
|
||||||
dlg_renamemp:set_parent(tabview)
|
dlg_delmod:set_parent(tabview)
|
||||||
tabview:hide()
|
tabview:hide()
|
||||||
dlg_renamemp:show()
|
dlg_delmod:show()
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
if fields["btn_mod_mgr_delete_mod"] ~= nil then
|
if fields["mod_mgt_open_dlg_accepted"] ~= nil and
|
||||||
local dlg_delmod = create_delete_mod_dlg(tabdata.selected_mod)
|
fields["mod_mgt_open_dlg_accepted"] ~= "" then
|
||||||
dlg_delmod:set_parent(tabview)
|
modmgr.installmod(fields["mod_mgt_open_dlg_accepted"],nil)
|
||||||
tabview:hide()
|
return true
|
||||||
dlg_delmod:show()
|
end
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
if fields["mod_mgt_open_dlg_accepted"] ~= nil and
|
return false
|
||||||
fields["mod_mgt_open_dlg_accepted"] ~= "" then
|
|
||||||
modmgr.installmod(fields["mod_mgt_open_dlg_accepted"],nil)
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
return false
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
tab_mods = {
|
tab_mods = {
|
||||||
name = "mods",
|
name = "mods",
|
||||||
caption = fgettext("Mods"),
|
caption = fgettext("Mods"),
|
||||||
cbf_formspec = get_formspec,
|
cbf_formspec = get_formspec,
|
||||||
cbf_button_handler = handle_buttons,
|
cbf_button_handler = handle_buttons,
|
||||||
on_change = gamemgr.update_gamelist
|
on_change = gamemgr.update_gamelist
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
--
|
--
|
||||||
--This program is free software; you can redistribute it and/or modify
|
--This program is free software; you can redistribute it and/or modify
|
||||||
--it under the terms of the GNU Lesser General Public License as published by
|
--it under the terms of the GNU Lesser General Public License as published by
|
||||||
--the Free Software Foundation; either version 3.0 of the License, or
|
--the Free Software Foundation; either version 2.1 of the License, or
|
||||||
--(at your option) any later version.
|
--(at your option) any later version.
|
||||||
--
|
--
|
||||||
--This program is distributed in the hope that it will be useful,
|
--This program is distributed in the hope that it will be useful,
|
||||||
|
@ -17,311 +17,245 @@
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
local function get_formspec(tabview, name, tabdata)
|
local function get_formspec(tabview, name, tabdata)
|
||||||
local retval =
|
local render_details = core.is_yes(core.setting_getbool("public_serverlist"))
|
||||||
"size[16,11]"..
|
|
||||||
"box[-100,8.5;200,10;#999999]" ..
|
local retval =
|
||||||
"box[-100,-10;200,12;#999999]" ..
|
"label[7.75,-0.15;" .. fgettext("Address / Port :") .. "]" ..
|
||||||
"bgcolor[#00000070;true]"..
|
"label[7.75,1.05;" .. fgettext("Name / Password :") .. "]" ..
|
||||||
|
"field[8,0.75;3.4,0.5;te_address;;" ..
|
||||||
|
core.formspec_escape(core.setting_get("address")) .. "]" ..
|
||||||
|
"field[11.25,0.75;1.3,0.5;te_port;;" ..
|
||||||
|
core.formspec_escape(core.setting_get("remote_port")) .. "]" ..
|
||||||
|
"checkbox[0,4.85;cb_public_serverlist;" .. fgettext("Public Serverlist") .. ";" ..
|
||||||
|
dump(core.setting_getbool("public_serverlist")) .. "]"
|
||||||
|
|
||||||
"image_button[12,9.55;4,0.8;"..multicraft.formspec_escape(mm_texture.basetexturedir).."menu_button.png;cancel;".. fgettext("Cancel") .. ";true;true;"..multicraft.formspec_escape(mm_texture.basetexturedir).."menu_button_b.png]"..
|
if not core.setting_getbool("public_serverlist") then
|
||||||
--"label[0,1.25;" .. fgettext("Address/Port") .. "]" ..
|
retval = retval ..
|
||||||
"field[1000.25,5.25;5.5,0.5;te_address;;" ..
|
"button[8,4.9;2,0.5;btn_delete_favorite;" .. fgettext("Delete") .. "]"
|
||||||
multicraft.formspec_escape(multicraft.setting_get("address")) .. "]" ..
|
end
|
||||||
"field[1005.75,5.25;2.25,0.5;te_port;;" ..
|
|
||||||
multicraft.formspec_escape(multicraft.setting_get("remote_port")) .. "]" ..
|
|
||||||
"checkbox[1000,3.6;cb_public_serverlist;" .. fgettext("Public Serverlist") .. ";" ..
|
|
||||||
dump(multicraft.setting_getbool("public_serverlist")) .. "]"..
|
|
||||||
|
|
||||||
"label[7,1.5;" .. fgettext("Select Server:") .. "]" ..
|
retval = retval ..
|
||||||
"label[0,0.25;Address: "..multicraft.formspec_escape(multicraft.setting_get("address")) .. "]" ..
|
"button[10,4.9;2,0.5;btn_mp_connect;" .. fgettext("Connect") .. "]" ..
|
||||||
"label[0,0.75;Port: "..multicraft.formspec_escape(multicraft.setting_get("remote_port")) .. "]"
|
"field[8,1.95;2.95,0.5;te_name;;" ..
|
||||||
|
core.formspec_escape(core.setting_get("name")) .. "]" ..
|
||||||
|
"pwdfield[10.78,1.95;1.77,0.5;te_pwd;]" ..
|
||||||
|
"box[7.73,2.35;4.3,2.28;#999999]" ..
|
||||||
|
"textarea[8.1,2.4;4.26,2.6;;"
|
||||||
|
|
||||||
|
if tabdata.fav_selected ~= nil and
|
||||||
|
menudata.favorites[tabdata.fav_selected] ~= nil and
|
||||||
|
menudata.favorites[tabdata.fav_selected].description ~= nil then
|
||||||
|
retval = retval ..
|
||||||
|
core.formspec_escape(menudata.favorites[tabdata.fav_selected].description,true)
|
||||||
|
end
|
||||||
|
|
||||||
|
retval = retval ..
|
||||||
|
";]"
|
||||||
|
|
||||||
--if not multicraft.setting_getbool("public_serverlist") then
|
--favourites
|
||||||
if (multicraft.get_table_index("favourites") or 10000) <= #multicraft.get_favorites("local") then
|
if render_details then
|
||||||
retval = retval ..
|
retval = retval .. "tablecolumns[" ..
|
||||||
"image_button[4,9.55;4,0.8;"..multicraft.formspec_escape(mm_texture.basetexturedir).."menu_button.png;btn_delete_favorite;" .. fgettext("Delete") .. ";true;true;"..multicraft.formspec_escape(mm_texture.basetexturedir).."menu_button_b.png]"
|
"color,span=3;" ..
|
||||||
else
|
"text,align=right;" .. -- clients
|
||||||
retval = retval ..
|
"text,align=center,padding=0.25;" .. -- "/"
|
||||||
"image_button[4,9.55;4,0.8;"..multicraft.formspec_escape(mm_texture.basetexturedir).."menu_button.png;add_server;" .. fgettext("Add") .. ";true;true;"..multicraft.formspec_escape(mm_texture.basetexturedir).."menu_button_b.png]"
|
"text,align=right,padding=0.25;" .. -- clients_max
|
||||||
end
|
image_column(fgettext("Creative mode"), "creative") .. ",padding=1;" ..
|
||||||
|
image_column(fgettext("Damage enabled"), "damage") .. ",padding=0.25;" ..
|
||||||
|
image_column(fgettext("PvP enabled"), "pvp") .. ",padding=0.25;" ..
|
||||||
|
"color,span=1;" ..
|
||||||
|
"text,padding=1]" -- name
|
||||||
|
else
|
||||||
|
retval = retval .. "tablecolumns[text]"
|
||||||
|
end
|
||||||
|
retval = retval ..
|
||||||
|
"table[-0.15,-0.1;7.75,5;favourites;"
|
||||||
|
|
||||||
retval = retval ..
|
if #menudata.favorites > 0 then
|
||||||
"image_button[8,9.55;3.95,0.8;"..multicraft.formspec_escape(mm_texture.basetexturedir).."menu_button.png;btn_mp_connect;" .. fgettext("Connect") .. ";true;true;"..multicraft.formspec_escape(mm_texture.basetexturedir).."menu_button_b.png]"..
|
retval = retval .. render_favorite(menudata.favorites[1],render_details)
|
||||||
"image_button[3.2,9.55;0.8,0.8;"..multicraft.formspec_escape(mm_texture.basetexturedir).."server_flags_favourite.png;btn_mp_favour;;true;true;"..multicraft.formspec_escape(mm_texture.basetexturedir).."menu_button_b.png]"..
|
|
||||||
|
|
||||||
"label[8,8;" .. fgettext("Name") .. ":]" ..
|
for i=2,#menudata.favorites,1 do
|
||||||
"field[8.3,9;3.95,0.8;te_name;;" ..
|
retval = retval .. "," .. render_favorite(menudata.favorites[i],render_details)
|
||||||
multicraft.formspec_escape(multicraft.setting_get("name")) .. "]" ..
|
end
|
||||||
"label[12,8;" .. fgettext("Password") .. ":]" ..
|
end
|
||||||
"pwdfield[12.3,9;4,0.8;te_pwd;]" ..
|
|
||||||
"textarea[9.3,0;2.5,3.0;;"
|
|
||||||
|
|
||||||
|
if tabdata.fav_selected ~= nil then
|
||||||
|
retval = retval .. ";" .. tabdata.fav_selected .. "]"
|
||||||
|
else
|
||||||
|
retval = retval .. ";0]"
|
||||||
|
end
|
||||||
|
|
||||||
if tabdata.fav_selected ~= nil and
|
return retval
|
||||||
menudata.favorites[tabdata.fav_selected] ~= nil and
|
|
||||||
menudata.favorites[tabdata.fav_selected].description ~= nil then
|
|
||||||
retval = retval ..
|
|
||||||
multicraft.formspec_escape(menudata.favorites[tabdata.fav_selected].description,true)
|
|
||||||
end
|
|
||||||
|
|
||||||
retval = retval ..
|
|
||||||
";]"
|
|
||||||
|
|
||||||
--favourites
|
|
||||||
local function image_column(tooltip, flagname)
|
|
||||||
local ret = "image," ..
|
|
||||||
"tooltip=" .. multicraft.formspec_escape(tooltip) .. ","
|
|
||||||
if flagname ~= 'favourite' then
|
|
||||||
ret = ret .. "0=" .. multicraft.formspec_escape(defaulttexturedir .. "blank.png") .. ","
|
|
||||||
else
|
|
||||||
ret = ret .. "0=" .. multicraft.formspec_escape(defaulttexturedir .. "server_flags_" .. flagname .. "_off.png") .. ","
|
|
||||||
end
|
|
||||||
ret = ret .. "1=" .. multicraft.formspec_escape(defaulttexturedir .. "server_flags_" .. flagname .. ".png")
|
|
||||||
return ret
|
|
||||||
end
|
|
||||||
retval = retval .. "tablecolumns[" ..
|
|
||||||
"color,span=3;" ..
|
|
||||||
"text,align=right;" .. -- clients
|
|
||||||
"text,align=center,padding=0.25;" .. -- "/"
|
|
||||||
"text,align=right,padding=0.25;" .. -- clients_max
|
|
||||||
image_column("Creative mode", "creative") .. ",padding=1;" ..
|
|
||||||
image_column("Damage enabled", "damage") .. ",padding=0.25;" ..
|
|
||||||
image_column("PvP enabled", "pvp") .. ",padding=0.25;" ..
|
|
||||||
"text,padding=1]"--..
|
|
||||||
--image_column("Favourite", "favourite") .. ",align=right]"
|
|
||||||
|
|
||||||
retval = retval ..
|
|
||||||
"tableoptions[background=#00000000;border=false]"..
|
|
||||||
"table[0,2.2;16,6.25;favourites;"
|
|
||||||
|
|
||||||
if #menudata.favorites == 0 then
|
|
||||||
asyncOnlineFavourites()
|
|
||||||
end
|
|
||||||
|
|
||||||
if #menudata.favorites > 0 then
|
|
||||||
retval = retval .. render_favorite(menudata.favorites[1])
|
|
||||||
|
|
||||||
for i=2,#menudata.favorites,1 do
|
|
||||||
retval = retval .. "," .. render_favorite(menudata.favorites[i])
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if tabdata.fav_selected ~= nil then
|
|
||||||
retval = retval .. ";" .. tabdata.fav_selected .. "]"
|
|
||||||
else
|
|
||||||
retval = retval .. ";0]"
|
|
||||||
end
|
|
||||||
--print(retval)
|
|
||||||
return retval
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
local function main_button_handler(tabview, fields, name, tabdata)
|
local function main_button_handler(tabview, fields, name, tabdata)
|
||||||
multicraft.set_clouds(false)
|
if fields["te_name"] ~= nil then
|
||||||
|
gamedata.playername = fields["te_name"]
|
||||||
|
core.setting_set("name", fields["te_name"])
|
||||||
|
end
|
||||||
|
|
||||||
if not tabdata then tabdata = {} end
|
if fields["favourites"] ~= nil then
|
||||||
|
local event = core.explode_table_event(fields["favourites"])
|
||||||
|
if event.type == "DCL" then
|
||||||
|
if event.row <= #menudata.favorites then
|
||||||
|
if not is_server_protocol_compat_or_error(menudata.favorites[event.row].proto_min,
|
||||||
|
menudata.favorites[event.row].proto_max) then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
gamedata.address = menudata.favorites[event.row].address
|
||||||
|
gamedata.port = menudata.favorites[event.row].port
|
||||||
|
gamedata.playername = fields["te_name"]
|
||||||
|
if fields["te_pwd"] ~= nil then
|
||||||
|
gamedata.password = fields["te_pwd"]
|
||||||
|
end
|
||||||
|
gamedata.selected_world = 0
|
||||||
|
|
||||||
if fields["add_server"] ~= nil then
|
if menudata.favorites ~= nil then
|
||||||
local add_server_dlg = create_add_server_dlg(true)
|
gamedata.servername = menudata.favorites[event.row].name
|
||||||
add_server_dlg:set_parent(tabview)
|
gamedata.serverdescription = menudata.favorites[event.row].description
|
||||||
add_server_dlg:show()
|
end
|
||||||
tabview:hide()
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
if fields["te_name"] ~= nil then
|
if gamedata.address ~= nil and
|
||||||
gamedata.playername = fields["te_name"]
|
gamedata.port ~= nil then
|
||||||
multicraft.setting_set("name", fields["te_name"])
|
core.setting_set("address",gamedata.address)
|
||||||
end
|
core.setting_set("remote_port",gamedata.port)
|
||||||
|
core.start()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
if fields["favourites"] ~= nil then
|
if event.type == "CHG" then
|
||||||
local event = multicraft.explode_table_event(fields["favourites"])
|
if event.row <= #menudata.favorites then
|
||||||
if event.type == "DCL" then
|
local address = menudata.favorites[event.row].address
|
||||||
if event.row <= #menudata.favorites then
|
local port = menudata.favorites[event.row].port
|
||||||
gamedata.address = menudata.favorites[event.row].address
|
|
||||||
gamedata.port = menudata.favorites[event.row].port
|
|
||||||
gamedata.playername = fields["te_name"]
|
|
||||||
if fields["te_pwd"] ~= nil then
|
|
||||||
gamedata.password = fields["te_pwd"]
|
|
||||||
end
|
|
||||||
gamedata.selected_world = 0
|
|
||||||
|
|
||||||
if menudata.favorites ~= nil then
|
if address ~= nil and
|
||||||
gamedata.servername = menudata.favorites[event.row].name
|
port ~= nil then
|
||||||
gamedata.serverdescription = menudata.favorites[event.row].description
|
core.setting_set("address",address)
|
||||||
end
|
core.setting_set("remote_port",port)
|
||||||
|
end
|
||||||
|
|
||||||
if gamedata.address ~= nil and
|
tabdata.fav_selected = event.row
|
||||||
gamedata.port ~= nil then
|
end
|
||||||
multicraft.setting_set("address",gamedata.address)
|
|
||||||
multicraft.setting_set("remote_port",gamedata.port)
|
return true
|
||||||
multicraft.start()
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
if event.type == "CHG" then
|
if fields["key_up"] ~= nil or
|
||||||
if event.row <= #menudata.favorites then
|
fields["key_down"] ~= nil then
|
||||||
local address = menudata.favorites[event.row].address
|
|
||||||
local port = menudata.favorites[event.row].port
|
|
||||||
|
|
||||||
if address ~= nil and
|
local fav_idx = core.get_table_index("favourites")
|
||||||
port ~= nil then
|
|
||||||
multicraft.setting_set("address",address)
|
|
||||||
multicraft.setting_set("remote_port",port)
|
|
||||||
end
|
|
||||||
|
|
||||||
tabdata.fav_selected = event.row
|
if fav_idx ~= nil then
|
||||||
end
|
if fields["key_up"] ~= nil and fav_idx > 1 then
|
||||||
return true
|
fav_idx = fav_idx -1
|
||||||
end
|
else if fields["key_down"] and fav_idx < #menudata.favorites then
|
||||||
end
|
fav_idx = fav_idx +1
|
||||||
|
end end
|
||||||
|
else
|
||||||
|
fav_idx = 1
|
||||||
|
end
|
||||||
|
|
||||||
|
if menudata.favorites == nil or
|
||||||
|
menudata.favorites[fav_idx] == nil then
|
||||||
|
tabdata.fav_selected = 0
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
local address = menudata.favorites[fav_idx].address
|
||||||
|
local port = menudata.favorites[fav_idx].port
|
||||||
|
|
||||||
if fields["key_up"] ~= nil or
|
if address ~= nil and
|
||||||
fields["key_down"] ~= nil then
|
port ~= nil then
|
||||||
|
core.setting_set("address",address)
|
||||||
|
core.setting_set("remote_port",port)
|
||||||
|
end
|
||||||
|
|
||||||
local fav_idx = multicraft.get_table_index("favourites")
|
tabdata.fav_selected = fav_idx
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
if fav_idx ~= nil then
|
if fields["cb_public_serverlist"] ~= nil then
|
||||||
if fields["key_up"] ~= nil and fav_idx > 1 then
|
core.setting_set("public_serverlist", fields["cb_public_serverlist"])
|
||||||
fav_idx = fav_idx -1
|
|
||||||
else if fields["key_down"] and fav_idx < #menudata.favorites then
|
|
||||||
fav_idx = fav_idx +1
|
|
||||||
end end
|
|
||||||
else
|
|
||||||
fav_idx = 1
|
|
||||||
end
|
|
||||||
|
|
||||||
if menudata.favorites == nil or
|
if core.setting_getbool("public_serverlist") then
|
||||||
menudata.favorites[fav_idx] == nil then
|
asyncOnlineFavourites()
|
||||||
tabdata.fav_selected = 0
|
else
|
||||||
return true
|
menudata.favorites = core.get_favorites("local")
|
||||||
end
|
end
|
||||||
|
tabdata.fav_selected = nil
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
local address = menudata.favorites[fav_idx].address
|
if fields["btn_delete_favorite"] ~= nil then
|
||||||
local port = menudata.favorites[fav_idx].port
|
local current_favourite = core.get_table_index("favourites")
|
||||||
|
if current_favourite == nil then return end
|
||||||
|
core.delete_favorite(current_favourite)
|
||||||
|
menudata.favorites = order_favorite_list(core.get_favorites())
|
||||||
|
tabdata.fav_selected = nil
|
||||||
|
|
||||||
if address ~= nil and
|
core.setting_set("address","")
|
||||||
port ~= nil then
|
core.setting_set("remote_port","30000")
|
||||||
multicraft.setting_set("address",address)
|
|
||||||
multicraft.setting_set("remote_port",port)
|
|
||||||
end
|
|
||||||
|
|
||||||
tabdata.fav_selected = fav_idx
|
return true
|
||||||
return true
|
end
|
||||||
end
|
|
||||||
|
|
||||||
if fields["cb_public_serverlist"] ~= nil then
|
if (fields["btn_mp_connect"] ~= nil or
|
||||||
multicraft.setting_set("public_serverlist", fields["cb_public_serverlist"])
|
fields["key_enter"] ~= nil) and fields["te_address"] ~= nil and
|
||||||
asyncOnlineFavourites()
|
fields["te_port"] ~= nil then
|
||||||
tabdata.fav_selected = nil
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
if fields["btn_mp_favour"] ~= nil then
|
gamedata.playername = fields["te_name"]
|
||||||
local current_favourite = multicraft.get_table_index("favourites")
|
gamedata.password = fields["te_pwd"]
|
||||||
local path = multicraft.get_modpath('')..'/../client/'..multicraft.formspec_escape(multicraft.setting_get("serverlist_file"))
|
gamedata.address = fields["te_address"]
|
||||||
local favourites
|
gamedata.port = fields["te_port"]
|
||||||
if path then
|
|
||||||
local input,err,errcode = io.open(path, "r")
|
|
||||||
if input then
|
|
||||||
favourites = input:read("*all")
|
|
||||||
io.close(input)
|
|
||||||
--else
|
|
||||||
--gamedata.errormessage = err..' ('..errcode..')'
|
|
||||||
end
|
|
||||||
if favourites then
|
|
||||||
favourites = multicraft.parse_json(favourites)
|
|
||||||
else
|
|
||||||
favourites = {["list"]={},}
|
|
||||||
end
|
|
||||||
table.insert(favourites.list,{
|
|
||||||
["address"] = fields["te_address"],
|
|
||||||
["description"] = "Saved at ".. os.date(),
|
|
||||||
["name"] = fields["te_address"],
|
|
||||||
["playername"] = fields["te_name"],
|
|
||||||
["playerpassword"] = fields["te_pwd"],
|
|
||||||
["port"] = fields["te_port"],
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
favourites = multicraft.write_json(favourites)
|
local fav_idx = core.get_table_index("favourites")
|
||||||
|
|
||||||
local output,err,errcode = io.open(path, "w")
|
if fav_idx ~= nil and fav_idx <= #menudata.favorites and
|
||||||
if output then
|
menudata.favorites[fav_idx].address == fields["te_address"] and
|
||||||
output:write(favourites or '')
|
menudata.favorites[fav_idx].port == fields["te_port"] then
|
||||||
io.close(output)
|
|
||||||
else
|
|
||||||
--gamedata.errormessage = fgettext("Can't write to serverlist_file! ("..path..')')
|
|
||||||
gamedata.errormessage = err..' ('..errcode..')'
|
|
||||||
end
|
|
||||||
end
|
|
||||||
asyncOnlineFavourites()
|
|
||||||
end
|
|
||||||
|
|
||||||
if fields["btn_delete_favorite"] ~= nil then
|
gamedata.servername = menudata.favorites[fav_idx].name
|
||||||
local current_favourite = multicraft.get_table_index("favourites")
|
gamedata.serverdescription = menudata.favorites[fav_idx].description
|
||||||
if current_favourite == nil then return end
|
|
||||||
if current_favourite > #multicraft.get_favorites('offline') then return end
|
|
||||||
multicraft.delete_favorite(current_favourite)
|
|
||||||
tabdata.fav_selected = nil
|
|
||||||
asyncOnlineFavourites()
|
|
||||||
|
|
||||||
|
if not is_server_protocol_compat_or_error(menudata.favorites[fav_idx].proto_min,
|
||||||
|
menudata.favorites[fav_idx].proto_max)then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
else
|
||||||
|
gamedata.servername = ""
|
||||||
|
gamedata.serverdescription = ""
|
||||||
|
end
|
||||||
|
|
||||||
multicraft.setting_set("address","")
|
gamedata.selected_world = 0
|
||||||
multicraft.setting_set("remote_port","30000")
|
|
||||||
|
|
||||||
return true
|
core.setting_set("address", fields["te_address"])
|
||||||
end
|
core.setting_set("remote_port",fields["te_port"])
|
||||||
|
|
||||||
if fields["btn_mp_connect"] ~= nil or
|
core.start()
|
||||||
fields["key_enter"] ~= nil then
|
return true
|
||||||
|
end
|
||||||
gamedata.playername = fields["te_name"]
|
return false
|
||||||
gamedata.password = fields["te_pwd"]
|
|
||||||
gamedata.address = fields["te_address"]
|
|
||||||
gamedata.port = fields["te_port"]
|
|
||||||
|
|
||||||
local fav_idx = multicraft.get_table_index("favourites")
|
|
||||||
if fav_idx ~= nil and fav_idx <= #menudata.favorites and
|
|
||||||
menudata.favorites[fav_idx].address == fields["te_address"] and
|
|
||||||
menudata.favorites[fav_idx].port == fields["te_port"] then
|
|
||||||
else
|
|
||||||
gamedata.servername = ""
|
|
||||||
gamedata.serverdescription = ""
|
|
||||||
end
|
|
||||||
|
|
||||||
gamedata.selected_world = 0
|
|
||||||
|
|
||||||
multicraft.setting_set("address", fields["te_address"])
|
|
||||||
multicraft.setting_set("remote_port",fields["te_port"])
|
|
||||||
|
|
||||||
multicraft.start()
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
if fields["cancel"] ~= nil then
|
|
||||||
tabview:hide()
|
|
||||||
tabview.parent:show()
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
return false
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local function on_change(type,old_tab,new_tab)
|
local function on_change(type,old_tab,new_tab)
|
||||||
if type == "LEAVE" then
|
if type == "LEAVE" then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
if core.setting_getbool("public_serverlist") then
|
||||||
|
asyncOnlineFavourites()
|
||||||
|
else
|
||||||
|
menudata.favorites = core.get_favorites("local")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
tab_multiplayer = {
|
tab_multiplayer = {
|
||||||
name = "multiplayer",
|
name = "multiplayer",
|
||||||
caption = fgettext("Client"),
|
caption = fgettext("Client"),
|
||||||
cbf_formspec = get_formspec,
|
cbf_formspec = get_formspec,
|
||||||
cbf_button_handler = main_button_handler,
|
cbf_button_handler = main_button_handler,
|
||||||
-- on_change = on_change
|
on_change = on_change
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
--
|
--
|
||||||
--This program is free software; you can redistribute it and/or modify
|
--This program is free software; you can redistribute it and/or modify
|
||||||
--it under the terms of the GNU Lesser General Public License as published by
|
--it under the terms of the GNU Lesser General Public License as published by
|
||||||
--the Free Software Foundation; either version 3.0 of the License, or
|
--the Free Software Foundation; either version 2.1 of the License, or
|
||||||
--(at your option) any later version.
|
--(at your option) any later version.
|
||||||
--
|
--
|
||||||
--This program is distributed in the hope that it will be useful,
|
--This program is distributed in the hope that it will be useful,
|
||||||
|
@ -17,210 +17,206 @@
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
local function get_formspec(tabview, name, tabdata)
|
local function get_formspec(tabview, name, tabdata)
|
||||||
|
|
||||||
|
local index = menudata.worldlist:get_current_index(
|
||||||
|
tonumber(core.setting_get("mainmenu_last_selected_world"))
|
||||||
|
)
|
||||||
|
|
||||||
local index = menudata.worldlist:get_current_index(
|
local retval =
|
||||||
tonumber(multicraft.setting_get("mainmenu_last_selected_world"))
|
"button[4,4.15;2.6,0.5;world_delete;" .. fgettext("Delete") .. "]" ..
|
||||||
)
|
"button[6.5,4.15;2.8,0.5;world_create;" .. fgettext("New") .. "]" ..
|
||||||
|
"button[9.2,4.15;2.55,0.5;world_configure;" .. fgettext("Configure") .. "]" ..
|
||||||
|
"button[8.5,4.95;3.25,0.5;start_server;" .. fgettext("Start Game") .. "]" ..
|
||||||
|
"label[4,-0.25;" .. fgettext("Select World:") .. "]" ..
|
||||||
|
"checkbox[0.25,0.25;cb_creative_mode;" .. fgettext("Creative Mode") .. ";" ..
|
||||||
|
dump(core.setting_getbool("creative_mode")) .. "]" ..
|
||||||
|
"checkbox[0.25,0.7;cb_enable_damage;" .. fgettext("Enable Damage") .. ";" ..
|
||||||
|
dump(core.setting_getbool("enable_damage")) .. "]" ..
|
||||||
|
"checkbox[0.25,1.15;cb_server_announce;" .. fgettext("Public") .. ";" ..
|
||||||
|
dump(core.setting_getbool("server_announce")) .. "]" ..
|
||||||
|
"label[0.25,2.2;" .. fgettext("Name/Password") .. "]" ..
|
||||||
|
"field[0.55,3.2;3.5,0.5;te_playername;;" ..
|
||||||
|
core.formspec_escape(core.setting_get("name")) .. "]" ..
|
||||||
|
"pwdfield[0.55,4;3.5,0.5;te_passwd;]"
|
||||||
|
|
||||||
local retval =
|
local bind_addr = core.setting_get("bind_address")
|
||||||
"size[16,11]"..
|
if bind_addr ~= nil and bind_addr ~= "" then
|
||||||
"box[-100,8.5;200,10;#999999]" ..
|
retval = retval ..
|
||||||
"box[-100,-10;200,12;#999999]" ..
|
"field[0.55,5.2;2.25,0.5;te_serveraddr;" .. fgettext("Bind Address") .. ";" ..
|
||||||
"bgcolor[#00000070;true]"..
|
core.formspec_escape(core.setting_get("bind_address")) .. "]" ..
|
||||||
"image_button[4,8.7;3.95,0.8;"..multicraft.formspec_escape(mm_texture.basetexturedir).."menu_button.png;start_server;".. fgettext("Play") .. ";true;true;"..multicraft.formspec_escape(mm_texture.basetexturedir).."menu_button_b.png]"..
|
"field[2.8,5.2;1.25,0.5;te_serverport;" .. fgettext("Port") .. ";" ..
|
||||||
"image_button[7.8,8.7;3.95,0.8;"..multicraft.formspec_escape(mm_texture.basetexturedir).."menu_button.png;world_create;".. fgettext("New") .. ";true;true;"..multicraft.formspec_escape(mm_texture.basetexturedir).."menu_button_b.png]"..
|
core.formspec_escape(core.setting_get("port")) .. "]"
|
||||||
|
else
|
||||||
"image_button[4,9.55;3.95,0.8;"..multicraft.formspec_escape(mm_texture.basetexturedir).."menu_button.png;world_delete;".. fgettext("Delete") .. ";true;true;"..multicraft.formspec_escape(mm_texture.basetexturedir).."menu_button_b.png]"..
|
retval = retval ..
|
||||||
--"image_button[6.53,9.55;2.68,0.8;"..multicraft.formspec_escape(mm_texture.basetexturedir).."menu_button.png;world_configure;".. fgettext("Configure") .. ";true;true;"..multicraft.formspec_escape(mm_texture.basetexturedir).."menu_button_b.png]"..
|
"field[0.55,5.2;3.5,0.5;te_serverport;" .. fgettext("Server Port") .. ";" ..
|
||||||
"image_button[7.8,9.55;3.95,0.8;"..multicraft.formspec_escape(mm_texture.basetexturedir).."menu_button.png;cancel;".. fgettext("Cancel") .. ";true;true;"..multicraft.formspec_escape(mm_texture.basetexturedir).."menu_button_b.png]"..
|
core.formspec_escape(core.setting_get("port")) .. "]"
|
||||||
"label[7,1.5;" .. fgettext("Select World:") .. "]" ..
|
end
|
||||||
|
|
||||||
"checkbox[12,8.70;cb_creative_mode;" .. fgettext("Creative Mode") .. ";" .. dump(multicraft.setting_getbool("creative_mode")) .. "]" ..
|
retval = retval ..
|
||||||
--"checkbox[1000,9.20;cb_enable_damage;" .. fgettext("Enable Damage") .. ";" .. dump(multicraft.setting_getbool("enable_damage")) .. "]" ..
|
"textlist[4,0.25;7.5,3.7;srv_worlds;" ..
|
||||||
"checkbox[12,9.50;cb_server_announce;" .. fgettext("Public") .. ";" .. dump(multicraft.setting_getbool("server_announce")) .. "]" ..
|
menu_render_worldlist() ..
|
||||||
|
";" .. index .. "]"
|
||||||
"checkbox[0.2,8.35;btn_single;Local Server;true]"..
|
|
||||||
|
return retval
|
||||||
"label[-0.25,9.15;Name]" ..
|
|
||||||
"field[1,9.45;3,0.5;te_playername;;"
|
|
||||||
|
|
||||||
local nm = multicraft.formspec_escape(multicraft.setting_get("name"))
|
|
||||||
if nm=='' then
|
|
||||||
nm='Player'
|
|
||||||
end
|
|
||||||
retval = retval ..
|
|
||||||
nm .. "]" ..
|
|
||||||
"label[-0.25,9.8;Pass]" ..
|
|
||||||
"pwdfield[1,10.15;3,0.5;te_passwd;]"
|
|
||||||
|
|
||||||
local bind_addr = multicraft.setting_get("bind_address")
|
|
||||||
|
|
||||||
if not PLATFORM=="android" and bind_addr ~= nil and bind_addr ~= "" then
|
|
||||||
retval = retval ..
|
|
||||||
"field[300,0;2.25,0.5;te_serveraddr;" .. fgettext("Bind Address") .. ";" ..
|
|
||||||
multicraft.formspec_escape(multicraft.setting_get("bind_address")) .. "]"..
|
|
||||||
"field[300,1;1.25,0.5;te_serverport;" .. fgettext("Port") .. ";" ..
|
|
||||||
multicraft.formspec_escape(multicraft.setting_get("port")) .. "]"
|
|
||||||
else
|
|
||||||
retval = retval ..
|
|
||||||
"field[300,1;3.5,0.5;te_serverport;" .. fgettext("Server Port") .. ";" ..
|
|
||||||
multicraft.formspec_escape(multicraft.setting_get("port")) .. "]"
|
|
||||||
end
|
|
||||||
|
|
||||||
retval = retval ..
|
|
||||||
"textlist[0,2.2;16,6.5;srv_worlds;" ..
|
|
||||||
menu_render_worldlist() ..
|
|
||||||
";" .. (index or 1) .. ";true]"
|
|
||||||
|
|
||||||
return retval
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
local function main_button_handler(this, fields, name, tabdata)
|
local function main_button_handler(this, fields, name, tabdata)
|
||||||
multicraft.set_clouds(false)
|
|
||||||
|
|
||||||
local world_doubleclick = false
|
local world_doubleclick = false
|
||||||
|
|
||||||
if fields["btn_single"]~=nil then
|
if fields["srv_worlds"] ~= nil then
|
||||||
local single = create_tab_single(true)
|
local event = core.explode_textlist_event(fields["srv_worlds"])
|
||||||
single:set_parent(this.parent)
|
|
||||||
single:show()
|
|
||||||
this:hide()
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
if fields["srv_worlds"] ~= nil then
|
local selected = core.get_textlist_index("srv_worlds")
|
||||||
local event = multicraft.explode_textlist_event(fields["srv_worlds"])
|
if selected ~= nil then
|
||||||
|
local filename = menudata.worldlist:get_list()[selected].path
|
||||||
|
local worldconfig = modmgr.get_worldconfig(filename)
|
||||||
|
filename = filename .. DIR_DELIM .. "world.mt"
|
||||||
|
|
||||||
if event.type == "DCL" then
|
if worldconfig.creative_mode ~= nil then
|
||||||
world_doubleclick = true
|
core.setting_set("creative_mode", worldconfig.creative_mode)
|
||||||
end
|
else
|
||||||
if event.type == "CHG" then
|
local worldfile = Settings(filename)
|
||||||
multicraft.setting_set("mainmenu_last_selected_world",
|
worldfile:set("creative_mode", core.setting_get("creative_mode"))
|
||||||
menudata.worldlist:get_raw_index(multicraft.get_textlist_index("srv_worlds")))
|
if not worldfile:write() then
|
||||||
return true
|
core.log("error", "Failed to write world config file")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
if worldconfig.enable_damage ~= nil then
|
||||||
|
core.setting_set("enable_damage", worldconfig.enable_damage)
|
||||||
|
else
|
||||||
|
local worldfile = Settings(filename)
|
||||||
|
worldfile:set("enable_damage", core.setting_get("enable_damage"))
|
||||||
|
if not worldfile:write() then
|
||||||
|
core.log("error", "Failed to write world config file")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
if menu_handle_key_up_down(fields,"srv_worlds","mainmenu_last_selected_world") then
|
if event.type == "DCL" then
|
||||||
return true
|
world_doubleclick = true
|
||||||
end
|
end
|
||||||
|
if event.type == "CHG" then
|
||||||
|
core.setting_set("mainmenu_last_selected_world",
|
||||||
|
menudata.worldlist:get_raw_index(core.get_textlist_index("srv_worlds")))
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
if fields["cb_creative_mode"] then
|
if menu_handle_key_up_down(fields,"srv_worlds","mainmenu_last_selected_world") then
|
||||||
multicraft.setting_set("creative_mode", fields["cb_creative_mode"])
|
return true
|
||||||
local bool = fields["cb_creative_mode"]
|
end
|
||||||
if bool == 'true' then
|
|
||||||
bool = 'false'
|
|
||||||
else
|
|
||||||
bool = 'true'
|
|
||||||
end
|
|
||||||
multicraft.setting_set("enable_damage", bool)
|
|
||||||
multicraft.setting_save()
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
if fields["cb_enable_damage"] then
|
if fields["cb_creative_mode"] then
|
||||||
multicraft.setting_set("enable_damage", fields["cb_enable_damage"])
|
core.setting_set("creative_mode", fields["cb_creative_mode"])
|
||||||
return true
|
local selected = core.get_textlist_index("srv_worlds")
|
||||||
end
|
local filename = menudata.worldlist:get_list()[selected].path ..
|
||||||
|
DIR_DELIM .. "world.mt"
|
||||||
|
|
||||||
if fields["cb_server_announce"] then
|
local worldfile = Settings(filename)
|
||||||
multicraft.setting_set("server_announce", fields["cb_server_announce"])
|
worldfile:set("creative_mode", fields["cb_creative_mode"])
|
||||||
return true
|
if not worldfile:write() then
|
||||||
end
|
core.log("error", "Failed to write world config file")
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
if fields["start_server"] ~= nil or
|
if fields["cb_enable_damage"] then
|
||||||
world_doubleclick or
|
core.setting_set("enable_damage", fields["cb_enable_damage"])
|
||||||
fields["key_enter"] then
|
local selected = core.get_textlist_index("srv_worlds")
|
||||||
local selected = multicraft.get_textlist_index("srv_worlds")
|
local filename = menudata.worldlist:get_list()[selected].path ..
|
||||||
if selected ~= nil then
|
DIR_DELIM .. "world.mt"
|
||||||
gamedata.playername = fields["te_playername"]
|
|
||||||
gamedata.password = fields["te_passwd"]
|
|
||||||
gamedata.port = fields["te_serverport"]
|
|
||||||
gamedata.address = ""
|
|
||||||
gamedata.selected_world = menudata.worldlist:get_raw_index(selected)
|
|
||||||
|
|
||||||
multicraft.setting_set("port",gamedata.port)
|
local worldfile = Settings(filename)
|
||||||
if fields["te_serveraddr"] ~= nil then
|
worldfile:set("enable_damage", fields["cb_enable_damage"])
|
||||||
multicraft.setting_set("bind_address",fields["te_serveraddr"])
|
if not worldfile:write() then
|
||||||
end
|
core.log("error", "Failed to write world config file")
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
--update last game
|
if fields["cb_server_announce"] then
|
||||||
local world = menudata.worldlist:get_raw_element(gamedata.selected_world)
|
core.setting_set("server_announce", fields["cb_server_announce"])
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
local game,index = gamemgr.find_by_gameid(world.gameid)
|
if fields["start_server"] ~= nil or
|
||||||
multicraft.setting_set("menu_last_game",game.id)
|
world_doubleclick or
|
||||||
multicraft.start()
|
fields["key_enter"] then
|
||||||
return true
|
local selected = core.get_textlist_index("srv_worlds")
|
||||||
end
|
if selected ~= nil then
|
||||||
end
|
gamedata.playername = fields["te_playername"]
|
||||||
|
gamedata.password = fields["te_passwd"]
|
||||||
|
gamedata.port = fields["te_serverport"]
|
||||||
|
gamedata.address = ""
|
||||||
|
gamedata.selected_world = menudata.worldlist:get_raw_index(selected)
|
||||||
|
|
||||||
if fields["world_create"] ~= nil then
|
core.setting_set("port",gamedata.port)
|
||||||
local create_world_dlg = create_create_world_dlg(true)
|
if fields["te_serveraddr"] ~= nil then
|
||||||
create_world_dlg:set_parent(this)
|
core.setting_set("bind_address",fields["te_serveraddr"])
|
||||||
create_world_dlg:show()
|
end
|
||||||
this:hide()
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
if fields["world_delete"] ~= nil then
|
--update last game
|
||||||
local selected = multicraft.get_textlist_index("srv_worlds")
|
local world = menudata.worldlist:get_raw_element(gamedata.selected_world)
|
||||||
if selected ~= nil and
|
|
||||||
selected <= menudata.worldlist:size() then
|
local game,index = gamemgr.find_by_gameid(world.gameid)
|
||||||
local world = menudata.worldlist:get_list()[selected]
|
core.setting_set("menu_last_game",game.id)
|
||||||
if world ~= nil and
|
core.start()
|
||||||
world.name ~= nil and
|
return true
|
||||||
world.name ~= "" then
|
end
|
||||||
local index = menudata.worldlist:get_raw_index(selected)
|
end
|
||||||
local delete_world_dlg = create_delete_world_dlg(world.name,index)
|
|
||||||
delete_world_dlg:set_parent(this)
|
|
||||||
delete_world_dlg:show()
|
|
||||||
this:hide()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
return true
|
if fields["world_create"] ~= nil then
|
||||||
end
|
local create_world_dlg = create_create_world_dlg(true)
|
||||||
|
create_world_dlg:set_parent(this)
|
||||||
|
create_world_dlg:show()
|
||||||
|
this:hide()
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
if fields["world_configure"] ~= nil then
|
if fields["world_delete"] ~= nil then
|
||||||
local selected = multicraft.get_textlist_index("srv_worlds")
|
local selected = core.get_textlist_index("srv_worlds")
|
||||||
if selected ~= nil then
|
if selected ~= nil and
|
||||||
local configdialog =
|
selected <= menudata.worldlist:size() then
|
||||||
create_configure_world_dlg(
|
local world = menudata.worldlist:get_list()[selected]
|
||||||
menudata.worldlist:get_raw_index(selected))
|
if world ~= nil and
|
||||||
|
world.name ~= nil and
|
||||||
|
world.name ~= "" then
|
||||||
|
local index = menudata.worldlist:get_raw_index(selected)
|
||||||
|
local delete_world_dlg = create_delete_world_dlg(world.name,index)
|
||||||
|
delete_world_dlg:set_parent(this)
|
||||||
|
delete_world_dlg:show()
|
||||||
|
this:hide()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
if (configdialog ~= nil) then
|
if fields["world_configure"] ~= nil then
|
||||||
configdialog:set_parent(this)
|
local selected = core.get_textlist_index("srv_worlds")
|
||||||
configdialog:show()
|
if selected ~= nil then
|
||||||
this:hide()
|
local configdialog =
|
||||||
end
|
create_configure_world_dlg(
|
||||||
end
|
menudata.worldlist:get_raw_index(selected))
|
||||||
return true
|
|
||||||
end
|
if (configdialog ~= nil) then
|
||||||
|
configdialog:set_parent(this)
|
||||||
if fields["cancel"] ~= nil then
|
configdialog:show()
|
||||||
this:hide()
|
this:hide()
|
||||||
this.parent:show()
|
end
|
||||||
return true
|
end
|
||||||
end
|
return true
|
||||||
|
end
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
tab_server = {
|
tab_server = {
|
||||||
name = "server",
|
name = "server",
|
||||||
caption = fgettext("Server"),
|
caption = fgettext("Server"),
|
||||||
cbf_formspec = get_formspec,
|
cbf_formspec = get_formspec,
|
||||||
cbf_button_handler = main_button_handler,
|
cbf_button_handler = main_button_handler,
|
||||||
on_change = nil
|
on_change = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function create_tab_server()
|
|
||||||
local retval = dialog_create("server",
|
|
||||||
get_formspec,
|
|
||||||
main_button_handler,
|
|
||||||
nil)
|
|
||||||
return retval
|
|
||||||
end
|
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
--
|
--
|
||||||
--This program is free software; you can redistribute it and/or modify
|
--This program is free software; you can redistribute it and/or modify
|
||||||
--it under the terms of the GNU Lesser General Public License as published by
|
--it under the terms of the GNU Lesser General Public License as published by
|
||||||
--the Free Software Foundation; either version 3.0 of the License, or
|
--the Free Software Foundation; either version 2.1 of the License, or
|
||||||
--(at your option) any later version.
|
--(at your option) any later version.
|
||||||
--
|
--
|
||||||
--This program is distributed in the hope that it will be useful,
|
--This program is distributed in the hope that it will be useful,
|
||||||
|
@ -16,451 +16,386 @@
|
||||||
--51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
--51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
local dd_filter_labels = {
|
local dd_filter_labels = {
|
||||||
fgettext("No Filter"),
|
fgettext("No Filter"),
|
||||||
fgettext("Bilinear Filter"),
|
fgettext("Bilinear Filter"),
|
||||||
fgettext("Trilinear Filter")
|
fgettext("Trilinear Filter")
|
||||||
}
|
}
|
||||||
|
|
||||||
local filters = {
|
local filters = {
|
||||||
{dd_filter_labels[1]..","..dd_filter_labels[2]..","..dd_filter_labels[3]},
|
{dd_filter_labels[1]..","..dd_filter_labels[2]..","..dd_filter_labels[3]},
|
||||||
{"", "bilinear_filter", "trilinear_filter"},
|
{"", "bilinear_filter", "trilinear_filter"},
|
||||||
}
|
}
|
||||||
|
|
||||||
local dd_mipmap_labels = {
|
local dd_mipmap_labels = {
|
||||||
fgettext("No Mipmap"),
|
fgettext("No Mipmap"),
|
||||||
fgettext("Mipmap"),
|
fgettext("Mipmap"),
|
||||||
fgettext("Mipmap + Aniso. Filter")
|
fgettext("Mipmap + Aniso. Filter")
|
||||||
}
|
}
|
||||||
|
|
||||||
local mipmap = {
|
local mipmap = {
|
||||||
{dd_mipmap_labels[1]..","..dd_mipmap_labels[2]..","..dd_mipmap_labels[3]},
|
{dd_mipmap_labels[1]..","..dd_mipmap_labels[2]..","..dd_mipmap_labels[3]},
|
||||||
{"", "mip_map", "anisotropic_filter"},
|
{"", "mip_map", "anisotropic_filter"},
|
||||||
}
|
}
|
||||||
|
|
||||||
local function getFilterSettingIndex()
|
local function getFilterSettingIndex()
|
||||||
if (multicraft.setting_get(filters[2][3]) == "true") then
|
if (core.setting_get(filters[2][3]) == "true") then
|
||||||
return 3
|
return 3
|
||||||
end
|
end
|
||||||
if (multicraft.setting_get(filters[2][3]) == "false" and multicraft.setting_get(filters[2][2]) == "true") then
|
if (core.setting_get(filters[2][3]) == "false" and core.setting_get(filters[2][2]) == "true") then
|
||||||
return 2
|
return 2
|
||||||
end
|
end
|
||||||
return 1
|
return 1
|
||||||
end
|
end
|
||||||
|
|
||||||
local function getMipmapSettingIndex()
|
local function getMipmapSettingIndex()
|
||||||
if (multicraft.setting_get(mipmap[2][3]) == "true") then
|
if (core.setting_get(mipmap[2][3]) == "true") then
|
||||||
return 3
|
return 3
|
||||||
end
|
end
|
||||||
if (multicraft.setting_get(mipmap[2][3]) == "false" and multicraft.setting_get(mipmap[2][2]) == "true") then
|
if (core.setting_get(mipmap[2][3]) == "false" and core.setting_get(mipmap[2][2]) == "true") then
|
||||||
return 2
|
return 2
|
||||||
end
|
end
|
||||||
return 1
|
return 1
|
||||||
end
|
end
|
||||||
|
|
||||||
local function video_driver_fname_to_name(selected_driver)
|
local function video_driver_fname_to_name(selected_driver)
|
||||||
local video_drivers = multicraft.get_video_drivers()
|
local video_drivers = core.get_video_drivers()
|
||||||
|
|
||||||
for i=1, #video_drivers do
|
for i=1, #video_drivers do
|
||||||
if selected_driver == video_drivers[i].friendly_name then
|
if selected_driver == video_drivers[i].friendly_name then
|
||||||
return video_drivers[i].name:lower()
|
return video_drivers[i].name:lower()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return ""
|
return ""
|
||||||
end
|
end
|
||||||
|
|
||||||
local function dlg_confirm_reset_formspec(data)
|
local function dlg_confirm_reset_formspec(data)
|
||||||
local retval =
|
local retval =
|
||||||
"size[8,3]" ..
|
"size[8,3]" ..
|
||||||
"label[1,1;".. fgettext("Are you sure to reset your singleplayer world?") .. "]"..
|
"label[1,1;".. fgettext("Are you sure to reset your singleplayer world?") .. "]"..
|
||||||
"image_button[1,2;2.6,0.8;"..multicraft.formspec_escape(mm_texture.basetexturedir).."menu_button.png;dlg_reset_singleplayer_confirm;"..
|
"button[1,2;2.6,0.5;dlg_reset_singleplayer_confirm;"..
|
||||||
fgettext("Yes") .. ";true;true;"..multicraft.formspec_escape(mm_texture.basetexturedir).."menu_button_b.png]"..
|
fgettext("Yes") .. "]" ..
|
||||||
"image_button[4,2;2.8,0.8;"..multicraft.formspec_escape(mm_texture.basetexturedir).."menu_button.png;dlg_reset_singleplayer_cancel;"..
|
"button[4,2;2.8,0.5;dlg_reset_singleplayer_cancel;"..
|
||||||
fgettext("No!!!") .. ";true;true;"..multicraft.formspec_escape(mm_texture.basetexturedir).."menu_button_b.png]"
|
fgettext("No!!!") .. "]"
|
||||||
return retval
|
return retval
|
||||||
end
|
end
|
||||||
|
|
||||||
local function dlg_confirm_reset_btnhandler(this, fields, dialogdata)
|
local function dlg_confirm_reset_btnhandler(this, fields, dialogdata)
|
||||||
multicraft.set_clouds(false)
|
|
||||||
|
|
||||||
if fields["dlg_reset_singleplayer_confirm"] ~= nil then
|
if fields["dlg_reset_singleplayer_confirm"] ~= nil then
|
||||||
local worldlist = multicraft.get_worlds()
|
local worldlist = core.get_worlds()
|
||||||
local found_singleplayerworld = false
|
local found_singleplayerworld = false
|
||||||
|
|
||||||
for i=1,#worldlist,1 do
|
for i=1,#worldlist,1 do
|
||||||
if worldlist[i].name == "singleplayerworld" then
|
if worldlist[i].name == "singleplayerworld" then
|
||||||
found_singleplayerworld = true
|
found_singleplayerworld = true
|
||||||
gamedata.worldindex = i
|
gamedata.worldindex = i
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if found_singleplayerworld then
|
if found_singleplayerworld then
|
||||||
multicraft.delete_world(gamedata.worldindex)
|
core.delete_world(gamedata.worldindex)
|
||||||
end
|
end
|
||||||
|
|
||||||
multicraft.create_world("singleplayerworld", 1)
|
core.create_world("singleplayerworld", 1)
|
||||||
|
|
||||||
worldlist = multicraft.get_worlds()
|
worldlist = core.get_worlds()
|
||||||
|
|
||||||
found_singleplayerworld = false
|
found_singleplayerworld = false
|
||||||
|
|
||||||
for i=1,#worldlist,1 do
|
for i=1,#worldlist,1 do
|
||||||
if worldlist[i].name == "singleplayerworld" then
|
if worldlist[i].name == "singleplayerworld" then
|
||||||
found_singleplayerworld = true
|
found_singleplayerworld = true
|
||||||
gamedata.worldindex = i
|
gamedata.worldindex = i
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
this.parent:show()
|
this.parent:show()
|
||||||
this:hide()
|
this:hide()
|
||||||
this:delete()
|
this:delete()
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
local function showconfirm_reset(tabview)
|
local function showconfirm_reset(tabview)
|
||||||
local new_dlg = dialog_create("reset_spworld",
|
local new_dlg = dialog_create("reset_spworld",
|
||||||
dlg_confirm_reset_formspec,
|
dlg_confirm_reset_formspec,
|
||||||
dlg_confirm_reset_btnhandler,
|
dlg_confirm_reset_btnhandler,
|
||||||
nil)
|
nil)
|
||||||
new_dlg:set_parent(tabview)
|
new_dlg:set_parent(tabview)
|
||||||
tabview:hide()
|
tabview:hide()
|
||||||
new_dlg:show()
|
new_dlg:show()
|
||||||
end
|
end
|
||||||
|
|
||||||
local function gui_scale_to_scrollbar()
|
local function gui_scale_to_scrollbar()
|
||||||
|
local current_value = tonumber(core.setting_get("gui_scaling"))
|
||||||
|
|
||||||
local current_value = tonumber(multicraft.setting_get("gui_scaling"))
|
if (current_value == nil) or current_value < 0.25 then
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
if current_value <= 1.25 then
|
||||||
|
return ((current_value - 0.25)/ 1.0) * 700
|
||||||
|
end
|
||||||
|
if current_value <= 6 then
|
||||||
|
return ((current_value -1.25) * 100) + 700
|
||||||
|
end
|
||||||
|
|
||||||
if (current_value == nil) or current_value < 0.25 then
|
return 1000
|
||||||
return 0
|
|
||||||
end
|
|
||||||
|
|
||||||
if current_value <= 1.25 then
|
|
||||||
return ((current_value - 0.25)/ 1.0) * 700
|
|
||||||
end
|
|
||||||
|
|
||||||
if current_value <= 6 then
|
|
||||||
return ((current_value -1.25) * 100) + 700
|
|
||||||
end
|
|
||||||
|
|
||||||
return 1000
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local function scrollbar_to_gui_scale(value)
|
local function scrollbar_to_gui_scale(value)
|
||||||
|
value = tonumber(value)
|
||||||
|
|
||||||
value = tonumber(value)
|
if (value <= 700) then
|
||||||
|
return ((value / 700) * 1.0) + 0.25
|
||||||
|
end
|
||||||
|
if (value <=1000) then
|
||||||
|
return ((value - 700) / 100) + 1.25
|
||||||
|
end
|
||||||
|
|
||||||
if (value <= 700) then
|
return 1
|
||||||
return ((value / 700) * 1.0) + 0.25
|
|
||||||
end
|
|
||||||
|
|
||||||
if (value <=1000) then
|
|
||||||
return ((value - 700) / 100) + 1.25
|
|
||||||
end
|
|
||||||
|
|
||||||
return 1
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local function formspec(tabview, name, tabdata)
|
local function formspec(tabview, name, tabdata)
|
||||||
local video_drivers = multicraft.get_video_drivers()
|
local video_drivers = core.get_video_drivers()
|
||||||
local current_video_driver = multicraft.setting_get("video_driver"):lower()
|
local current_video_driver = core.setting_get("video_driver"):lower()
|
||||||
|
|
||||||
local driver_formspec_string = ""
|
local driver_formspec_string = ""
|
||||||
local driver_current_idx = 0
|
local driver_current_idx = 0
|
||||||
|
|
||||||
for i=2, #video_drivers do
|
for i=2, #video_drivers do
|
||||||
driver_formspec_string = driver_formspec_string .. video_drivers[i].friendly_name
|
driver_formspec_string = driver_formspec_string .. video_drivers[i].friendly_name
|
||||||
if i ~= #video_drivers then
|
if i ~= #video_drivers then
|
||||||
driver_formspec_string = driver_formspec_string .. ","
|
driver_formspec_string = driver_formspec_string .. ","
|
||||||
end
|
end
|
||||||
|
|
||||||
if current_video_driver == video_drivers[i].name:lower() then
|
if current_video_driver == video_drivers[i].name:lower() then
|
||||||
driver_current_idx = i - 1
|
driver_current_idx = i - 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local tab_string =
|
||||||
|
"box[0,0;3.5,3.9;#999999]" ..
|
||||||
|
"checkbox[0.25,0;cb_smooth_lighting;".. fgettext("Smooth Lighting")
|
||||||
|
.. ";".. dump(core.setting_getbool("smooth_lighting")) .. "]"..
|
||||||
|
"checkbox[0.25,0.5;cb_particles;".. fgettext("Enable Particles") .. ";"
|
||||||
|
.. dump(core.setting_getbool("enable_particles")) .. "]"..
|
||||||
|
"checkbox[0.25,1;cb_3d_clouds;".. fgettext("3D Clouds") .. ";"
|
||||||
|
.. dump(core.setting_getbool("enable_3d_clouds")) .. "]"..
|
||||||
|
"checkbox[0.25,1.5;cb_fancy_trees;".. fgettext("Fancy Trees") .. ";"
|
||||||
|
.. dump(core.setting_getbool("new_style_leaves")) .. "]"..
|
||||||
|
"checkbox[0.25,2.0;cb_opaque_water;".. fgettext("Opaque Water") .. ";"
|
||||||
|
.. dump(core.setting_getbool("opaque_water")) .. "]"..
|
||||||
|
"checkbox[0.25,2.5;cb_connected_glass;".. fgettext("Connected Glass") .. ";"
|
||||||
|
.. dump(core.setting_getbool("connected_glass")) .. "]"..
|
||||||
|
"checkbox[0.25,3.0;cb_node_highlighting;".. fgettext("Node Highlighting") .. ";"
|
||||||
|
.. dump(core.setting_getbool("enable_node_highlighting")) .. "]"..
|
||||||
|
"box[3.75,0;3.75,3.45;#999999]" ..
|
||||||
|
"label[3.85,0.1;".. fgettext("Texturing:") .. "]"..
|
||||||
|
"dropdown[3.85,0.55;3.85;dd_filters;" .. filters[1][1] .. ";"
|
||||||
|
.. getFilterSettingIndex() .. "]" ..
|
||||||
|
"dropdown[3.85,1.35;3.85;dd_mipmap;" .. mipmap[1][1] .. ";"
|
||||||
|
.. getMipmapSettingIndex() .. "]" ..
|
||||||
|
"label[3.85,2.15;".. fgettext("Rendering:") .. "]"..
|
||||||
|
"dropdown[3.85,2.6;3.85;dd_video_driver;"
|
||||||
|
.. driver_formspec_string .. ";" .. driver_current_idx .. "]" ..
|
||||||
|
"tooltip[dd_video_driver;" ..
|
||||||
|
fgettext("Restart minetest for driver change to take effect") .. "]" ..
|
||||||
|
"box[7.75,0;4,4;#999999]" ..
|
||||||
|
"checkbox[8,0;cb_shaders;".. fgettext("Shaders") .. ";"
|
||||||
|
.. dump(core.setting_getbool("enable_shaders")) .. "]"
|
||||||
|
|
||||||
local tab_string =
|
if PLATFORM ~= "Android" then
|
||||||
"size[16,11]"..
|
tab_string = tab_string ..
|
||||||
"bgcolor[#00000070;true]"..
|
"button[8,4.75;3.75,0.5;btn_change_keys;".. fgettext("Change keys") .. "]"
|
||||||
"box[-100,8.5;200,10;#999999]" ..
|
else
|
||||||
"box[-100,-10;200,12;#999999]" ..
|
tab_string = tab_string ..
|
||||||
|
"button[8,4.75;3.75,0.5;btn_reset_singleplayer;".. fgettext("Reset singleplayer world") .. "]"
|
||||||
|
end
|
||||||
|
tab_string = tab_string ..
|
||||||
|
"box[0,4.25;3.5,1.1;#999999]" ..
|
||||||
|
"label[0.25,4.25;" .. fgettext("GUI scale factor") .. "]" ..
|
||||||
|
"scrollbar[0.25,4.75;3,0.4;sb_gui_scaling;horizontal;" ..
|
||||||
|
gui_scale_to_scrollbar() .. "]" ..
|
||||||
|
"tooltip[sb_gui_scaling;" ..
|
||||||
|
fgettext("Scaling factor applied to menu elements: ") ..
|
||||||
|
dump(core.setting_get("gui_scaling")) .. "]"
|
||||||
|
|
||||||
"box[0.75,2.5;4.5,3.9;#999999]" ..
|
if PLATFORM == "Android" then
|
||||||
"checkbox[1.0,2.5;cb_smooth_lighting;".. fgettext("Smooth Lighting")
|
tab_string = tab_string ..
|
||||||
.. ";".. dump(multicraft.setting_getbool("smooth_lighting")) .. "]"..
|
"box[3.75,3.55;3.75,1.8;#999999]" ..
|
||||||
"checkbox[1.0,3.0;cb_particles;".. fgettext("Enable Particles") .. ";"
|
"checkbox[3.9,3.45;cb_touchscreen_target;".. fgettext("Touch free target") .. ";"
|
||||||
.. dump(multicraft.setting_getbool("enable_particles")) .. "]"..
|
.. dump(core.setting_getbool("touchtarget")) .. "]"
|
||||||
"checkbox[1.0,3.5;cb_3d_clouds;".. fgettext("3D Clouds") .. ";"
|
end
|
||||||
.. dump(multicraft.setting_getbool("enable_3d_clouds")) .. "]"..
|
|
||||||
"checkbox[1.0,4.0;cb_fancy_trees;".. fgettext("Fancy Trees") .. ";"
|
|
||||||
.. dump(multicraft.setting_getbool("new_style_leaves")) .. "]"..
|
|
||||||
"checkbox[1.0,4.5;cb_opaque_water;".. fgettext("Opaque Water") .. ";"
|
|
||||||
.. dump(multicraft.setting_getbool("opaque_water")) .. "]"..
|
|
||||||
"checkbox[1.0,5.0;cb_connected_glass;".. fgettext("Connected Glass") .. ";"
|
|
||||||
.. dump(multicraft.setting_getbool("connected_glass")) .. "]"..
|
|
||||||
"checkbox[1.0,5.5;cb_node_highlighting;".. fgettext("Node Highlighting") .. ";"
|
|
||||||
.. dump(multicraft.setting_getbool("enable_node_highlighting")) .. "]"..
|
|
||||||
|
|
||||||
|
if core.setting_get("touchscreen_threshold") ~= nil then
|
||||||
|
tab_string = tab_string ..
|
||||||
|
"label[4.3,4.1;" .. fgettext("Touchthreshold (px)") .. "]" ..
|
||||||
|
"dropdown[3.85,4.55;3.85;dd_touchthreshold;0,10,20,30,40,50;" ..
|
||||||
|
((tonumber(core.setting_get("touchscreen_threshold"))/10)+1) .. "]"
|
||||||
|
end
|
||||||
|
|
||||||
"box[5.5,2.5;4,3.45;#999999]" ..
|
if core.setting_getbool("enable_shaders") then
|
||||||
"label[5.85,2.5;".. fgettext("Texturing:") .. "]"..
|
tab_string = tab_string ..
|
||||||
"dropdown[5.85,3.05;3.85;dd_filters;" .. filters[1][1] .. ";"
|
"checkbox[8,0.5;cb_bumpmapping;".. fgettext("Bumpmapping") .. ";"
|
||||||
.. getFilterSettingIndex() .. "]" ..
|
.. dump(core.setting_getbool("enable_bumpmapping")) .. "]"..
|
||||||
"dropdown[5.85,3.85;3.85;dd_mipmap;" .. mipmap[1][1] .. ";"
|
"checkbox[8,1.0;cb_generate_normalmaps;".. fgettext("Generate Normalmaps") .. ";"
|
||||||
.. getMipmapSettingIndex() .. "]" ..
|
.. dump(core.setting_getbool("generate_normalmaps")) .. "]"..
|
||||||
"label[5.85,4.65;".. fgettext("Rendering:") .. "]"..
|
"checkbox[8,1.5;cb_parallax;".. fgettext("Parallax Occlusion") .. ";"
|
||||||
"dropdown[5.85,5.1;3.85;dd_video_driver;"
|
.. dump(core.setting_getbool("enable_parallax_occlusion")) .. "]"..
|
||||||
.. driver_formspec_string .. ";" .. driver_current_idx .. "]" ..
|
"checkbox[8,2.0;cb_waving_water;".. fgettext("Waving Water") .. ";"
|
||||||
"tooltip[dd_video_driver;" ..
|
.. dump(core.setting_getbool("enable_waving_water")) .. "]"..
|
||||||
fgettext("Restart multicraft for driver change to take effect") .. "]"
|
"checkbox[8,2.5;cb_waving_leaves;".. fgettext("Waving Leaves") .. ";"
|
||||||
|
.. dump(core.setting_getbool("enable_waving_leaves")) .. "]"..
|
||||||
|
"checkbox[8,3.0;cb_waving_plants;".. fgettext("Waving Plants") .. ";"
|
||||||
|
.. dump(core.setting_getbool("enable_waving_plants")) .. "]"
|
||||||
|
else
|
||||||
if PLATFORM ~= "Android" then
|
tab_string = tab_string ..
|
||||||
tab_string = tab_string ..
|
"textlist[8.33,0.7;4,1;;#888888" .. fgettext("Bumpmapping") .. ";0;true]" ..
|
||||||
"box[9.75,2.5;5.25,4;#999999]"..
|
"textlist[8.33,1.2;4,1;;#888888" .. fgettext("Generate Normalmaps") .. ";0;true]" ..
|
||||||
"checkbox[10,2.5;cb_shaders;".. fgettext("Shaders") .. ";"
|
"textlist[8.33,1.7;4,1;;#888888" .. fgettext("Parallax Occlusion") .. ";0;true]" ..
|
||||||
.. dump(multicraft.setting_getbool("enable_shaders")) .. "]"..
|
"textlist[8.33,2.2;4,1;;#888888" .. fgettext("Waving Water") .. ";0;true]" ..
|
||||||
"image_button[0,9.55;4,0.8;"..multicraft.formspec_escape(mm_texture.basetexturedir).."menu_button.png;btn_change_keys;".. fgettext("Change keys") .. ";true;true;"..multicraft.formspec_escape(mm_texture.basetexturedir).."menu_button_b.png]"--..
|
"textlist[8.33,2.7;4,1;;#888888" .. fgettext("Waving Leaves") .. ";0;true]" ..
|
||||||
-- "image_button[3.75,5;3.88,0.8;"..multicraft.formspec_escape(mm_texture.basetexturedir).."menu_button.png;btn_reset_singleplayer;".. fgettext("Reset singleplayer world") .. ";true;true;"..multicraft.formspec_escape(mm_texture.basetexturedir).."menu_button_b.png]"
|
"textlist[8.33,3.2;4,1;;#888888" .. fgettext("Waving Plants") .. ";0;true]"
|
||||||
else
|
end
|
||||||
--tab_string = tab_string ..
|
return tab_string
|
||||||
-- "image_button[3.75,5;3.88,0.8;"..multicraft.formspec_escape(mm_texture.basetexturedir).."menu_button.png;btn_reset_singleplayer;".. fgettext("Reset singleplayer world") .. ";true;true;"..multicraft.formspec_escape(mm_texture.basetexturedir).."menu_button_b.png]"
|
|
||||||
end
|
|
||||||
|
|
||||||
tab_string = tab_string ..
|
|
||||||
"image_button[4,9.55;3.95,0.8;"..multicraft.formspec_escape(mm_texture.basetexturedir).."menu_button.png;btn_show_textures;".. fgettext("Texturepacks") .. ";true;true;"..multicraft.formspec_escape(mm_texture.basetexturedir)..
|
|
||||||
"menu_button_b.png]"..
|
|
||||||
"image_button[8,9.55;3.95,0.8;"..multicraft.formspec_escape(mm_texture.basetexturedir).."menu_button.png;btn_show_credits;".. fgettext("Credits") .. ";true;true;"..multicraft.formspec_escape(mm_texture.basetexturedir).."menu_button_b.png]"..
|
|
||||||
"image_button[12,9.55;4,0.8;"..multicraft.formspec_escape(mm_texture.basetexturedir).."menu_button.png;btn_cancel;".. fgettext("OK") .. ";true;true;"..multicraft.formspec_escape(mm_texture.basetexturedir).."menu_button_b.png]"
|
|
||||||
|
|
||||||
|
|
||||||
if PLATFORM == "Android" then
|
|
||||||
tab_string = tab_string ..
|
|
||||||
"box[9.75,2.5;5.25,2.5;#999999]" ..
|
|
||||||
"checkbox[10,2.75;cb_touchscreen_target;".. fgettext("Touch free target") .. ";" .. dump(multicraft.setting_getbool("touchtarget")) .. "]"..
|
|
||||||
""
|
|
||||||
-- "box[0.75,6.8;14.25,1.35;#999999]" ..
|
|
||||||
-- "label[1.5,6.8;" .. fgettext("GUI scale factor") .. "]"..
|
|
||||||
--"scrollbar[1.0,7.2;13.75,0.7;sb_gui_scaling;horizontal;" .. gui_scale_to_scrollbar() .. "]" ..
|
|
||||||
-- "tooltip[sb_gui_scaling;" .. fgettext("Scaling factor applied to menu elements: ") .. dump(multicraft.setting_get("gui_scaling")) .. "]"
|
|
||||||
|
|
||||||
-- if multicraft.setting_get("touchscreen_threshold") ~= nil then
|
|
||||||
tab_string = tab_string ..
|
|
||||||
"label[10,3.5;" .. fgettext("Touchthreshold (px)") .. "]" ..
|
|
||||||
"dropdown[10,4.0;5.18;dd_touchthreshold;0,10,20,30,40,50;" .. ((tonumber(multicraft.setting_get("touchscreen_threshold") or 20)/10)+1) .. "]"
|
|
||||||
-- end
|
|
||||||
|
|
||||||
--else
|
|
||||||
-- tab_string = tab_string ..
|
|
||||||
-- "box[0.75,6.8;14.25,1.35;#999999]" ..
|
|
||||||
-- "label[1.5,6.8;" .. fgettext("GUI scale factor") .. "]"..
|
|
||||||
-- "scrollbar[1.0,7.5;13.75,0.4;sb_gui_scaling;horizontal;" .. gui_scale_to_scrollbar() .. "]" ..
|
|
||||||
-- "tooltip[sb_gui_scaling;" .. fgettext("Scaling factor applied to menu elements: ") .. dump(multicraft.setting_get("gui_scaling")) .. "]"
|
|
||||||
end
|
|
||||||
|
|
||||||
if PLATFORM ~= "Android" then
|
|
||||||
if multicraft.setting_getbool("enable_shaders") then
|
|
||||||
tab_string = tab_string ..
|
|
||||||
"checkbox[10,3.0;cb_bumpmapping;".. fgettext("Bumpmapping") .. ";"
|
|
||||||
.. dump(multicraft.setting_getbool("enable_bumpmapping")) .. "]"..
|
|
||||||
"checkbox[10,3.5;cb_generate_normalmaps;".. fgettext("Generate Normalmaps") .. ";"
|
|
||||||
.. dump(multicraft.setting_getbool("generate_normalmaps")) .. "]"..
|
|
||||||
"checkbox[10,4.0;cb_parallax;".. fgettext("Parallax Occlusion") .. ";"
|
|
||||||
.. dump(multicraft.setting_getbool("enable_parallax_occlusion")) .. "]"..
|
|
||||||
"checkbox[10,4.5;cb_waving_water;".. fgettext("Waving Water") .. ";"
|
|
||||||
.. dump(multicraft.setting_getbool("enable_waving_water")) .. "]"..
|
|
||||||
"checkbox[10,5.0;cb_waving_leaves;".. fgettext("Waving Leaves") .. ";"
|
|
||||||
.. dump(multicraft.setting_getbool("enable_waving_leaves")) .. "]"..
|
|
||||||
"checkbox[10,5.5;cb_waving_plants;".. fgettext("Waving Plants") .. ";"
|
|
||||||
.. dump(multicraft.setting_getbool("enable_waving_plants")) .. "]"
|
|
||||||
else
|
|
||||||
tab_string = tab_string ..
|
|
||||||
"textlist[10.3,3.2;4,1;;#888888" .. fgettext("Bumpmapping") .. ";0;true]" ..
|
|
||||||
"textlist[10.3,3.7;4,1;;#888888" .. fgettext("Generate Normalmaps") .. ";0;true]" ..
|
|
||||||
"textlist[10.3,4.2;4,1;;#888888" .. fgettext("Parallax Occlusion") .. ";0;true]" ..
|
|
||||||
"textlist[10.3,4.7;4,1;;#888888" .. fgettext("Waving Water") .. ";0;true]" ..
|
|
||||||
"textlist[10.3,5.2;4,1;;#888888" .. fgettext("Waving Leaves") .. ";0;true]" ..
|
|
||||||
"textlist[10.3,5.7;4,1;;#888888" .. fgettext("Waving Plants") .. ";0;true]"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return tab_string
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
local function handle_settings_buttons(this, fields, tabname, tabdata)
|
local function handle_settings_buttons(this, fields, tabname, tabdata)
|
||||||
if fields["cb_fancy_trees"] then
|
if fields["cb_fancy_trees"] then
|
||||||
multicraft.setting_set("new_style_leaves", fields["cb_fancy_trees"])
|
core.setting_set("new_style_leaves", fields["cb_fancy_trees"])
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
if fields["cb_smooth_lighting"] then
|
if fields["cb_smooth_lighting"] then
|
||||||
multicraft.setting_set("smooth_lighting", fields["cb_smooth_lighting"])
|
core.setting_set("smooth_lighting", fields["cb_smooth_lighting"])
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
if fields["cb_3d_clouds"] then
|
if fields["cb_3d_clouds"] then
|
||||||
multicraft.setting_set("enable_3d_clouds", fields["cb_3d_clouds"])
|
core.setting_set("enable_3d_clouds", fields["cb_3d_clouds"])
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
if fields["cb_opaque_water"] then
|
if fields["cb_opaque_water"] then
|
||||||
multicraft.setting_set("opaque_water", fields["cb_opaque_water"])
|
core.setting_set("opaque_water", fields["cb_opaque_water"])
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
if fields["cb_mipmapping"] then
|
if fields["cb_shaders"] then
|
||||||
multicraft.setting_set("mip_map", fields["cb_mipmapping"])
|
if (core.setting_get("video_driver") == "direct3d8" or core.setting_get("video_driver") == "direct3d9") then
|
||||||
return true
|
core.setting_set("enable_shaders", "false")
|
||||||
end
|
gamedata.errormessage = fgettext("To enable shaders the OpenGL driver needs to be used.")
|
||||||
if fields["cb_anisotrophic"] then
|
else
|
||||||
multicraft.setting_set("anisotropic_filter", fields["cb_anisotrophic"])
|
core.setting_set("enable_shaders", fields["cb_shaders"])
|
||||||
return true
|
end
|
||||||
end
|
return true
|
||||||
if fields["cb_bilinear"] then
|
end
|
||||||
multicraft.setting_set("bilinear_filter", fields["cb_bilinear"])
|
if fields["cb_connected_glass"] then
|
||||||
return true
|
core.setting_set("connected_glass", fields["cb_connected_glass"])
|
||||||
end
|
return true
|
||||||
if fields["cb_trilinear"] then
|
end
|
||||||
multicraft.setting_set("trilinear_filter", fields["cb_trilinear"])
|
if fields["cb_node_highlighting"] then
|
||||||
return true
|
core.setting_set("enable_node_highlighting", fields["cb_node_highlighting"])
|
||||||
end
|
return true
|
||||||
if fields["cb_shaders"] then
|
end
|
||||||
if (multicraft.setting_get("video_driver") == "direct3d8" or multicraft.setting_get("video_driver") == "direct3d9") then
|
if fields["cb_particles"] then
|
||||||
multicraft.setting_set("enable_shaders", "false")
|
core.setting_set("enable_particles", fields["cb_particles"])
|
||||||
gamedata.errormessage = fgettext("To enable shaders the OpenGL driver needs to be used.")
|
return true
|
||||||
else
|
end
|
||||||
multicraft.setting_set("enable_shaders", fields["cb_shaders"])
|
if fields["cb_bumpmapping"] then
|
||||||
end
|
core.setting_set("enable_bumpmapping", fields["cb_bumpmapping"])
|
||||||
return true
|
end
|
||||||
end
|
if fields["cb_generate_normalmaps"] then
|
||||||
if fields["cb_connected_glass"] then
|
core.setting_set("generate_normalmaps", fields["cb_generate_normalmaps"])
|
||||||
multicraft.setting_set("connected_glass", fields["cb_connected_glass"])
|
end
|
||||||
return true
|
if fields["cb_parallax"] then
|
||||||
end
|
core.setting_set("enable_parallax_occlusion", fields["cb_parallax"])
|
||||||
if fields["cb_particles"] then
|
return true
|
||||||
multicraft.setting_set("enable_particles", fields["cb_particles"])
|
end
|
||||||
return true
|
if fields["cb_waving_water"] then
|
||||||
end
|
core.setting_set("enable_waving_water", fields["cb_waving_water"])
|
||||||
if fields["cb_bumpmapping"] then
|
return true
|
||||||
multicraft.setting_set("enable_bumpmapping", fields["cb_bumpmapping"])
|
end
|
||||||
end
|
if fields["cb_waving_leaves"] then
|
||||||
if fields["cb_generate_normalmaps"] then
|
core.setting_set("enable_waving_leaves", fields["cb_waving_leaves"])
|
||||||
multicraft.setting_set("generate_normalmaps", fields["cb_generate_normalmaps"])
|
end
|
||||||
end
|
if fields["cb_waving_plants"] then
|
||||||
if fields["cb_parallax"] then
|
core.setting_set("enable_waving_plants", fields["cb_waving_plants"])
|
||||||
multicraft.setting_set("enable_parallax_occlusion", fields["cb_parallax"])
|
return true
|
||||||
return true
|
end
|
||||||
end
|
if fields["btn_change_keys"] ~= nil then
|
||||||
if fields["cb_waving_water"] then
|
core.show_keys_menu()
|
||||||
multicraft.setting_set("enable_waving_water", fields["cb_waving_water"])
|
return true
|
||||||
return true
|
end
|
||||||
end
|
|
||||||
if fields["cb_waving_leaves"] then
|
|
||||||
multicraft.setting_set("enable_waving_leaves", fields["cb_waving_leaves"])
|
|
||||||
end
|
|
||||||
if fields["cb_waving_plants"] then
|
|
||||||
multicraft.setting_set("enable_waving_plants", fields["cb_waving_plants"])
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
if fields["btn_change_keys"] ~= nil then
|
|
||||||
multicraft.show_keys_menu()
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
if fields["sb_gui_scaling"] then
|
if fields["sb_gui_scaling"] then
|
||||||
local event = multicraft.explode_scrollbar_event(fields["sb_gui_scaling"])
|
local event = core.explode_scrollbar_event(fields["sb_gui_scaling"])
|
||||||
|
|
||||||
if event.type == "CHG" then
|
if event.type == "CHG" then
|
||||||
local tosave = string.format("%.2f",scrollbar_to_gui_scale(event.value))
|
local tosave = string.format("%.2f",scrollbar_to_gui_scale(event.value))
|
||||||
multicraft.setting_set("gui_scaling",tosave)
|
core.setting_set("gui_scaling",tosave)
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if fields["cb_touchscreen_target"] then
|
if fields["cb_touchscreen_target"] then
|
||||||
multicraft.setting_set("touchtarget", fields["cb_touchscreen_target"])
|
core.setting_set("touchtarget", fields["cb_touchscreen_target"])
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
if fields["btn_reset_singleplayer"] then
|
if fields["btn_reset_singleplayer"] then
|
||||||
showconfirm_reset(this)
|
showconfirm_reset(this)
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
if fields["btn_cancel"] ~= nil then
|
--Note dropdowns have to be handled LAST!
|
||||||
this:hide()
|
local ddhandled = false
|
||||||
this.parent:show()
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
|
if fields["dd_touchthreshold"] then
|
||||||
|
core.setting_set("touchscreen_threshold",fields["dd_touchthreshold"])
|
||||||
|
ddhandled = true
|
||||||
|
end
|
||||||
|
|
||||||
local index = ''
|
if fields["dd_video_driver"] then
|
||||||
if fields["btn_show_textures"] then index = "texturepacks" end
|
core.setting_set("video_driver",
|
||||||
if fields["btn_show_credits"] then index = "credits" end
|
video_driver_fname_to_name(fields["dd_video_driver"]))
|
||||||
|
ddhandled = true
|
||||||
|
end
|
||||||
|
if fields["dd_filters"] == dd_filter_labels[1] then
|
||||||
|
core.setting_set("bilinear_filter", "false")
|
||||||
|
core.setting_set("trilinear_filter", "false")
|
||||||
|
ddhandled = true
|
||||||
|
end
|
||||||
|
if fields["dd_filters"] == dd_filter_labels[2] then
|
||||||
|
core.setting_set("bilinear_filter", "true")
|
||||||
|
core.setting_set("trilinear_filter", "false")
|
||||||
|
ddhandled = true
|
||||||
|
end
|
||||||
|
if fields["dd_filters"] == dd_filter_labels[3] then
|
||||||
|
core.setting_set("bilinear_filter", "false")
|
||||||
|
core.setting_set("trilinear_filter", "true")
|
||||||
|
ddhandled = true
|
||||||
|
end
|
||||||
|
if fields["dd_mipmap"] == dd_mipmap_labels[1] then
|
||||||
|
core.setting_set("mip_map", "false")
|
||||||
|
core.setting_set("anisotropic_filter", "false")
|
||||||
|
ddhandled = true
|
||||||
|
end
|
||||||
|
if fields["dd_mipmap"] == dd_mipmap_labels[2] then
|
||||||
|
core.setting_set("mip_map", "true")
|
||||||
|
core.setting_set("anisotropic_filter", "false")
|
||||||
|
ddhandled = true
|
||||||
|
end
|
||||||
|
if fields["dd_mipmap"] == dd_mipmap_labels[3] then
|
||||||
|
core.setting_set("mip_map", "true")
|
||||||
|
core.setting_set("anisotropic_filter", "true")
|
||||||
|
ddhandled = true
|
||||||
|
end
|
||||||
|
|
||||||
for name,def in pairs(this.parent.tablist) do
|
return ddhandled
|
||||||
if index == def.name then
|
|
||||||
local get_fs = function()
|
|
||||||
local retval = def.get_formspec(this.parent, name, tabdata)
|
|
||||||
retval = 'size[12,5.2]'..retval
|
|
||||||
return retval
|
|
||||||
end
|
|
||||||
local dlg = dialog_create(def.name, get_fs, def.button_handler, def.on_change)
|
|
||||||
dlg:set_parent(this)
|
|
||||||
this:hide()
|
|
||||||
dlg:show()
|
|
||||||
return dlg
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
--Note dropdowns have to be handled LAST!
|
|
||||||
local ddhandled = false
|
|
||||||
|
|
||||||
if fields["dd_touchthreshold"] then
|
|
||||||
multicraft.setting_set("touchscreen_threshold",fields["dd_touchthreshold"])
|
|
||||||
ddhandled = true
|
|
||||||
end
|
|
||||||
|
|
||||||
if fields["dd_video_driver"] then
|
|
||||||
multicraft.setting_set("video_driver",
|
|
||||||
video_driver_fname_to_name(fields["dd_video_driver"]))
|
|
||||||
ddhandled = true
|
|
||||||
end
|
|
||||||
if fields["dd_filters"] == dd_filter_labels[1] then
|
|
||||||
multicraft.setting_set("bilinear_filter", "false")
|
|
||||||
multicraft.setting_set("trilinear_filter", "false")
|
|
||||||
ddhandled = true
|
|
||||||
end
|
|
||||||
if fields["dd_filters"] == dd_filter_labels[2] then
|
|
||||||
multicraft.setting_set("bilinear_filter", "true")
|
|
||||||
multicraft.setting_set("trilinear_filter", "false")
|
|
||||||
ddhandled = true
|
|
||||||
end
|
|
||||||
if fields["dd_filters"] == dd_filter_labels[3] then
|
|
||||||
multicraft.setting_set("bilinear_filter", "false")
|
|
||||||
multicraft.setting_set("trilinear_filter", "true")
|
|
||||||
ddhandled = true
|
|
||||||
end
|
|
||||||
if fields["dd_mipmap"] == dd_mipmap_labels[1] then
|
|
||||||
multicraft.setting_set("mip_map", "false")
|
|
||||||
multicraft.setting_set("anisotropic_filter", "false")
|
|
||||||
ddhandled = true
|
|
||||||
end
|
|
||||||
if fields["dd_mipmap"] == dd_mipmap_labels[2] then
|
|
||||||
multicraft.setting_set("mip_map", "true")
|
|
||||||
multicraft.setting_set("anisotropic_filter", "false")
|
|
||||||
ddhandled = true
|
|
||||||
end
|
|
||||||
if fields["dd_mipmap"] == dd_mipmap_labels[3] then
|
|
||||||
multicraft.setting_set("mip_map", "true")
|
|
||||||
multicraft.setting_set("anisotropic_filter", "true")
|
|
||||||
ddhandled = true
|
|
||||||
end
|
|
||||||
|
|
||||||
return ddhandled
|
|
||||||
end
|
end
|
||||||
|
|
||||||
tab_settings = {
|
tab_settings = {
|
||||||
name = "settings",
|
name = "settings",
|
||||||
caption = fgettext("Settings"),
|
caption = fgettext("Settings"),
|
||||||
cbf_formspec = formspec,
|
cbf_formspec = formspec,
|
||||||
cbf_button_handler = handle_settings_buttons
|
cbf_button_handler = handle_settings_buttons
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,205 @@
|
||||||
|
--Minetest
|
||||||
|
--Copyright (C) 2013 sapier
|
||||||
|
--
|
||||||
|
--This program is free software; you can redistribute it and/or modify
|
||||||
|
--it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
--the Free Software Foundation; either version 2.1 of the License, or
|
||||||
|
--(at your option) any later version.
|
||||||
|
--
|
||||||
|
--This program is distributed in the hope that it will be useful,
|
||||||
|
--but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
--MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
--GNU Lesser General Public License for more details.
|
||||||
|
--
|
||||||
|
--You should have received a copy of the GNU Lesser General Public License along
|
||||||
|
--with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
--51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
local function get_formspec(tabview, name, tabdata)
|
||||||
|
local retval = ""
|
||||||
|
|
||||||
|
local render_details = dump(core.setting_getbool("public_serverlist"))
|
||||||
|
|
||||||
|
retval = retval ..
|
||||||
|
"label[8,0.5;".. fgettext("Name/Password") .. "]" ..
|
||||||
|
"field[0.25,3.25;5.5,0.5;te_address;;" ..
|
||||||
|
core.formspec_escape(core.setting_get("address")) .."]" ..
|
||||||
|
"field[5.75,3.25;2.25,0.5;te_port;;" ..
|
||||||
|
core.formspec_escape(core.setting_get("remote_port")) .."]" ..
|
||||||
|
"checkbox[8,-0.25;cb_public_serverlist;".. fgettext("Public Serverlist") .. ";" ..
|
||||||
|
render_details .. "]"
|
||||||
|
|
||||||
|
retval = retval ..
|
||||||
|
"button[8,2.5;4,1.5;btn_mp_connect;".. fgettext("Connect") .. "]" ..
|
||||||
|
"field[8.75,1.5;3.5,0.5;te_name;;" ..
|
||||||
|
core.formspec_escape(core.setting_get("name")) .."]" ..
|
||||||
|
"pwdfield[8.75,2.3;3.5,0.5;te_pwd;]"
|
||||||
|
|
||||||
|
if render_details then
|
||||||
|
retval = retval .. "tablecolumns[" ..
|
||||||
|
"color,span=3;" ..
|
||||||
|
"text,align=right;" .. -- clients
|
||||||
|
"text,align=center,padding=0.25;" .. -- "/"
|
||||||
|
"text,align=right,padding=0.25;" .. -- clients_max
|
||||||
|
image_column(fgettext("Creative mode"), "creative") .. ",padding=1;" ..
|
||||||
|
image_column(fgettext("Damage enabled"), "damage") .. ",padding=0.25;" ..
|
||||||
|
image_column(fgettext("PvP enabled"), "pvp") .. ",padding=0.25;" ..
|
||||||
|
"color,span=1;" ..
|
||||||
|
"text,padding=1]" -- name
|
||||||
|
else
|
||||||
|
retval = retval .. "tablecolumns[text]"
|
||||||
|
end
|
||||||
|
retval = retval ..
|
||||||
|
"table[-0.05,0;7.55,2.75;favourites;"
|
||||||
|
|
||||||
|
if #menudata.favorites > 0 then
|
||||||
|
retval = retval .. render_favorite(menudata.favorites[1],render_details)
|
||||||
|
|
||||||
|
for i=2,#menudata.favorites,1 do
|
||||||
|
retval = retval .. "," .. render_favorite(menudata.favorites[i],render_details)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if tabdata.fav_selected ~= nil then
|
||||||
|
retval = retval .. ";" .. tabdata.fav_selected .. "]"
|
||||||
|
else
|
||||||
|
retval = retval .. ";0]"
|
||||||
|
end
|
||||||
|
|
||||||
|
-- separator
|
||||||
|
retval = retval ..
|
||||||
|
"box[-0.28,3.75;12.4,0.1;#FFFFFF]"
|
||||||
|
|
||||||
|
-- checkboxes
|
||||||
|
retval = retval ..
|
||||||
|
"checkbox[8.0,3.9;cb_creative;".. fgettext("Creative Mode") .. ";" ..
|
||||||
|
dump(core.setting_getbool("creative_mode")) .. "]"..
|
||||||
|
"checkbox[8.0,4.4;cb_damage;".. fgettext("Enable Damage") .. ";" ..
|
||||||
|
dump(core.setting_getbool("enable_damage")) .. "]"
|
||||||
|
-- buttons
|
||||||
|
retval = retval ..
|
||||||
|
"button[0,3.7;8,1.5;btn_start_singleplayer;" .. fgettext("Start Singleplayer") .. "]" ..
|
||||||
|
"button[0,4.5;8,1.5;btn_config_sp_world;" .. fgettext("Config mods") .. "]"
|
||||||
|
|
||||||
|
return retval
|
||||||
|
end
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
local function main_button_handler(tabview, fields, name, tabdata)
|
||||||
|
|
||||||
|
if fields["btn_start_singleplayer"] then
|
||||||
|
gamedata.selected_world = gamedata.worldindex
|
||||||
|
gamedata.singleplayer = true
|
||||||
|
core.start()
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
if fields["favourites"] ~= nil then
|
||||||
|
local event = core.explode_table_event(fields["favourites"])
|
||||||
|
|
||||||
|
if event.type == "CHG" then
|
||||||
|
if event.row <= #menudata.favorites then
|
||||||
|
local address = menudata.favorites[event.row].address
|
||||||
|
local port = menudata.favorites[event.row].port
|
||||||
|
|
||||||
|
if address ~= nil and
|
||||||
|
port ~= nil then
|
||||||
|
core.setting_set("address",address)
|
||||||
|
core.setting_set("remote_port",port)
|
||||||
|
end
|
||||||
|
|
||||||
|
tabdata.fav_selected = event.row
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
if fields["cb_public_serverlist"] ~= nil then
|
||||||
|
core.setting_set("public_serverlist", fields["cb_public_serverlist"])
|
||||||
|
|
||||||
|
if core.setting_getbool("public_serverlist") then
|
||||||
|
asyncOnlineFavourites()
|
||||||
|
else
|
||||||
|
menudata.favorites = core.get_favorites("local")
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
if fields["cb_creative"] then
|
||||||
|
core.setting_set("creative_mode", fields["cb_creative"])
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
if fields["cb_damage"] then
|
||||||
|
core.setting_set("enable_damage", fields["cb_damage"])
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
if fields["btn_mp_connect"] ~= nil or
|
||||||
|
fields["key_enter"] ~= nil then
|
||||||
|
|
||||||
|
gamedata.playername = fields["te_name"]
|
||||||
|
gamedata.password = fields["te_pwd"]
|
||||||
|
gamedata.address = fields["te_address"]
|
||||||
|
gamedata.port = fields["te_port"]
|
||||||
|
|
||||||
|
local fav_idx = core.get_textlist_index("favourites")
|
||||||
|
|
||||||
|
if fav_idx ~= nil and fav_idx <= #menudata.favorites and
|
||||||
|
menudata.favorites[fav_idx].address == fields["te_address"] and
|
||||||
|
menudata.favorites[fav_idx].port == fields["te_port"] then
|
||||||
|
|
||||||
|
gamedata.servername = menudata.favorites[fav_idx].name
|
||||||
|
gamedata.serverdescription = menudata.favorites[fav_idx].description
|
||||||
|
|
||||||
|
if not is_server_protocol_compat_or_error(menudata.favorites[fav_idx].proto_min,
|
||||||
|
menudata.favorites[fav_idx].proto_max) then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
else
|
||||||
|
gamedata.servername = ""
|
||||||
|
gamedata.serverdescription = ""
|
||||||
|
end
|
||||||
|
|
||||||
|
gamedata.selected_world = 0
|
||||||
|
|
||||||
|
core.setting_set("address",fields["te_address"])
|
||||||
|
core.setting_set("remote_port",fields["te_port"])
|
||||||
|
|
||||||
|
core.start()
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
if fields["btn_config_sp_world"] ~= nil then
|
||||||
|
local configdialog = create_configure_world_dlg(1)
|
||||||
|
|
||||||
|
if (configdialog ~= nil) then
|
||||||
|
configdialog:set_parent(tabview)
|
||||||
|
tabview:hide()
|
||||||
|
configdialog:show()
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
local function on_activate(type,old_tab,new_tab)
|
||||||
|
if type == "LEAVE" then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
if core.setting_getbool("public_serverlist") then
|
||||||
|
asyncOnlineFavourites()
|
||||||
|
else
|
||||||
|
menudata.favorites = core.get_favorites("local")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
tab_simple_main = {
|
||||||
|
name = "main",
|
||||||
|
caption = fgettext("Main"),
|
||||||
|
cbf_formspec = get_formspec,
|
||||||
|
cbf_button_handler = main_button_handler,
|
||||||
|
on_change = on_activate
|
||||||
|
}
|
|
@ -3,7 +3,7 @@
|
||||||
--
|
--
|
||||||
--This program is free software; you can redistribute it and/or modify
|
--This program is free software; you can redistribute it and/or modify
|
||||||
--it under the terms of the GNU Lesser General Public License as published by
|
--it under the terms of the GNU Lesser General Public License as published by
|
||||||
--the Free Software Foundation; either version 3.0 of the License, or
|
--the Free Software Foundation; either version 2.1 of the License, or
|
||||||
--(at your option) any later version.
|
--(at your option) any later version.
|
||||||
--
|
--
|
||||||
--This program is distributed in the hope that it will be useful,
|
--This program is distributed in the hope that it will be useful,
|
||||||
|
@ -16,269 +16,257 @@
|
||||||
--51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
--51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
|
||||||
local function current_game()
|
local function current_game()
|
||||||
local last_game_id = multicraft.setting_get("menu_last_game")
|
local last_game_id = core.setting_get("menu_last_game")
|
||||||
local game, index = gamemgr.find_by_gameid(last_game_id)
|
local game, index = gamemgr.find_by_gameid(last_game_id)
|
||||||
|
|
||||||
return game
|
return game
|
||||||
end
|
end
|
||||||
|
|
||||||
local function singleplayer_refresh_gamebar()
|
local function singleplayer_refresh_gamebar()
|
||||||
|
|
||||||
|
local old_bar = ui.find_by_name("game_button_bar")
|
||||||
|
|
||||||
|
if old_bar ~= nil then
|
||||||
|
old_bar:delete()
|
||||||
|
end
|
||||||
|
|
||||||
local old_bar = ui.find_by_name("game_button_bar")
|
local function game_buttonbar_button_handler(fields)
|
||||||
|
for key,value in pairs(fields) do
|
||||||
|
for j=1,#gamemgr.games,1 do
|
||||||
|
if ("game_btnbar_" .. gamemgr.games[j].id == key) then
|
||||||
|
mm_texture.update("singleplayer", gamemgr.games[j])
|
||||||
|
core.set_topleft_text(gamemgr.games[j].name)
|
||||||
|
core.setting_set("menu_last_game",gamemgr.games[j].id)
|
||||||
|
menudata.worldlist:set_filtercriteria(gamemgr.games[j].id)
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
if old_bar ~= nil then
|
local btnbar = buttonbar_create("game_button_bar",
|
||||||
old_bar:delete()
|
game_buttonbar_button_handler,
|
||||||
end
|
{x=-0.3,y=5.65}, "horizontal", {x=12.4,y=1.15})
|
||||||
|
|
||||||
local function game_buttonbar_button_handler(fields)
|
for i=1,#gamemgr.games,1 do
|
||||||
for key,value in pairs(fields) do
|
local btn_name = "game_btnbar_" .. gamemgr.games[i].id
|
||||||
for j=1,#gamemgr.games,1 do
|
|
||||||
if ("game_btnbar_" .. gamemgr.games[j].id == key) then
|
local image = nil
|
||||||
-- mm_texture.update("singleplayer", gamemgr.games[j])
|
local text = nil
|
||||||
multicraft.setting_set("menu_last_game",gamemgr.games[j].id)
|
local tooltip = core.formspec_escape(gamemgr.games[i].name)
|
||||||
menudata.worldlist:set_filtercriteria(gamemgr.games[j].id)
|
|
||||||
return true
|
if gamemgr.games[i].menuicon_path ~= nil and
|
||||||
end
|
gamemgr.games[i].menuicon_path ~= "" then
|
||||||
end
|
image = core.formspec_escape(gamemgr.games[i].menuicon_path)
|
||||||
end
|
else
|
||||||
end
|
|
||||||
|
local part1 = gamemgr.games[i].id:sub(1,5)
|
||||||
local btnbar = buttonbar_create("game_button_bar",
|
local part2 = gamemgr.games[i].id:sub(6,10)
|
||||||
game_buttonbar_button_handler,
|
local part3 = gamemgr.games[i].id:sub(11)
|
||||||
{x=-0.3,y=5.65}, "horizontal", {x=12.4,y=1.15})
|
|
||||||
|
text = part1 .. "\n" .. part2
|
||||||
for i=1,#gamemgr.games,1 do
|
if part3 ~= nil and
|
||||||
local btn_name = "game_btnbar_" .. gamemgr.games[i].id
|
part3 ~= "" then
|
||||||
|
text = text .. "\n" .. part3
|
||||||
local image = nil
|
end
|
||||||
local text = nil
|
end
|
||||||
local tooltip = multicraft.formspec_escape(gamemgr.games[i].name)
|
btnbar:add_button(btn_name, text, image, tooltip)
|
||||||
|
end
|
||||||
if gamemgr.games[i].menuicon_path ~= nil and
|
|
||||||
gamemgr.games[i].menuicon_path ~= "" then
|
|
||||||
image = multicraft.formspec_escape(gamemgr.games[i].menuicon_path)
|
|
||||||
else
|
|
||||||
|
|
||||||
local part1 = gamemgr.games[i].id:sub(1,5)
|
|
||||||
local part2 = gamemgr.games[i].id:sub(6,10)
|
|
||||||
local part3 = gamemgr.games[i].id:sub(11)
|
|
||||||
|
|
||||||
text = part1 .. "\n" .. part2
|
|
||||||
if part3 ~= nil and
|
|
||||||
part3 ~= "" then
|
|
||||||
text = text .. "\n" .. part3
|
|
||||||
end
|
|
||||||
end
|
|
||||||
btnbar:add_button(btn_name, text, image, tooltip)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local function get_formspec(tabview, name, tabdata)
|
local function get_formspec(tabview, name, tabdata)
|
||||||
|
local retval = ""
|
||||||
|
|
||||||
|
local index = filterlist.get_current_index(menudata.worldlist,
|
||||||
|
tonumber(core.setting_get("mainmenu_last_selected_world"))
|
||||||
|
)
|
||||||
|
|
||||||
local index = menudata.worldlist:get_current_index(
|
retval = retval ..
|
||||||
tonumber(multicraft.setting_get("mainmenu_last_selected_world"))
|
"button[4,4.15;2.6,0.5;world_delete;".. fgettext("Delete") .. "]" ..
|
||||||
)
|
"button[6.5,4.15;2.8,0.5;world_create;".. fgettext("New") .. "]" ..
|
||||||
|
"button[9.2,4.15;2.55,0.5;world_configure;".. fgettext("Configure") .. "]" ..
|
||||||
local retval =
|
"button[8.5,4.95;3.25,0.5;play;".. fgettext("Play") .. "]" ..
|
||||||
"size[16,11]"..
|
"label[4,-0.25;".. fgettext("Select World:") .. "]"..
|
||||||
"box[-100,8.5;200,10;#999999]" ..
|
"checkbox[0.25,0.25;cb_creative_mode;".. fgettext("Creative Mode") .. ";" ..
|
||||||
"box[-100,-10;200,12;#999999]" ..
|
dump(core.setting_getbool("creative_mode")) .. "]"..
|
||||||
"bgcolor[#00000070;true]"..
|
"checkbox[0.25,0.7;cb_enable_damage;".. fgettext("Enable Damage") .. ";" ..
|
||||||
"image_button[4,8.7;3.95,0.8;"..multicraft.formspec_escape(mm_texture.basetexturedir).."menu_button.png;play;".. fgettext("Play") .. ";true;true;"..multicraft.formspec_escape(mm_texture.basetexturedir).."menu_button_b.png]"..
|
dump(core.setting_getbool("enable_damage")) .. "]"..
|
||||||
"image_button[7.8,8.7;3.95,0.8;"..multicraft.formspec_escape(mm_texture.basetexturedir).."menu_button.png;world_create;".. fgettext("New") .. ";true;true;"..multicraft.formspec_escape(mm_texture.basetexturedir).."menu_button_b.png]"..
|
"textlist[4,0.25;7.5,3.7;sp_worlds;" ..
|
||||||
|
menu_render_worldlist() ..
|
||||||
"image_button[4,9.55;3.95,0.8;"..multicraft.formspec_escape(mm_texture.basetexturedir).."menu_button.png;world_delete;".. fgettext("Delete") .. ";true;true;"..multicraft.formspec_escape(mm_texture.basetexturedir).."menu_button_b.png]"..
|
";" .. index .. "]"
|
||||||
--"image_button[6.53,9.55;2.68,0.8;"..multicraft.formspec_escape(mm_texture.basetexturedir).."menu_button.png;world_configure;".. fgettext("Configure") .. ";true;true;"..multicraft.formspec_escape(mm_texture.basetexturedir).."menu_button_b.png]"..
|
return retval
|
||||||
"image_button[7.8,9.55;3.95,0.8;"..multicraft.formspec_escape(mm_texture.basetexturedir).."menu_button.png;cancel;".. fgettext("Cancel") .. ";true;true;"..multicraft.formspec_escape(mm_texture.basetexturedir).."menu_button_b.png]"..
|
|
||||||
"label[7,1.5;" .. fgettext("Select World:") .. "]" ..
|
|
||||||
|
|
||||||
"checkbox[12,8.70;cb_creative_mode;" .. fgettext("Creative Mode") .. ";" .. dump(multicraft.setting_getbool("creative_mode")) .. "]" ..
|
|
||||||
--"checkbox[1000,9.20;cb_enable_damage;" .. fgettext("Enable Damage") .. ";" .. dump(multicraft.setting_getbool("enable_damage")) .. "]" ..
|
|
||||||
-- "checkbox[12,9.50;cb_server_announce;" .. fgettext("Public") .. ";" .. dump(multicraft.setting_getbool("server_announce")) .. "]" ..
|
|
||||||
|
|
||||||
|
|
||||||
"checkbox[0.2,8.35;btn_server;Local Server;false]"
|
|
||||||
|
|
||||||
|
|
||||||
local bind_addr = multicraft.setting_get("bind_address")
|
|
||||||
|
|
||||||
if not PLATFORM=="android" and bind_addr ~= nil and bind_addr ~= "" then
|
|
||||||
retval = retval ..
|
|
||||||
"field[300,0;2.25,0.5;te_serveraddr;" .. fgettext("Bind Address") .. ";" ..
|
|
||||||
multicraft.formspec_escape(multicraft.setting_get("bind_address")) .. "]"..
|
|
||||||
"field[300,1;1.25,0.5;te_serverport;" .. fgettext("Port") .. ";" ..
|
|
||||||
multicraft.formspec_escape(multicraft.setting_get("port")) .. "]"
|
|
||||||
else
|
|
||||||
retval = retval ..
|
|
||||||
"field[300,1;3.5,0.5;te_serverport;" .. fgettext("Server Port") .. ";" ..
|
|
||||||
multicraft.formspec_escape(multicraft.setting_get("port")) .. "]"
|
|
||||||
end
|
|
||||||
|
|
||||||
retval = retval ..
|
|
||||||
"textlist[0,2.2;16,6.5;sp_worlds;" ..
|
|
||||||
menu_render_worldlist() ..
|
|
||||||
";" .. (index or 1) .. ";true]"
|
|
||||||
|
|
||||||
return retval
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local function main_button_handler(this, fields, name, tabdata)
|
local function main_button_handler(this, fields, name, tabdata)
|
||||||
multicraft.set_clouds(false)
|
|
||||||
--assert(name == "singleplayer")
|
|
||||||
|
|
||||||
if fields["btn_server"]~=nil then
|
assert(name == "singleplayer")
|
||||||
local single = create_tab_server(true)
|
|
||||||
single:set_parent(this.parent)
|
|
||||||
single:show()
|
|
||||||
this:hide()
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
local world_doubleclick = false
|
local world_doubleclick = false
|
||||||
|
|
||||||
if fields["sp_worlds"] ~= nil then
|
if fields["sp_worlds"] ~= nil then
|
||||||
local event = multicraft.explode_textlist_event(fields["sp_worlds"])
|
local event = core.explode_textlist_event(fields["sp_worlds"])
|
||||||
|
|
||||||
if event.type == "DCL" then
|
local selected = core.get_textlist_index("sp_worlds")
|
||||||
world_doubleclick = true
|
if selected ~= nil then
|
||||||
end
|
local filename = menudata.worldlist:get_list()[selected].path
|
||||||
|
local worldconfig = modmgr.get_worldconfig(filename)
|
||||||
|
filename = filename .. DIR_DELIM .. "world.mt"
|
||||||
|
|
||||||
if event.type == "CHG" then
|
if worldconfig.creative_mode ~= nil then
|
||||||
multicraft.setting_set("mainmenu_last_selected_world",
|
core.setting_set("creative_mode", worldconfig.creative_mode)
|
||||||
menudata.worldlist:get_raw_index(multicraft.get_textlist_index("sp_worlds")))
|
else
|
||||||
return true
|
local worldfile = Settings(filename)
|
||||||
end
|
worldfile:set("creative_mode", core.setting_get("creative_mode"))
|
||||||
end
|
if not worldfile:write() then
|
||||||
|
core.log("error", "Failed to write world config file")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if worldconfig.enable_damage ~= nil then
|
||||||
|
core.setting_set("enable_damage", worldconfig.enable_damage)
|
||||||
|
else
|
||||||
|
local worldfile = Settings(filename)
|
||||||
|
worldfile:set("enable_damage", core.setting_get("enable_damage"))
|
||||||
|
if not worldfile:write() then
|
||||||
|
core.log("error", "Failed to write world config file")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
if menu_handle_key_up_down(fields,"sp_worlds","mainmenu_last_selected_world") then
|
if event.type == "DCL" then
|
||||||
return true
|
world_doubleclick = true
|
||||||
end
|
end
|
||||||
|
|
||||||
if fields["cb_creative_mode"] then
|
if event.type == "CHG" and selected ~= nil then
|
||||||
multicraft.setting_set("creative_mode", fields["cb_creative_mode"])
|
core.setting_set("mainmenu_last_selected_world",
|
||||||
local bool = fields["cb_creative_mode"]
|
menudata.worldlist:get_raw_index(selected))
|
||||||
if bool == 'true' then
|
return true
|
||||||
bool = 'false'
|
end
|
||||||
else
|
end
|
||||||
bool = 'true'
|
|
||||||
end
|
|
||||||
multicraft.setting_set("enable_damage", bool)
|
|
||||||
multicraft.setting_save()
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
if fields["cb_enable_damage"] then
|
if menu_handle_key_up_down(fields,"sp_worlds","mainmenu_last_selected_world") then
|
||||||
multicraft.setting_set("enable_damage", fields["cb_enable_damage"])
|
return true
|
||||||
multicraft.setting_save()
|
end
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
if fields["play"] ~= nil or
|
if fields["cb_creative_mode"] then
|
||||||
world_doubleclick or
|
core.setting_set("creative_mode", fields["cb_creative_mode"])
|
||||||
fields["key_enter"] then
|
local selected = core.get_textlist_index("sp_worlds")
|
||||||
local selected = multicraft.get_textlist_index("sp_worlds")
|
local filename = menudata.worldlist:get_list()[selected].path ..
|
||||||
if selected ~= nil then
|
DIR_DELIM .. "world.mt"
|
||||||
gamedata.selected_world = menudata.worldlist:get_raw_index(selected)
|
|
||||||
gamedata.singleplayer = true
|
|
||||||
|
|
||||||
multicraft.start()
|
local worldfile = Settings(filename)
|
||||||
end
|
worldfile:set("creative_mode", fields["cb_creative_mode"])
|
||||||
return true
|
if not worldfile:write() then
|
||||||
end
|
core.log("error", "Failed to write world config file")
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
if fields["world_create"] ~= nil then
|
if fields["cb_enable_damage"] then
|
||||||
local create_world_dlg = create_create_world_dlg(true)
|
core.setting_set("enable_damage", fields["cb_enable_damage"])
|
||||||
create_world_dlg:set_parent(this)
|
local selected = core.get_textlist_index("sp_worlds")
|
||||||
this:hide()
|
local filename = menudata.worldlist:get_list()[selected].path ..
|
||||||
create_world_dlg:show()
|
DIR_DELIM .. "world.mt"
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
if fields["world_delete"] ~= nil then
|
local worldfile = Settings(filename)
|
||||||
local selected = multicraft.get_textlist_index("sp_worlds")
|
worldfile:set("enable_damage", fields["cb_enable_damage"])
|
||||||
if selected ~= nil and
|
if not worldfile:write() then
|
||||||
selected <= menudata.worldlist:size() then
|
core.log("error", "Failed to write world config file")
|
||||||
local world = menudata.worldlist:get_list()[selected]
|
end
|
||||||
if world ~= nil and
|
return true
|
||||||
world.name ~= nil and
|
end
|
||||||
world.name ~= "" then
|
|
||||||
local index = menudata.worldlist:get_raw_index(selected)
|
|
||||||
local delete_world_dlg = create_delete_world_dlg(world.name,index)
|
|
||||||
delete_world_dlg:set_parent(this)
|
|
||||||
this:hide()
|
|
||||||
delete_world_dlg:show()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
return true
|
if fields["play"] ~= nil or
|
||||||
end
|
world_doubleclick or
|
||||||
|
fields["key_enter"] then
|
||||||
|
local selected = core.get_textlist_index("sp_worlds")
|
||||||
|
|
||||||
|
if selected ~= nil then
|
||||||
|
gamedata.selected_world = menudata.worldlist:get_raw_index(selected)
|
||||||
|
gamedata.singleplayer = true
|
||||||
|
|
||||||
|
core.start()
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
if fields["world_configure"] ~= nil then
|
if fields["world_create"] ~= nil then
|
||||||
local selected = multicraft.get_textlist_index("sp_worlds")
|
local create_world_dlg = create_create_world_dlg(true)
|
||||||
if selected ~= nil then
|
create_world_dlg:set_parent(this)
|
||||||
local configdialog =
|
this:hide()
|
||||||
create_configure_world_dlg(
|
create_world_dlg:show()
|
||||||
menudata.worldlist:get_raw_index(selected))
|
mm_texture.update("singleplayer",current_game())
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
if (configdialog ~= nil) then
|
if fields["world_delete"] ~= nil then
|
||||||
configdialog:set_parent(this)
|
local selected = core.get_textlist_index("sp_worlds")
|
||||||
this:hide()
|
if selected ~= nil and
|
||||||
configdialog:show()
|
selected <= menudata.worldlist:size() then
|
||||||
--mm_texture.update("singleplayer",current_game())
|
local world = menudata.worldlist:get_list()[selected]
|
||||||
end
|
if world ~= nil and
|
||||||
end
|
world.name ~= nil and
|
||||||
|
world.name ~= "" then
|
||||||
|
local index = menudata.worldlist:get_raw_index(selected)
|
||||||
|
local delete_world_dlg = create_delete_world_dlg(world.name,index)
|
||||||
|
delete_world_dlg:set_parent(this)
|
||||||
|
this:hide()
|
||||||
|
delete_world_dlg:show()
|
||||||
|
mm_texture.update("singleplayer",current_game())
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
return true
|
if fields["world_configure"] ~= nil then
|
||||||
end
|
local selected = core.get_textlist_index("sp_worlds")
|
||||||
|
if selected ~= nil then
|
||||||
if fields["cancel"] ~= nil then
|
local configdialog =
|
||||||
this:hide()
|
create_configure_world_dlg(
|
||||||
this.parent:show()
|
menudata.worldlist:get_raw_index(selected))
|
||||||
return true
|
|
||||||
end
|
if (configdialog ~= nil) then
|
||||||
|
configdialog:set_parent(this)
|
||||||
return false
|
this:hide()
|
||||||
|
configdialog:show()
|
||||||
|
mm_texture.update("singleplayer",current_game())
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function on_change(type, old_tab, new_tab)
|
local function on_change(type, old_tab, new_tab)
|
||||||
local buttonbar = ui.find_by_name("game_button_bar")
|
local buttonbar = ui.find_by_name("game_button_bar")
|
||||||
|
|
||||||
if ( buttonbar == nil ) then
|
if ( buttonbar == nil ) then
|
||||||
singleplayer_refresh_gamebar()
|
singleplayer_refresh_gamebar()
|
||||||
buttonbar = ui.find_by_name("game_button_bar")
|
buttonbar = ui.find_by_name("game_button_bar")
|
||||||
end
|
end
|
||||||
|
|
||||||
if (type == "ENTER") then
|
if (type == "ENTER") then
|
||||||
local game = current_game()
|
local game = current_game()
|
||||||
|
|
||||||
if game then
|
if game then
|
||||||
menudata.worldlist:set_filtercriteria(game.id)
|
menudata.worldlist:set_filtercriteria(game.id)
|
||||||
--multicraft.set_topleft_text(game.name)
|
core.set_topleft_text(game.name)
|
||||||
-- mm_texture.update("singleplayer",game)
|
mm_texture.update("singleplayer",game)
|
||||||
end
|
end
|
||||||
buttonbar:show()
|
buttonbar:show()
|
||||||
else
|
else
|
||||||
menudata.worldlist:set_filtercriteria(nil)
|
menudata.worldlist:set_filtercriteria(nil)
|
||||||
buttonbar:hide()
|
buttonbar:hide()
|
||||||
--multicraft.set_topleft_text("")
|
core.set_topleft_text("")
|
||||||
--mm_texture.update(new_tab,nil)
|
mm_texture.update(new_tab,nil)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
tab_singleplayer = {
|
tab_singleplayer = {
|
||||||
name = "singleplayer",
|
name = "singleplayer",
|
||||||
caption = fgettext("Singleplayer"),
|
caption = fgettext("Singleplayer"),
|
||||||
cbf_formspec = get_formspec,
|
cbf_formspec = get_formspec,
|
||||||
cbf_button_handler = main_button_handler,
|
cbf_button_handler = main_button_handler,
|
||||||
--on_change = on_change
|
on_change = on_change
|
||||||
}
|
}
|
||||||
|
|
||||||
function create_tab_single()
|
|
||||||
local retval = dialog_create("singleplayer",
|
|
||||||
get_formspec,
|
|
||||||
main_button_handler,
|
|
||||||
nil)
|
|
||||||
return retval
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
--
|
--
|
||||||
--This program is free software; you can redistribute it and/or modify
|
--This program is free software; you can redistribute it and/or modify
|
||||||
--it under the terms of the GNU Lesser General Public License as published by
|
--it under the terms of the GNU Lesser General Public License as published by
|
||||||
--the Free Software Foundation; either version 3.0 of the License, or
|
--the Free Software Foundation; either version 2.1 of the License, or
|
||||||
--(at your option) any later version.
|
--(at your option) any later version.
|
||||||
--
|
--
|
||||||
--This program is distributed in the hope that it will be useful,
|
--This program is distributed in the hope that it will be useful,
|
||||||
|
@ -36,7 +36,7 @@ local function render_texture_pack_list(list)
|
||||||
retval = retval ..","
|
retval = retval ..","
|
||||||
end
|
end
|
||||||
|
|
||||||
retval = retval .. multicraft.formspec_escape(v)
|
retval = retval .. core.formspec_escape(v)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -45,12 +45,13 @@ end
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
local function get_formspec(tabview, name, tabdata)
|
local function get_formspec(tabview, name, tabdata)
|
||||||
|
|
||||||
local retval = "label[4,-0.25;".. fgettext("Select texture pack:") .. "]"..
|
local retval = "label[4,-0.25;".. fgettext("Select texture pack:") .. "]"..
|
||||||
"textlist[4,0.25;7.5,5.0;TPs;"
|
"textlist[4,0.25;7.5,5.0;TPs;"
|
||||||
|
|
||||||
local current_texture_path = multicraft.setting_get("texture_path")
|
local current_texture_path = core.setting_get("texture_path")
|
||||||
local list = filter_texture_pack_list(multicraft.get_dir_list(multicraft.get_texturepath(), true))
|
local list = filter_texture_pack_list(core.get_dir_list(core.get_texturepath(), true))
|
||||||
local index = tonumber(multicraft.setting_get("mainmenu_last_selected_TP"))
|
local index = tonumber(core.setting_get("mainmenu_last_selected_TP"))
|
||||||
|
|
||||||
if index == nil then index = 1 end
|
if index == nil then index = 1 end
|
||||||
|
|
||||||
|
@ -81,27 +82,25 @@ local function get_formspec(tabview, name, tabdata)
|
||||||
return retval ..
|
return retval ..
|
||||||
render_texture_pack_list(list) ..
|
render_texture_pack_list(list) ..
|
||||||
";" .. index .. "]" ..
|
";" .. index .. "]" ..
|
||||||
"image[0.25,0.25;4.0,3.7;"..multicraft.formspec_escape(screenfile or no_screenshot).."]"..
|
"image[0.25,0.25;4.0,3.7;"..core.formspec_escape(screenfile or no_screenshot).."]"..
|
||||||
"textarea[0.6,3.25;3.7,1.5;;"..multicraft.formspec_escape(infotext or "")..";]"
|
"textarea[0.6,3.25;3.7,1.5;;"..core.formspec_escape(infotext or "")..";]"
|
||||||
end
|
end
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
local function main_button_handler(tabview, fields, name, tabdata)
|
local function main_button_handler(tabview, fields, name, tabdata)
|
||||||
multicraft.set_clouds(false)
|
|
||||||
|
|
||||||
if fields["TPs"] ~= nil then
|
if fields["TPs"] ~= nil then
|
||||||
local event = multicraft.explode_textlist_event(fields["TPs"])
|
local event = core.explode_textlist_event(fields["TPs"])
|
||||||
if event.type == "CHG" or event.type == "DCL" then
|
if event.type == "CHG" or event.type == "DCL" then
|
||||||
local index = multicraft.get_textlist_index("TPs")
|
local index = core.get_textlist_index("TPs")
|
||||||
multicraft.setting_set("mainmenu_last_selected_TP",
|
core.setting_set("mainmenu_last_selected_TP",
|
||||||
index)
|
index)
|
||||||
local list = filter_texture_pack_list(multicraft.get_dir_list(multicraft.get_texturepath(), true))
|
local list = filter_texture_pack_list(core.get_dir_list(core.get_texturepath(), true))
|
||||||
local current_index = multicraft.get_textlist_index("TPs")
|
local current_index = core.get_textlist_index("TPs")
|
||||||
if current_index ~= nil and #list >= current_index then
|
if current_index ~= nil and #list >= current_index then
|
||||||
local new_path = multicraft.get_texturepath()..DIR_DELIM..list[current_index]
|
local new_path = core.get_texturepath()..DIR_DELIM..list[current_index]
|
||||||
if list[current_index] == "None" then new_path = "" end
|
if list[current_index] == "None" then new_path = "" end
|
||||||
|
|
||||||
multicraft.setting_set("texture_path", new_path)
|
core.setting_set("texture_path", new_path)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return true
|
return true
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
--
|
--
|
||||||
--This program is free software; you can redistribute it and/or modify
|
--This program is free software; you can redistribute it and/or modify
|
||||||
--it under the terms of the GNU Lesser General Public License as published by
|
--it under the terms of the GNU Lesser General Public License as published by
|
||||||
--the Free Software Foundation; either version 3.0 of the License, or
|
--the Free Software Foundation; either version 2.1 of the License, or
|
||||||
--(at your option) any later version.
|
--(at your option) any later version.
|
||||||
--
|
--
|
||||||
--This program is distributed in the hope that it will be useful,
|
--This program is distributed in the hope that it will be useful,
|
||||||
|
@ -20,142 +20,147 @@ mm_texture = {}
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
function mm_texture.init()
|
function mm_texture.init()
|
||||||
mm_texture.defaulttexturedir = multicraft.get_texturepath() .. DIR_DELIM .. "base" ..
|
mm_texture.defaulttexturedir = core.get_texturepath() .. DIR_DELIM .. "base" ..
|
||||||
DIR_DELIM .. "pack" .. DIR_DELIM
|
DIR_DELIM .. "pack" .. DIR_DELIM
|
||||||
mm_texture.basetexturedir = mm_texture.defaulttexturedir
|
mm_texture.basetexturedir = mm_texture.defaulttexturedir
|
||||||
|
|
||||||
mm_texture.texturepack = multicraft.setting_get("texture_path")
|
mm_texture.texturepack = core.setting_get("texture_path")
|
||||||
|
|
||||||
mm_texture.gameid = nil
|
mm_texture.gameid = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
function mm_texture.update(tab,gamedetails)
|
function mm_texture.update(tab,gamedetails)
|
||||||
if gamedetails == nil then
|
if tab ~= "singleplayer" then
|
||||||
return
|
mm_texture.reset()
|
||||||
end
|
return
|
||||||
mm_texture.update_game(gamedetails)
|
end
|
||||||
|
|
||||||
|
if gamedetails == nil then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
mm_texture.update_game(gamedetails)
|
||||||
end
|
end
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
function mm_texture.reset()
|
function mm_texture.reset()
|
||||||
mm_texture.gameid = nil
|
mm_texture.gameid = nil
|
||||||
local have_bg = false
|
local have_bg = false
|
||||||
local have_overlay = mm_texture.set_generic("overlay")
|
local have_overlay = mm_texture.set_generic("overlay")
|
||||||
|
|
||||||
if not have_overlay then
|
if not have_overlay then
|
||||||
have_bg = mm_texture.set_generic("background")
|
have_bg = mm_texture.set_generic("background")
|
||||||
end
|
end
|
||||||
|
|
||||||
mm_texture.clear("header")
|
mm_texture.clear("header")
|
||||||
mm_texture.clear("footer")
|
mm_texture.clear("footer")
|
||||||
multicraft.set_clouds(false)
|
core.set_clouds(false)
|
||||||
|
|
||||||
mm_texture.set_generic("footer")
|
mm_texture.set_generic("footer")
|
||||||
mm_texture.set_generic("header")
|
mm_texture.set_generic("header")
|
||||||
|
|
||||||
if not have_bg then
|
if not have_bg then
|
||||||
if multicraft.setting_getbool("menu_clouds") then
|
if core.setting_getbool("menu_clouds") then
|
||||||
multicraft.set_clouds(true)
|
core.set_clouds(true)
|
||||||
else
|
else
|
||||||
mm_texture.set_dirt_bg()
|
mm_texture.set_dirt_bg()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
function mm_texture.update_game(gamedetails)
|
function mm_texture.update_game(gamedetails)
|
||||||
if mm_texture.gameid == gamedetails.id then
|
if mm_texture.gameid == gamedetails.id then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local have_bg = false
|
local have_bg = false
|
||||||
local have_overlay = mm_texture.set_game("overlay",gamedetails)
|
local have_overlay = mm_texture.set_game("overlay",gamedetails)
|
||||||
|
|
||||||
if not have_overlay then
|
if not have_overlay then
|
||||||
have_bg = mm_texture.set_game("background",gamedetails)
|
have_bg = mm_texture.set_game("background",gamedetails)
|
||||||
end
|
end
|
||||||
|
|
||||||
mm_texture.clear("header")
|
mm_texture.clear("header")
|
||||||
mm_texture.clear("footer")
|
mm_texture.clear("footer")
|
||||||
multicraft.set_clouds(false)
|
core.set_clouds(false)
|
||||||
|
|
||||||
if not have_bg then
|
if not have_bg then
|
||||||
|
|
||||||
if multicraft.setting_getbool("menu_clouds") then
|
if core.setting_getbool("menu_clouds") then
|
||||||
multicraft.set_clouds(true)
|
core.set_clouds(true)
|
||||||
else
|
else
|
||||||
mm_texture.set_dirt_bg()
|
mm_texture.set_dirt_bg()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
mm_texture.set_game("footer",gamedetails)
|
mm_texture.set_game("footer",gamedetails)
|
||||||
--print(dump(gamedetails))
|
mm_texture.set_game("header",gamedetails)
|
||||||
mm_texture.set_game("header",gamedetails)
|
|
||||||
|
mm_texture.gameid = gamedetails.id
|
||||||
mm_texture.gameid = gamedetails.id
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
function mm_texture.clear(identifier)
|
function mm_texture.clear(identifier)
|
||||||
multicraft.set_background(identifier,"")
|
core.set_background(identifier,"")
|
||||||
end
|
end
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
function mm_texture.set_generic(identifier)
|
function mm_texture.set_generic(identifier)
|
||||||
--try texture pack first
|
--try texture pack first
|
||||||
if mm_texture.texturepack ~= nil then
|
if mm_texture.texturepack ~= nil then
|
||||||
local path = mm_texture.texturepack .. DIR_DELIM .."menu_" ..
|
local path = mm_texture.texturepack .. DIR_DELIM .."menu_" ..
|
||||||
identifier .. ".png"
|
identifier .. ".png"
|
||||||
if multicraft.set_background(identifier,path) then
|
if core.set_background(identifier,path) then
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if mm_texture.defaulttexturedir ~= nil then
|
if mm_texture.defaulttexturedir ~= nil then
|
||||||
local path = mm_texture.defaulttexturedir .. DIR_DELIM .."menu_" ..
|
local path = mm_texture.defaulttexturedir .. DIR_DELIM .."menu_" ..
|
||||||
identifier .. ".png"
|
identifier .. ".png"
|
||||||
if multicraft.set_background(identifier,path) then
|
if core.set_background(identifier,path) then
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
function mm_texture.set_game(identifier,gamedetails)
|
function mm_texture.set_game(identifier,gamedetails)
|
||||||
|
|
||||||
|
if gamedetails == nil then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
if gamedetails == nil then
|
if mm_texture.texturepack ~= nil then
|
||||||
return false
|
local path = mm_texture.texturepack .. DIR_DELIM ..
|
||||||
end
|
gamedetails.id .. "_menu_" .. identifier .. ".png"
|
||||||
|
if core.set_background(identifier,path) then
|
||||||
if mm_texture.texturepack ~= nil then
|
return true
|
||||||
local path = mm_texture.texturepack .. DIR_DELIM ..
|
end
|
||||||
gamedetails.id .. "_menu_" .. identifier .. ".png"
|
end
|
||||||
if multicraft.set_background(identifier,path) then
|
|
||||||
return true
|
local path = gamedetails.path .. DIR_DELIM .."menu" ..
|
||||||
end
|
DIR_DELIM .. identifier .. ".png"
|
||||||
end
|
if core.set_background(identifier,path) then
|
||||||
|
return true
|
||||||
local path = gamedetails.path .. DIR_DELIM .."menu" ..
|
end
|
||||||
DIR_DELIM .. identifier .. ".png"
|
|
||||||
if multicraft.set_background(identifier,path) then
|
return false
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
return false
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function mm_texture.set_dirt_bg()
|
function mm_texture.set_dirt_bg()
|
||||||
if mm_texture.texturepack ~= nil then
|
if mm_texture.texturepack ~= nil then
|
||||||
local path = mm_texture.texturepack .. DIR_DELIM .."default_stone.png"
|
local path = mm_texture.texturepack .. DIR_DELIM .."default_dirt.png"
|
||||||
if multicraft.set_background("background", path, true, 128) then
|
if core.set_background("background", path, true, 128) then
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--use base pack
|
--use base pack
|
||||||
local minimalpath = defaulttexturedir .. "dirt_bg.png"
|
local minimalpath = defaulttexturedir .. "dirt_bg.png"
|
||||||
multicraft.set_background("background", minimalpath, true, 128)
|
core.set_background("background", minimalpath, true, 128)
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,66 +0,0 @@
|
||||||
local ffi
|
|
||||||
|
|
||||||
-- there's no ffi in Lua, only in LuaJIT
|
|
||||||
-- when Freeminer is run with Lua the profiler is not available because we can't access precise timer
|
|
||||||
if not pcall(function() ffi = require("ffi") end) then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
ffi.cdef[[
|
|
||||||
unsigned int get_time_us();
|
|
||||||
]]
|
|
||||||
|
|
||||||
local modpath = multicraft.get_builtin_path()..DIR_DELIM
|
|
||||||
|
|
||||||
package.path = package.path .. ";" .. modpath .. "/?.lua"
|
|
||||||
ProFi = require 'ProFi'
|
|
||||||
|
|
||||||
local function get_time_precise()
|
|
||||||
return ffi.C.get_time_us() / 1000000
|
|
||||||
end
|
|
||||||
|
|
||||||
ProFi:setGetTimeMethod(get_time_precise)
|
|
||||||
|
|
||||||
local started = false
|
|
||||||
|
|
||||||
local function start_profiler()
|
|
||||||
ProFi:start()
|
|
||||||
started = true
|
|
||||||
end
|
|
||||||
|
|
||||||
if freeminer.setting_getbool("profiler_autostart") then
|
|
||||||
start_profiler()
|
|
||||||
freeminer.after(3, function()
|
|
||||||
freeminer.chat_send_all("The profiler was started. If you don't want this, set " .. freeminer.colorize("61ad6d", "profiler_autostart")
|
|
||||||
.. " to false in " .. freeminer.colorize("61ad6d", "freeminer.conf"))
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
|
|
||||||
freeminer.register_chatcommand("profiler_stop", {
|
|
||||||
description = "stop the profiler and write report",
|
|
||||||
privs = {server=true},
|
|
||||||
func = function(name)
|
|
||||||
if not started then
|
|
||||||
freeminer.chat_send_player(name, "Profiler has not been started. You can start it using " .. freeminer.colorize("00ffff", "/profiler_start"))
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
ProFi:stop()
|
|
||||||
ProFi:writeReport("profile.txt")
|
|
||||||
|
|
||||||
freeminer.chat_send_player(name, "Profiler is stopped.")
|
|
||||||
end,
|
|
||||||
})
|
|
||||||
|
|
||||||
freeminer.register_chatcommand("profiler_start", {
|
|
||||||
description = "start the profiler",
|
|
||||||
privs = {server=true},
|
|
||||||
func = function(name)
|
|
||||||
if started then
|
|
||||||
freeminer.chat_send_player(name, "Profiler is already running.")
|
|
||||||
return
|
|
||||||
end
|
|
||||||
start_profiler()
|
|
||||||
freeminer.chat_send_player(name, "Profiler is started.")
|
|
||||||
end
|
|
||||||
})
|
|
Loading…
Reference in New Issue