<commit_before># This file is part of NIT ( http://www.nitlanguage.org ).
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Android client with a joystick
module android_client is
	app_name "Tinks!"
	app_namespace "net.xymus.tinks"
	android_manifest """<uses-permission android:name="android.permission.INTERNET" />"""
	android_api_target 10
end

import mnit_android
import android::audio
import android::vibration
import android::landscape

intrude import client
import controls

redef class App

	# Tank direction control
	var joystick = new Joystick is lazy

	redef var controls = new Array[Control].with_items(joystick) is lazy

	redef fun input(event)
	do
		var local_player = context.local_player
		var local_tank = local_tank
		if local_player != null and local_tank != null and event isa ControlEvent then
			local_player.orders.add new TankDirectionOrder(local_tank, joystick.value_x, joystick.value_y)
			return true
		end

		if event isa AndroidKeyEvent then
			if event.is_back_key then
				quit = true
				native_activity.finish
				return false
			end
		end

		return super
	end
end

redef class ExplosionEvent
	redef fun client_react(display, turn)
	do
		super

		var local_tank = app.local_tank
		var d = 20
		if local_tank != null then
			d = local_tank.pos.dist(pos).to_i
			d = 500 - d*20
			d = d.max(10)
		end

		app.vibrator.vibrate d
	end
end

# On-demand joystick that popups up when tapping the left border of the screen
class Joystick
	super Control

	# Current position of the joystick from its center on the X axis, in `[-1.0..1.0]`
	var value_x = 0.0

	# Current position of the joystick from its center on the Y axis, in `[-1.0..1.0]`
	var value_y = 0.0

	# Deadzone at the center of the joystick where the values are set at 0.0<commit_msg>contrib/tinks: greatly reduce the vibration strength under android<commit_after># This file is part of NIT ( http://www.nitlanguage.org ).
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Android client with a joystick
module android_client is
	app_name "Tinks!"
	app_namespace "net.xymus.tinks"
	android_manifest """<uses-permission android:name="android.permission.INTERNET" />"""
	android_api_target 10
end

import mnit_android
import android::audio
import android::vibration
import android::landscape

intrude import client
import controls

redef class App

	# Tank direction control
	var joystick = new Joystick is lazy

	redef var controls = new Array[Control].with_items(joystick) is lazy

	redef fun input(event)
	do
		var local_player = context.local_player
		var local_tank = local_tank
		if local_player != null and local_tank != null and event isa ControlEvent then
			local_player.orders.add new TankDirectionOrder(local_tank, joystick.value_x, joystick.value_y)
			return true
		end

		if event isa AndroidKeyEvent then
			if event.is_back_key then
				quit = true
				native_activity.finish
				return false
			end
		end

		return super
	end
end

redef class ExplosionEvent
	redef fun client_react(display, turn)
	do
		super

		var local_tank = app.local_tank
		var d = 20
		if local_tank != null then
			d = local_tank.pos.dist(pos).to_i
			d = 100 - d*5
			d = d.max(10)
		end

		app.vibrator.vibrate d
	end
end

# On-demand joystick that popups up when tapping the left border of the screen
class Joystick
	super Control

	# Current position of the joystick from its center on the X axis, in `[-1.0..1.0]`
	var value_x = 0.0

	# Current position of the joystick from its center on the Y axis, in `[-1.0..1.0]`
	var value_y = 0.0

	# Deadzone at the center of the joystick where the values are set at 0.0
{'fraction_non_alphanumeric': 0.06971677559912855, 'fraction_numerical': 0.01241830065359477, 'mean_word_length': 3.8685047720042416, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4321996', 'n_tokens_mistral': 1562, 'n_tokens_neox': 1403, 'n_words': 566}