https://github.com/hazzard993/love-inline-import
A TypeScriptToLua plugin that in-lines image imports
https://github.com/hazzard993/love-inline-import
import-resolver love2d plugin typescripttolua
Last synced: 27 days ago
JSON representation
A TypeScriptToLua plugin that in-lines image imports
- Host: GitHub
- URL: https://github.com/hazzard993/love-inline-import
- Owner: hazzard993
- Created: 2020-11-30T10:59:08.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-11-30T11:58:07.000Z (over 5 years ago)
- Last Synced: 2025-03-28T21:43:39.735Z (about 1 year ago)
- Topics: import-resolver, love2d, plugin, typescripttolua
- Language: TypeScript
- Homepage:
- Size: 9.77 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# love-inline-import
A [TypeScriptToLua](https://typescripttolua.github.io/) plugin that in-lines image imports.
## How to use
Add the plugin
```bash
yarn add -D love-inline-import
# or npm install -D love-inline-import
```
Register the plugin in your `tsconfig.json`
```json
{
"tstl": {
"luaPlugins": [
{ "name": "love-inline-import" }
]
}
}
```
Tell TypeScript that a png import returns an `Image` type
```ts
// add this ambient code to a file within your project
// this tells TypeScript that imports ending with .png
// are expected to return an image type
declare module "*.png" {
import { Image } from "love.graphics";
const image: Image;
export = image;
}
```
And you're good to go! Here's some sample input and output code
```ts
import * as player from "./player.png";
love.draw = () => {
love.graphics.draw(player);
};
```
```lua
local player = love.graphics.newImage(...) -- ... is generated and contains image data
love.draw = function()
love.graphics.draw(player)
end
```
## Features
- Allows images to be stored in your source directory
- Image resolution is handled on compilation