Commit b83a0e73 authored by Delisa Mason's avatar Delisa Mason

feat: Add Tiled command and make target for generating hooks

parent 9ab384d0
-- Map object hooks
--
-- Helpers:
-- self:property(name) - get sprite property
-- self:set_property(name, value) - set sprite property
-- self:lookup_object(name) - get sprite by name
-- self:lookup_targets() - get sprites from `targets` map property
local hooks = {}
-- Respond to a target invocation
--function hooks:update()
--end
-- If map property actionable == true, respond to collision + player action
--function hooks:action()
--end
return hooks
......@@ -28,3 +28,41 @@ ifeq ($(name),)
@$(error name is not defined. Run with `make add-system name=[value]`)
endif
@install .templates/system.lua game/systems/$(name).lua
add-hooks: ## Create new map object hooks
ifeq ($(name),)
@$(error name is not defined. Run with `make add-hooks name=[value] level=[value]`)
endif
ifeq ($(level),)
@$(error level is not defined. Run with `make add-hooks name=[value] level=[value]`)
endif
@mkdir -p game/assets/maps/$(level)
@install .templates/hooks.lua game/assets/maps/$(level)/$(name).lua
# Companion to a Tiled command which, when an object is selected, opens (and
# creates if needed) a hooks script for interacting with map object properties.
# Uses .templates/hooks.lua to create a new file if it does not exist already.
#
# Tiled command:
# * Executable: `make tiled-edit-hooks mapfile=%mapfile layer=%layername id=%objectid`
# * Working directory: wherever this file is
#
# Dependencies:
# * yq (http://yq.readthedocs.io) - `brew install python-yq`
# * MacVim (http://macvim-dev.github.io) - `brew cask install macvim`
tiled-edit-hooks: ## Add and edit hoox for a map object from Tiled command
ifeq ($(mapfile),) # %mapfile
@$(error mapfile is not defined. Run with `make add-hooks mapfile=[value] layer=[value] id=[value]`)
endif
ifeq ($(layer),) # %layername
@$(error layer is not defined. Run with `make add-hooks mapfile=[value] layer=[value] id=[value]`)
endif
ifeq ($(id),) # %objectid
@$(error id is not defined. Run with `make add-hooks mapfile=[value] layer=[value] id=[value]`)
endif
@mapname=$(shell basename $(mapfile)); \
level=$${mapname%.*}; \
objname=$(shell xq '.map.objectgroup[] | select(.["@name"] == "$(layer)") | .object[] | select(.["@id"] == "$(id)") | .["@name"]' game/assets/maps/level01.tmx | tr -d '"'); \
filepath=game/assets/maps/$${level}/$${objname}.lua; \
test -f $${filepath} || $(MAKE) add-hooks name=$${objname} level=$${level}; \
mvim game/assets/maps/$${level}/$${objname}.lua;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment