Merge remote-tracking branch 'warmist/dev_building_hacks' into develop

develop
expwnent 2014-08-16 10:26:24 -04:00
commit 59e6607d8c
7 changed files with 93 additions and 24 deletions

@ -965,6 +965,12 @@ Job module
Compares important fields in the job item structures.
* ``dfhack.job.linkIntoWorld(job,new_id)``
Adds job into ``df.global.job_list``, and if new_id
is true, then also sets it's id and increases
``df.global.job_next_id``
* ``dfhack.job.listNewlyCreated(first_id)``
Returns the current value of ``df.global.job_next_id``, and
@ -3209,7 +3215,8 @@ Functions
5. ``registerSidebar(shop_name,callback)``
Enable callback when sidebar for ``shop_name`` is drawn. Usefull for custom workshop views e.g. using gui.dwarfmode lib.
Enable callback when sidebar for ``shop_name`` is drawn. Usefull for custom workshop views e.g. using gui.dwarfmode lib. Also accepts a ``class`` instead of function
as callback. Best used with ``gui.dwarfmode`` class ``WorkshopOverlay``.
Examples
--------
@ -3266,7 +3273,8 @@ Functions
a. tables of 4 numbers ``{tile,fore,back,bright}`` OR
b. empty table (tile not modified) OR
c. ``{x=<number> y=<number> + 4 numbers like in first case}``, this generates full frame useful for animations that change little (1-2 tiles)
8. canBeRoomSubset -- a flag if this building can be counted in room. 1 means it can, 0 means it can't and -1 default building behaviour
Animate table also might contain:
1. frameLenght -- how many ticks does one frame take OR
2. isMechanical -- a bool that says to try to match to mechanical system (i.e. how gears are turning)

@ -1339,6 +1339,7 @@ static const LuaWrapper::FunctionReg dfhack_job_module[] = {
WRAPM(Job,isSuitableItem),
WRAPM(Job,isSuitableMaterial),
WRAPM(Job,getName),
WRAPM(Job,linkIntoWorld),
WRAPN(is_equal, jobEqual),
WRAPN(is_item_equal, jobItemEqual),
{ NULL, NULL }

@ -383,7 +383,7 @@ MenuOverlay = defclass(MenuOverlay, DwarfOverlay)
MenuOverlay.ATTRS {
frame_inset = 0,
frame_background = CLEAR_PEN,
frame_background = gui.CLEAR_PEN,
}
function MenuOverlay:computeFrame(parent_rect)
@ -417,5 +417,35 @@ function MenuOverlay:render(dc)
MenuOverlay.super.render(self, dc)
end
end
--fakes a "real" workshop sidebar menu, but on exactly selected workshop
WorkshopOverlay = defclass(WorkshopOverlay, MenuOverlay)
WorkshopOverlay.ATTRS={
workshop=DEFAULT_NIL,
}
function WorkshopOverlay:onInput(keys)
local allowedKeys={ --TODO add options: job management, profile, etc...
"CURSOR_RIGHT","CURSOR_LEFT","CURSOR_UP","CURSOR_DOWN",
"CURSOR_UPRIGHT","CURSOR_UPLEFT","CURSOR_DOWNRIGHT","CURSOR_DOWNLEFT",
"CURSOR_UP_Z","CURSOR_DOWN_Z","DESTROYBUILDING","CHANGETAB"}
if keys.LEAVESCREEN then
self:dismiss()
self:sendInputToParent('LEAVESCREEN')
elseif keys.CHANGETAB then
self:sendInputToParent("CHANGETAB")
self:inputToSubviews(keys)
self:updateLayout()
else
for _,name in ipairs(allowedKeys) do
if keys[name] then
self:sendInputToParent(name)
break
end
end
self:inputToSubviews(keys)
end
if df.global.world.selected_building ~= self.workshop then
self:dismiss()
return
end
end
return _ENV

@ -47,6 +47,7 @@ struct workshop_hack_data
int frame_skip; // e.g. 2 means have to ticks between frames
//updateCallback:
int skip_updates;
int room_subset; //0 no, 1 yes, -1 default
};
typedef std::map<int32_t,workshop_hack_data> workshops_data_t;
workshops_data_t hacked_workshops;
@ -174,6 +175,17 @@ struct work_hook : df::building_workshopst{
return INTERPOSE_NEXT(isUnpowered)();
}
DEFINE_VMETHOD_INTERPOSE(bool, canBeRoomSubset, ())
{
if(auto def = find_def())
{
if(def->room_subset==0)
return false;
if(def->room_subset==1)
return true;
}
return INTERPOSE_NEXT(canBeRoomSubset)();
}
DEFINE_VMETHOD_INTERPOSE(void, updateAction, ())
{
if(auto def = find_def())
@ -241,6 +253,7 @@ IMPLEMENT_VMETHOD_INTERPOSE(work_hook, categorize);
IMPLEMENT_VMETHOD_INTERPOSE(work_hook, uncategorize);
IMPLEMENT_VMETHOD_INTERPOSE(work_hook, canConnectToMachine);
IMPLEMENT_VMETHOD_INTERPOSE(work_hook, isUnpowered);
IMPLEMENT_VMETHOD_INTERPOSE(work_hook, canBeRoomSubset);
IMPLEMENT_VMETHOD_INTERPOSE(work_hook, updateAction);
IMPLEMENT_VMETHOD_INTERPOSE(work_hook, drawBuilding);
void clear_mapping()
@ -336,6 +349,7 @@ static int addBuilding(lua_State* L)
else
newDefinition.machine_timing=false;
}
newDefinition.room_subset=luaL_optinteger(L,9,-1);
hacked_workshops[newDefinition.myType]=newDefinition;
return 0;
}
@ -354,6 +368,7 @@ static void enable_hooks(bool enable)
INTERPOSE_HOOK(work_hook,uncategorize).apply(enable);
INTERPOSE_HOOK(work_hook,canConnectToMachine).apply(enable);
INTERPOSE_HOOK(work_hook,isUnpowered).apply(enable);
INTERPOSE_HOOK(work_hook,canBeRoomSubset).apply(enable);
//update n render
INTERPOSE_HOOK(work_hook,updateAction).apply(enable);
INTERPOSE_HOOK(work_hook,drawBuilding).apply(enable);

@ -102,8 +102,8 @@ function registerBuilding(args)
end
frames=processFrames(shop_def,animate.frames)
end
addBuilding(shop_id,fix_impassible,consume,produce,gears,updateSkip,frames,frameLength)
local roomSubset=args.canBeRoomSubset or -1
addBuilding(shop_id,fix_impassible,consume,produce,gears,updateSkip,frames,frameLength,roomSubset)
end
return _ENV

@ -98,10 +98,25 @@ function registerReaction(reaction_name,callback)
end
function registerSidebar(shop_name,callback)
_registeredStuff.customSidebar=_registeredStuff.customSidebar or {}
_registeredStuff.customSidebar[shop_name]=callback
onWorkshopFillSidebarMenu._library=customSidebarsCallback
dfhack.onStateChange.eventful=unregall
if type(callback)=="function" then
_registeredStuff.customSidebar=_registeredStuff.customSidebar or {}
_registeredStuff.customSidebar[shop_name]=callback
onWorkshopFillSidebarMenu._library=customSidebarsCallback
dfhack.onStateChange.eventful=unregall
else
local function drawSidebar( wshop )
local valid_focus="dwarfmode/QueryBuilding/Some"
if wshop:getMaxBuildStage()==wshop:getBuildStage() then
local sidebar=callback{workshop=wshop}
if string.sub(dfhack.gui.getCurFocus(),1,#valid_focus)==valid_focus then
sidebar:show()
else
sidebar:show(dfhack.gui.getCurViewscreen(true).parent)
end
end
end
registerSidebar(shop_name,drawSidebar)
end
end
function removeNative(shop_name,name)
@ -126,11 +141,11 @@ function addReactionToShop(reaction_name,shop_name)
dfhack.onStateChange.eventful=unregall
end
local function invertTable(tbl)
local ret={}
for k,v in pairs(tbl) do
ret[v]=k
end
return ret
local ret={}
for k,v in pairs(tbl) do
ret[v]=k
end
return ret
end
eventType=invertTable{
[0]="TICK",

@ -34,7 +34,7 @@ function fileExists(filename)
end
end
if not fileExists(init_file) then
local initFile=io.open(initFileName,"a")
local initFile=io.open(init_file,"a")
initFile:close()
end
function copyFile(from,to) --oh so primitive
@ -52,15 +52,15 @@ function patchInit(initFileName,patch_guard,code)
code,patch_guard[2]))
initFile:close()
end
function patchDofile( initFileName,patch_guard,dofile_list )
local initFile=io.open(initFileName,"a")
initFile:write(patch_guard[1].."\n")
function patchDofile( luaFileName,patch_guard,dofile_list,mod_path )
local luaFile=io.open(luaFileName,"a")
luaFile:write(patch_guard[1].."\n")
for _,v in ipairs(dofile_list) do
local fixed_path=mod_dir:gsub("\\","/")
initFile:write(string.format("dofile('%s/%s')\n",fixed_path,v))
local fixed_path=mod_path:gsub("\\","/")
luaFile:write(string.format("dofile('%s/%s')\n",fixed_path,v))
end
initFile:write(patch_guard[2].."\n")
initFile:close()
luaFile:write(patch_guard[2].."\n")
luaFile:close()
end
function patchFile(file_name,patch_guard,after_string,code)
local input_lines=patch_guard[1].."\n"..code.."\n"..patch_guard[2]
@ -294,7 +294,7 @@ function manager:install(trgMod,force)
patchInit(init_file,trgMod.guard_init,trgMod.patch_init)
end
if trgMod.patch_dofile then
patchDofile(init_file,trgMod.guard_init,trgMod.patch_dofile)
patchDofile(init_file,trgMod.guard_init,trgMod.patch_dofile,trgMod.path)
end
trgMod.installed=true