Repository navigation
Expand file tree
/
Copy pathscratch_compat.go
More file actions
134 lines (118 loc) · 4.65 KB
/
Copy pathscratch_compat.go
File metadata and controls
134 lines (118 loc) · 4.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/*
* Copyright (c) 2021 The XGo Authors (xgo.dev). All rights reserved.
*
* 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.
*/
package spx
import (
"strconv"
spxlog "github.com/goplus/spx/v4/internal/base/log"
"github.com/goplus/spx/v4/internal/core/scratch"
)
// ResolveCostumeIndex resolves a costume name or 1-based integer string to an index.
//
// Deprecated: Use [github.com/goplus/spx/v4/pkg/scratchcompat.ResolveCostumeIndex] instead.
func (p *SpriteImpl) ResolveCostumeIndex(costume string) int {
if isDebugInstrEnabled() {
spxlog.Debug("ResolveCostumeIndex: sprite=%s, costume=%v", p.name, costume)
}
if idx := p.findCostume(costume); idx >= 0 {
return idx
}
number, err := strconv.Atoi(costume)
if err != nil {
return -1
}
return p.ResolveCostumeNumber(number)
}
// ResolveCostumeNumber wraps a 1-based Scratch costume number over this sprite's costumes.
func (p *SpriteImpl) ResolveCostumeNumber(number int) int {
return scratch.WrapCostumeNumber(number, len(p.costumes))
}
// ResolveBackdropIndex resolves a backdrop name, action, or numeric selector.
//
// Deprecated: Use [github.com/goplus/spx/v4/pkg/scratchcompat.ResolveBackdropIndex] instead.
func (p *Game) ResolveBackdropIndex(backdrop string) int {
if isDebugInstrEnabled() {
spxlog.Debug("ResolveBackdropIndex: backdrop=%v", backdrop)
}
if idx := p.findCostume(backdrop); idx >= 0 {
return idx
}
return scratch.ParseBackdropIndex(backdrop, len(p.costumes))
}
// List stores values using 0-based indexes.
//
// Deprecated: Use [github.com/goplus/spx/v4/pkg/scratchcompat.List] instead.
type List = scratch.List
// NewList creates a new List initialized with the given elements.
//
// Deprecated: Use [github.com/goplus/spx/v4/pkg/scratchcompat.NewList] instead.
func NewList(l ...any) List {
return scratch.NewList(l...)
}
// LimitPrecision rounds a coordinate when it is strictly within 1e-9 of an
// integer; NaN and infinities pass through. Apply it to a sprite's own x/y
// reporters, leaving property queries unchanged.
//
// Deprecated: Use [github.com/goplus/spx/v4/pkg/scratchcompat.LimitPrecision] instead.
func LimitPrecision(coordinate float64) float64 {
return scratch.LimitPrecision(coordinate)
}
// Div divides a by b, converting a NaN result to zero and preserving infinities.
//
// Deprecated: Use [github.com/goplus/spx/v4/pkg/scratchcompat.Div] instead.
func Div(a, b float64) float64 {
return scratch.Div(a, b)
}
// FloorMod computes the remainder, adding the divisor when remainder/divisor
// is negative. A zero divisor produces NaN.
//
// Deprecated: Use [github.com/goplus/spx/v4/pkg/scratchcompat.FloorMod] instead.
func FloorMod(dividend, divisor float64) float64 {
return scratch.FloorMod(dividend, divisor)
}
// Contains reports whether substr occurs in s, ignoring case.
//
// Deprecated: Use [github.com/goplus/spx/v4/pkg/scratchcompat.Contains] instead.
func Contains(s, substr string) bool {
return scratch.Contains(s, substr)
}
// Compare compares numbers when both operands are numeric, otherwise strings
// ignoring case. It returns -1, 0, or 1 without Equal's numeric tolerance.
//
// Deprecated: Use [github.com/goplus/spx/v4/pkg/scratchcompat.Compare] instead.
func Compare(v1, v2 any) int {
return scratch.Compare(v1, v2)
}
// Equal compares like Compare, allowing up to two ULPs of numeric rounding error.
// Numeric comparisons involving NaN return false.
//
// Deprecated: Use [github.com/goplus/spx/v4/pkg/scratchcompat.Equal] instead.
func Equal(v1, v2 any) bool {
return scratch.Equal(v1, v2)
}
// CharAt returns the rune at the 0-based index in s, or "" if out of range.
//
// Deprecated: Use [github.com/goplus/spx/v4/pkg/scratchcompat.CharAt] with a 1-based index instead.
func CharAt(s string, idx int) string {
return scratch.CharAt(s, idx)
}
// PenColorParamFromString converts a string to its corresponding PenColorParam.
// It accepts "color", "saturation", "brightness", and "transparency" (case-insensitive).
// Returns PenNone if the string is not recognized.
//
// Deprecated: Use [github.com/goplus/spx/v4/pkg/scratchcompat.PenColorParamFromString] instead.
func PenColorParamFromString(s string) PenColorParam {
return PenColorParam(scratch.PenColorParamFromString(s))
}