Scrappy Device

Scrappy Device is a simple library for Solar2D that allows you to get info about the device your app is running on.

As with all my plugins it is free to use however if you find it useful, and are able to, I’d appreciate a coffee.

Image Credit: Digital devices by ProSymbols from the Noun Project.

Getting Started

There are multiple ways to include the library in your project, the simplest is probably via the plugin, as outlined below, however if you wish you can also access the source code.

Plugin

build.settings


settings =
{
    plugins =
    {
        ["plugin.scrappyDevice"] =
        {
            publisherId = "com.scrappyferret",
            supportedPlatforms =
            {
                iphone = { url="https://plugins.scrappyferret.com/scrappyDevice/iphone.tgz" },
                android = { url="https://plugins.scrappyferret.com/scrappyDevice/android.tgz" },
                macos = false,
                win32 = false
            },
        },
    },
}

main.lua


require( "plugin.scrappyDevice" )

Scrappy.Device:init()

Source Code

If you wish you to access the source code directly it is available on GitLab here.

You can then clone or fork it if you wish, or add the library as a submodule to your project with this command:

git submodule add https://gitlab.com/scrappyferret-libs/scrappy-device.git device

However you get the source code into your project, you will then need to include it and initiate it.

main.lua


require( "device.core" )

Scrappy.Device:init()

API

Scrappy.Device:init( params )

Initiates the library.

params ( table ) – Parameters for the initiation.


Scrappy.Device:getPlatform()

Gets the simple tag for each platform.

returns – The name of the platform. Either ‘macos’, ‘win32’, ‘android’, ‘ios’, ‘tvos’, ‘winphone’, or ‘html5’.


Scrappy.Device:getEnvironment()

Gets the environment name.

returns – The name of the environment. Either ‘device’ or ‘simulator’.


Scrappy.Device:getModel()

Gets the model name.

returns – The name of the model.


Scrappy.Device:isReal()

Checks if the game is currently running on a physical device.

returns – True if it is, false otherwise.


Scrappy.Device:isSimulator()

Checks if the game is currently running in the simulator.

returns – True if it is, false otherwise.


Scrappy.Device:isTV()

Checks if the game is currently running on a TV based console.

returns – True if it is, false otherwise.


Scrappy.Device:isAppleTV()

Checks if the game is currently running on an AppleTV.

returns – True if it is, false otherwise.


Scrappy.Device:isAmazonTV()

Checks if the game is currently running on an Amazon FireTV.

returns – True if it is, false otherwise.


Scrappy.Device:isAndroidTV()

Checks if the game is currently running on an Android TV.

returns – True if it is, false otherwise.


Scrappy.Device:isIOS()

Checks if the game is currently running on an iOS device.

returns – True if it is, false otherwise.


Scrappy.Device:isAndroid()

Checks if the game is currently running on an Android device.

returns – True if it is, false otherwise.


Scrappy.Device:isOSX()

Checks if the game is currently running on an OSX device.

returns – True if it is, false otherwise.


Scrappy.Device:isWindows()

Checks if the game is currently running on a Windows device.

returns – True if it is, false otherwise.


Scrappy.Device:isLinux()

Checks if the game is currently running on a Linux device.

returns – True if it is, false otherwise.


Scrappy.Device:isKindle()

Checks if the game is currently running on an Amazon Kindle device.

returns – True if it is, false otherwise.


Scrappy.Device:isDesktop()

Checks if the game is currently running on a desktop.

returns – True if it is, false otherwise.


Scrappy.Device:isMobile()

Checks if the game is currently running on a mobile device.

returns – True if it is, false otherwise.


Scrappy.Device:isWeb()

Checks if the game is currently in a browser.

returns – True if it is, false otherwise.


Scrappy.Device:getTargetStore()

Gets the name of the store that the app was built for.

returns – The name of the store.


Scrappy.Device:destroy()

Destroys this library.


Examples

Thank the player

if Scrappy.Device:isIOS() then
	print( "Thank you random player for buying an expensive phone and then quibbling over spending pennies on an app!" )
elseif Scrappy.Device:isKindle() then
	print( "Thank you personally for being the one user that owns a Kindle Fire." )
elseif Scrappy.Device:isAndroid() then
	print( "Thank you random player for buying one of about a million different variants of Android phones, this will be fun to develop for!" )
end