forked from AiTechEye/smartshop
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
another checkpoint commit, nothing is tested, i doubt it even loads
- Loading branch information
1 parent
718b2c1
commit e9f76a2
Showing
21 changed files
with
924 additions
and
192 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
* redo how storage is linked - punch node instead of right-click | ||
* remove dependency on default |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
|
||
minetest.register_alias("smartshop:wifistorage", "smartshop:storage") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,19 @@ | ||
local formspec_escape = minetest.formspec_escape | ||
|
||
local formspec_pos = smartshop.util.formspec_pos | ||
local string_to_pos = minetest.string_to_pos | ||
|
||
-------------------- | ||
|
||
local mesein_descriptions = { | ||
"Don't send", | ||
"Incoming", | ||
"Outgoing", | ||
"Both", | ||
} | ||
|
||
function smartshop.api.build_wifi_formspec(obj) | ||
local fpos = formspec_pos(obj.pos) | ||
local title = formspec_escape(obj:get_title()) | ||
|
||
local gui_parts = { | ||
"size[12,9]", | ||
("field[0.3,5.3;2,1;title;;%s]"):format(title), | ||
"tooltip[title;Used with connected smartshops]", | ||
"button_exit[0,6;2,1;save;Save]", | ||
("list[nodemeta:%s;main;0,0;12,5;]"):format(fpos), | ||
"list[current_player;main;2,5;8,4;]", | ||
("listring[nodemeta:%s;main]"):format(fpos), | ||
"listring[current_player;main]" | ||
} | ||
|
||
if smartshop.has.mesecons then | ||
local mesein = obj:get_mesein() | ||
local description = mesein_descriptions[mesein] | ||
table.insert(gui_parts, ("button[0,7;2,1;mesesin;%s]"):format(description)) | ||
table.insert(gui_parts, "tooltip[mesesin;Send mesecon signal when items from shops does:]") | ||
function smartshop.api.on_player_receive_fields(player, formname, fields) | ||
local spos = formname:match("smartshop:(.+)") | ||
local pos = spos and string_to_pos(spos) | ||
local obj = smartshop.api.get_object(pos) | ||
if obj then | ||
obj:receive_fields(player, fields) | ||
return true | ||
end | ||
|
||
return table.concat(gui_parts, "") | ||
end | ||
|
||
function smartshop.api.wifi_receive_fields(player, pressed) | ||
local player_name = player:get_player_name() | ||
if not pos then return end | ||
minetest.register_on_player_receive_fields(function(player, formname, fields) | ||
return smartshop.api.on_player_receive_fields(player, formname, fields) | ||
end) | ||
|
||
if pressed.mesesin then | ||
toggle_mesein(meta) | ||
smartshop.wifi_showform(pos, player) | ||
elseif pressed.save then | ||
local title = pressed.title | ||
if not title or title == "" then | ||
title = "wifi " .. minetest.pos_to_string(pos) | ||
end | ||
smartshop.set_title(meta, title) | ||
local spos = minetest.pos_to_string(pos) | ||
smartshop.log("action", "%s set title of wifi storage at %s to %s", player_name, spos, title) | ||
smartshop.player_pos[player_name] = nil | ||
elseif pressed.quit then | ||
smartshop.player_pos[player_name] = nil | ||
end | ||
end | ||
-------------------- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,48 @@ | ||
smartshop.api = {} | ||
|
||
|
||
local shop_node_names = { | ||
"smartshop:shop", | ||
"smartshop:shop_full", | ||
"smartshop:shop_empty", | ||
"smartshop:shop_used", | ||
"smartshop:shop_admin" | ||
} | ||
|
||
function smartshop.api.is_smartshop(pos) | ||
function smartshop.api.is_shop(pos) | ||
if not pos then return end | ||
local node_name = minetest.get_node(pos).name | ||
for _, name in ipairs(shop_node_names) do | ||
for _, name in ipairs(smartshop.shop_node_names) do | ||
if name == node_name then | ||
return true | ||
end | ||
end | ||
return false | ||
end | ||
|
||
smartshop.dofile("api", "node_class") | ||
smartshop.dofile("api", "shop_class") | ||
smartshop.dofile("api", "storage_class") | ||
function smartshop.api.is_storage(pos) | ||
if not pos then return end | ||
local node_name = minetest.get_node(pos).name | ||
for _, name in ipairs(smartshop.storage_node_names) do | ||
if name == node_name then | ||
return true | ||
end | ||
end | ||
return false | ||
end | ||
|
||
--[[ | ||
TODO: i'm not certain whether memoizing the returned objects is worth doing or not. | ||
also it'd require clearing the memo when a node is destroyed. | ||
]] | ||
function smartshop.api.get_object(pos) | ||
if smartshop.api.is_smartshop(pos) then | ||
return smartshop.node_class:new(pos) | ||
else | ||
if not pos then return end | ||
if smartshop.api.is_shop(pos) then | ||
return smartshop.shop_class:new(pos) | ||
elseif smartshop.api.is_storage(pos) then | ||
return smartshop.storage_class:new(pos) | ||
end | ||
end | ||
|
||
smartshop.dofile("api", "node_class") | ||
smartshop.dofile("api", "shop_class") | ||
smartshop.dofile("api", "storage_class") | ||
smartshop.dofile("api", "player_inv_class") | ||
|
||
smartshop.dofile("api", "formspec") | ||
|
||
smartshop.dofile("api", "purchase_mechanics") | ||
smartshop.dofile("api", "storage_linking") | ||
|
||
smartshop.dofile("api", "entities") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
-- this will allow us to more easily extend behavior e.g. interacting directly w/ inventory bags | ||
|
||
local check_player_add_remainder = smartshop.util.check_player_add_remainder | ||
local check_player_remove_remainder = smartshop.util.check_player_remove_remainder | ||
|
||
-------------------- | ||
|
||
|
||
local player_inv_class = {} | ||
smartshop.player_inv_class = player_inv_class | ||
|
||
-------------------- | ||
|
||
function player_inv_class:new(player) | ||
local name = player:get_player_name() | ||
local inv = player:get_inventory() | ||
local object = { | ||
player = player, | ||
name = name, | ||
inv = inv, | ||
} | ||
setmetatable(object, self) | ||
self.__index = self -- magic for inheritance? | ||
return object | ||
end | ||
|
||
function smartshop.api.get_player_inv(player) | ||
return player_inv_class:new(player) | ||
end | ||
|
||
-------------------- | ||
|
||
function player_inv_class:room_for_item(stack) | ||
return self.inv:room_for_item("main", stack) | ||
end | ||
|
||
function player_inv_class:add_item(stack) | ||
local remainder = self.inv:add_item("main", stack) | ||
check_player_add_remainder(remainder) | ||
return remainder | ||
end | ||
|
||
function player_inv_class:contains_item(stack, match_meta) | ||
return self.inv:contains_item("main", stack, match_meta) | ||
end | ||
|
||
function player_inv_class:remove_item(stack) | ||
local remainder = self.inv:remove_item("main", stack) | ||
check_player_remove_remainder(remainder) | ||
return remainder | ||
end | ||
|
Oops, something went wrong.