-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontrol.lua
217 lines (168 loc) · 4.73 KB
/
control.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
require ('utils.eventWrapper')
require ('utils.timeout')
require ('utils.player')
require ('utils.keys')
require ('utils.flashlight')
-- require ('utils.autowalk')
-- require ('utils.inventory')
require ('utils.fuelNearby')
require ('utils.craftingQueue')
require ('utils.jumplist')
require ('utils.warp')
require ('utils.cursorHistory')
require ('utils.related')
------------- Yank selected
function yankSelected ()
local sel = pl.selected
if sel == nil then return end
local name = sel.name
if name == 'entity-ghost' then
name = sel.ghost_name
end
local item = game.item_prototypes[name]
if not item then return end
_setCursor (item)
updateCursorStack ()
end
script.on_event("yank-selected", yankSelected)
------------- Cursor history
script.on_event("cursor-item-prev", cursorHistoryPrev)
script.on_event("cursor-item-next", cursorHistoryNext)
nmapf ('O', cursorHistoryPromote)
nmapf ('I', cursorHistoryDelete)
nmapf ('n', relatedItemNext)
nmapf ('p', relatedItemPrev)
nmapf ('gn', relatedItemTierUp)
nmapf ('gp', relatedItemTierDown)
------------- Insert fuel
-- script.on_event("insert-fuel", fuelNearby)
nmapf('F', fuelNearby)
nmapf('<c-f>', fuelNearbyEq)
------------- Craft cursor
function craftCursor (count)
local cur = getCursor ()
if cur == nil then return end
local r = pl.force.recipes[cur]
if r == nil then return end
pl.begin_crafting({count = count, recipe = r, silent = false})
end
-- If cursor was a ghost, swap to the crafted item
onEvent (defines.events.on_player_crafted_item, function (ev)
local gh = pl.cursor_ghost
if gh == nil or ev == nil or ev.item_stack == nil or gh.name ~= ev.item_stack.name then return end
pl.cursor_stack.swap_stack (ev.item_stack)
end)
script.on_event("craft-cursor", function (ev)
craftCursor (1)
end)
script.on_event("craft-cursor-five", function (ev)
craftCursor (5)
end)
------------- Game Speed
function tellSpeed ()
game.print("Speed: " .. game.speed)
end
script.on_event("speed-reset", function (ev)
game.speed = 1.0
tellSpeed ()
end)
script.on_event("speed-up", function (ev)
game.speed = game.speed * 2
tellSpeed ()
end)
script.on_event("speed-down", function (ev)
game.speed = game.speed / 2
tellSpeed ()
end)
------------------
nmapf ('tq', toggleCraftingQueueMode)
nmapf ('tf', toggleFlashlight)
nmapf ('tm', function ()
pl.game_view_settings.show_minimap = not pl.game_view_settings.show_minimap
end)
nmapf ('ts', function ()
pl.game_view_settings.show_shortcut_bar = not pl.game_view_settings.show_shortcut_bar
end)
nmapf ('w', warpShort)
nmapf ('W', warpWord)
nmapf ('E', warpEnd)
------------------
nmapf ('gm', function ()
if pl.render_mode == defines.render_mode.game then
pl.open_map (pl.position, 0.2)
else
pl.close_map ()
end
end)
nmapf ('gw', function ()
if pl.render_mode == defines.render_mode.game then
pl.zoom_to_world(pl.position)
else
pl.close_map ()
end
end)
nmapf ('gt', function ()
pl.open_technology_gui()
end)
nmapf ('u', function ()
if pl.opened_self then
pl.opened = nil
else
pl.opened = pl
end
end)
------------
-- onEvent (defines.events.on_built_entity, function (ev)
-- pl.selected = ev.created_entity
-- end)
-- local inv
--
-- nmapf ('gi', function ()
-- if not inv then
-- inv = Inventory (pl)
-- end
-- inv.toggle ()
-- end)
-- nmapf ('h', function ()
-- if not inv or not inv.isOpen then return end
-- inv.moveSelLeft ()
-- end)
--
-- nmapf ('l', function ()
-- if not inv or not inv.isOpen then return end
-- inv.moveSelRight ()
-- end)
--
-- nmapf ('j', function ()
-- if not inv or not inv.isOpen then return end
-- inv.moveSelDown ()
-- end)
--
-- nmapf ('k', function ()
-- if not inv or not inv.isOpen then return end
-- inv.moveSelUp ()
-- end)
-- onEvent (defines.events.on_put_item, function (ev)
-- if not pl.cursor_stack or not pl.cursor_stack.valid_for_read then return end
-- local st = pl.cursor_stack.prototype
-- if st.subgroup.name ~= 'belt' then return end
-- pl.clean_cursor()
-- pl.cursor_ghost = st;
-- -- pl.print("put")
-- end)
-- onEvent (defines.events.on_built_entity, function (ev)
-- if not ev.stack or not ev.stack.valid_for_read then return end
-- local st = ev.stack.prototype
-- -- if st.subgroup.name ~= 'belt' then return end
-- -- ev.created_entity.direction = 0
-- pl.print(ev.stack.count)
-- end)
-- onEvent (defines.events.on_selected_entity_changed, function (ev)
-- if not pl then return end
-- if pl.selected then return end
-- if not pl.cursor_stack or not pl.cursor_stack.valid_for_read then return end
-- local st = pl.cursor_stack.prototype
-- if st.subgroup.name ~= 'belt' then return end
-- pl.print("selected")
-- -- pl.build_from_cursor({position = pl.selected.position})
-- end)